openstack: nova_utils_tests: Wait for volume detachment 71/52371/1
authorMarkos Chandras <mchandras@suse.de>
Tue, 20 Feb 2018 17:19:13 +0000 (17:19 +0000)
committerMarkos Chandras <mchandras@suse.de>
Tue, 20 Feb 2018 17:21:12 +0000 (17:21 +0000)
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 <mchandras@suse.de>
snaps/openstack/utils/tests/nova_utils_tests.py

index 494c96c..ee9c5d1 100644 (file)
@@ -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))