From: Markos Chandras Date: Tue, 20 Feb 2018 17:19:13 +0000 (+0000) Subject: openstack: nova_utils_tests: Wait for volume detachment X-Git-Tag: opnfv-6.0.0~18 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=f3553913925b8ee5869c8e06047d6e4161a968c7;p=snaps.git 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 --- 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))