From 8ce45a3a7f99da9e71596a3eff86d15aa65a0556 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 21 Dec 2023 10:51:52 +0530 Subject: [PATCH 1/5] Fixup test_list_volumes.py failure --- test/integration/smoke/test_list_volumes.py | 32 +++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/test/integration/smoke/test_list_volumes.py b/test/integration/smoke/test_list_volumes.py index b08e9cf3b383..a7a4753044e6 100644 --- a/test/integration/smoke/test_list_volumes.py +++ b/test/integration/smoke/test_list_volumes.py @@ -28,6 +28,7 @@ VirtualMachine) from marvin.lib.common import (get_domain, list_accounts, list_zones, list_clusters, list_hosts, get_suitable_test_template) +from marvin.lib.utils import wait_until # Import System modules from nose.plugins.attrib import attr @@ -76,8 +77,7 @@ 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 [] + cls.wait_for_volume_cleanup() # Create VM cls.virtual_machine = VirtualMachine.create( @@ -140,6 +140,26 @@ def setUpClass(cls): def tearDownClass(cls): super(TestListVolumes, cls).tearDownClass() + @classmethod + def wait_for_volume_cleanup(cls): + """Clean up volumes that were left by previous tests + """ + def check_volumes_status(): + result = False + volumes = Volume.list( + cls.apiclient, + listall=True + ) + if volumes is None or len(volumes) == 0: + return True + + for volume in volumes: + if volume.state not in ['Ready', 'Allocated']: + result = False + return result + + wait_until(10, 30, check_volumes_status) + @attr(tags=["advanced", "advancedns", "smoke", "basic"], required_hardware="false") def test_01_list_volumes_account_domain_filter(self): """Test listing Volumes with account & domain filter @@ -260,7 +280,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 +296,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 +339,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 +354,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) ) From 7283100aac51cffe26712d2141c9ac52add6b87a Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 21 Dec 2023 11:24:05 +0530 Subject: [PATCH 2/5] Update test/integration/smoke/test_list_volumes.py Co-authored-by: Suresh Kumar Anaparti --- test/integration/smoke/test_list_volumes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/smoke/test_list_volumes.py b/test/integration/smoke/test_list_volumes.py index a7a4753044e6..3f733b0b34f4 100644 --- a/test/integration/smoke/test_list_volumes.py +++ b/test/integration/smoke/test_list_volumes.py @@ -142,7 +142,7 @@ def tearDownClass(cls): @classmethod def wait_for_volume_cleanup(cls): - """Clean up volumes that were left by previous tests + """Wait for volumes to clean up that were left by previous tests """ def check_volumes_status(): result = False From f423235c22a6690e23fea01fcc53b84f613ec255 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 21 Dec 2023 12:55:06 +0530 Subject: [PATCH 3/5] Fixup --- test/integration/smoke/test_list_volumes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/integration/smoke/test_list_volumes.py b/test/integration/smoke/test_list_volumes.py index 3f733b0b34f4..401379ed5c9f 100644 --- a/test/integration/smoke/test_list_volumes.py +++ b/test/integration/smoke/test_list_volumes.py @@ -45,6 +45,9 @@ def setUpClass(cls): cls.hypervisor = testClient.getHypervisorInfo() cls.domain = get_domain(cls.apiclient) cls.zones = list_zones(cls.apiclient) + import ipdb; ipdb.set_trace() + cls.wait_for_volume_cleanup() + import ipdb; ipdb.set_trace() cls.zone = cls.zones[0] cls.clusters = list_clusters(cls.apiclient) cls.cluster = cls.clusters[0] @@ -77,8 +80,6 @@ def setUpClass(cls): cls.services["disk_offering"]) cls._cleanup.append(cls.disk_offering) - cls.wait_for_volume_cleanup() - # Create VM cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -151,12 +152,12 @@ def check_volumes_status(): listall=True ) if volumes is None or len(volumes) == 0: - return True + return True, None for volume in volumes: if volume.state not in ['Ready', 'Allocated']: result = False - return result + return result, None wait_until(10, 30, check_volumes_status) From 3b47c569ec044ffe727ab59eba443016c5677720 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 21 Dec 2023 14:33:01 +0530 Subject: [PATCH 4/5] Wait for volumes to be deleted on cleanup --- test/integration/smoke/test_list_volumes.py | 24 --------------------- tools/marvin/marvin/cloudstackTestCase.py | 20 +++++++++++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/test/integration/smoke/test_list_volumes.py b/test/integration/smoke/test_list_volumes.py index 401379ed5c9f..aea775f19ccc 100644 --- a/test/integration/smoke/test_list_volumes.py +++ b/test/integration/smoke/test_list_volumes.py @@ -28,7 +28,6 @@ VirtualMachine) from marvin.lib.common import (get_domain, list_accounts, list_zones, list_clusters, list_hosts, get_suitable_test_template) -from marvin.lib.utils import wait_until # Import System modules from nose.plugins.attrib import attr @@ -45,9 +44,6 @@ def setUpClass(cls): cls.hypervisor = testClient.getHypervisorInfo() cls.domain = get_domain(cls.apiclient) cls.zones = list_zones(cls.apiclient) - import ipdb; ipdb.set_trace() - cls.wait_for_volume_cleanup() - import ipdb; ipdb.set_trace() cls.zone = cls.zones[0] cls.clusters = list_clusters(cls.apiclient) cls.cluster = cls.clusters[0] @@ -141,26 +137,6 @@ def setUpClass(cls): def tearDownClass(cls): super(TestListVolumes, cls).tearDownClass() - @classmethod - def wait_for_volume_cleanup(cls): - """Wait for volumes to clean up that were left by previous tests - """ - def check_volumes_status(): - result = False - volumes = Volume.list( - cls.apiclient, - listall=True - ) - if volumes is None or len(volumes) == 0: - return True, None - - for volume in volumes: - if volume.state not in ['Ready', 'Allocated']: - result = False - return result, None - - wait_until(10, 30, check_volumes_status) - @attr(tags=["advanced", "advancedns", "smoke", "basic"], required_hardware="false") def test_01_list_volumes_account_domain_filter(self): """Test listing Volumes with account & domain filter diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index d178b6ec139b..65a8b028ca01 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -98,12 +98,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}") From 49f385cbbadb606ca8f8c8bd45683df29867ac7e Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 21 Dec 2023 20:28:25 +0530 Subject: [PATCH 5/5] Fixup --- tools/marvin/marvin/cloudstackTestCase.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index 65a8b028ca01..bf7061621ff9 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -23,7 +23,8 @@ Network, NetworkACL, NetworkOffering, - VirtualMachine + VirtualMachine, + Volume )