From f3553913925b8ee5869c8e06047d6e4161a968c7 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Tue, 20 Feb 2018 17:19:13 +0000 Subject: [PATCH] openstack: nova_utils_tests: Wait for volume detachment The 'test_add_remove_volum' is supposed to wait for volume attachment and detachments. However, the code for the latter was missing. Moreover, we remove some code that checks for attached volumes since that should never happen when detaching the volume. Change-Id: I9ed54a467062d0ddc4efeddf03af7ebe6173e789 Signed-off-by: Markos Chandras --- snaps/openstack/utils/tests/nova_utils_tests.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/snaps/openstack/utils/tests/nova_utils_tests.py b/snaps/openstack/utils/tests/nova_utils_tests.py index 494c96c..ee9c5d1 100644 --- a/snaps/openstack/utils/tests/nova_utils_tests.py +++ b/snaps/openstack/utils/tests/nova_utils_tests.py @@ -456,6 +456,7 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase): self.volume_creator.get_volume(), self.project_id)) vol_attach = None + vol_detach = None attached = False start_time = time.time() while time.time() < start_time + 120: @@ -487,8 +488,19 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase): self.nova, neutron, self.instance_creator.get_vm_inst(), self.volume_creator.get_volume(), self.project_id)) - vol_detach = cinder_utils.get_volume_by_id( - self.cinder, self.volume_creator.get_volume().id) + start_time = time.time() + while time.time() < start_time + 120: + vol_detach = cinder_utils.get_volume_by_id( + self.cinder, self.volume_creator.get_volume().id) + if len(vol_detach.attachments) == 0: + attached = False + break + + time.sleep(3) + + self.assertFalse(attached) + self.assertIsNotNone(vol_detach) + vm_detach = nova_utils.get_server_object_by_id( self.nova, neutron, self.instance_creator.get_vm_inst().id, self.project_id) @@ -497,10 +509,6 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase): self.assertIsNotNone(vol_detach) self.assertEqual(self.volume_creator.get_volume().id, vol_detach.id) - if len(vol_detach.attachments) > 0: - vol_detach = cinder_utils.get_volume_by_id( - self.cinder, self.volume_creator.get_volume().id) - self.assertEqual(0, len(vol_detach.attachments)) self.assertEqual(0, len(vm_detach.volume_ids)) -- 2.16.6