From ff6bb0ffeab44015ec4a9b072becf83c6983407b Mon Sep 17 00:00:00 2001 From: pengdake <19921207pq@gmail.com> Date: Mon, 29 Jan 2018 00:38:32 +0800 Subject: [PATCH] Update function named _wait_volumes_available When a volume is not available, it should set count to 0 and sleep. If not, the count maybe larger than length of volumes in some situation. Change-Id: Ifb28cd4be212284ce833b68b31725a84077215dc --- zun/compute/manager.py | 8 +++++--- zun/tests/unit/compute/test_compute_manager.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 4aa7db1d1..c2cbe7d5f 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -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" diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index 2bfa73579..cb96124a4 100644 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -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()