Merge "Update function named _wait_volumes_available"

This commit is contained in:
Zuul 2018-01-31 06:21:02 +00:00 committed by Gerrit Code Review
commit 7487f92c86
2 changed files with 18 additions and 3 deletions

View File

@ -132,14 +132,16 @@ class Manager(periodic_task.PeriodicTasks):
def _wait_for_volumes_available(self, context, volumes, container,
timeout=60, poll_interval=1):
count = 0
start_time = time.time()
while time.time() - start_time < timeout:
if count == len(volumes):
break
count = 0
for vol in volumes:
if self.driver.is_volume_available(context, vol):
count = count + 1
else:
break
if count == len(volumes):
break
time.sleep(poll_interval)
else:
msg = _("Volumes did not reach available status after"

View File

@ -919,3 +919,16 @@ class TestManager(base.TestCase):
def test_container_network_attach(self, mock_attach):
container = Container(self.context, **utils.get_test_container())
self.compute_manager.network_attach(self.context, container, 'network')
@mock.patch.object(fake_driver, 'is_volume_available')
@mock.patch.object(manager.Manager, '_fail_container')
def test_wait_for_volumes_available(self, mock_fail,
mock_is_volume_available):
mock_is_volume_available.return_value = True
container = Container(self.context, **utils.get_test_container())
volumes = [FakeVolumeMapping()]
self.compute_manager._wait_for_volumes_available(self.context,
volumes,
container)
mock_is_volume_available.assert_called_once()
mock_fail.assert_not_called()