diff --git a/test/integration/smoke/test_list_volumes.py b/test/integration/smoke/test_list_volumes.py index b08e9cf3b383..aea775f19ccc 100644 --- a/test/integration/smoke/test_list_volumes.py +++ b/test/integration/smoke/test_list_volumes.py @@ -76,9 +76,6 @@ def setUpClass(cls): cls.services["disk_offering"]) cls._cleanup.append(cls.disk_offering) - # Get already existing volumes in the env for assertions - cls.volumes = Volume.list(cls.apiclient, zoneid=cls.zone.id) or [] - # Create VM cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -260,7 +257,7 @@ def test_05_list_volumes_isrecursive(self): "List Volume response is not a valid list" ) self.assertEqual( - len(list_volume_response) - len(self.volumes), + len(list_volume_response), 4, "ListVolumes response expected 4 Volumes, received %s" % len(list_volume_response) ) @@ -276,7 +273,7 @@ def test_05_list_volumes_isrecursive(self): "List Volume response is not a valid list" ) self.assertEqual( - len(list_volume_response) - len(self.volumes), + len(list_volume_response), 3, "ListVolumes response expected 3 Volumes, received %s" % len(list_volume_response) ) @@ -319,7 +316,7 @@ def test_07_list_volumes_listall(self): "List Volume response is not a valid list" ) self.assertEqual( - len(list_volume_response) - len(self.volumes), + len(list_volume_response), 4, "ListVolumes response expected 4 Volumes, received %s" % len(list_volume_response) ) @@ -334,7 +331,7 @@ def test_07_list_volumes_listall(self): "List Volume response is not a valid list" ) self.assertEqual( - len(list_volume_response) - len(self.volumes), + len(list_volume_response), 3, "ListVolumes response expected 3 Volumes, received %s" % len(list_volume_response) ) diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index d178b6ec139b..bf7061621ff9 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -23,7 +23,8 @@ Network, NetworkACL, NetworkOffering, - VirtualMachine + VirtualMachine, + Volume ) @@ -98,12 +99,32 @@ def cleanup_resources(cls, api_client, resources): """ Delete resources (created during tests) """ + volume_list = [] for obj in resources: if isinstance(obj, VirtualMachine): obj.delete(api_client, expunge=True) + if isinstance(obj, Volume): + obj.destroy(api_client, expunge=True) + volume_list.append(obj) else: obj.delete(api_client) + cls.wait_for_volumes_cleanup(api_client, volume_list) + + def wait_for_volumes_cleanup(cls, api_client, volume_list): + """Wait for volumes to be deleted""" + for volume in volume_list: + max_retries = 24 # Max wait time will be 5 * 12 = 120 seconds + while max_retries > 0: + volumes = Volume.list( + api_client, + id=volume.id + ) + if volumes is None or len(volumes) == 0: + break + max_retries = max_retries - 1 + time.sleep(5) + def check_wget_from_vm(self, vm, public_ip, network=None, testnegative=False, isVmAccessible=True): import urllib.request, urllib.error self.debug(f"Checking if we can wget from a VM={vm.name} http server on public_ip={public_ip.ipaddress.ipaddress}, expecting failure == {testnegative} and vm is acceccible == {isVmAccessible}")