From a2ec1f3777824a8a5b877bf7e1b7bd600567cabd Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 19 Oct 2023 23:10:03 +0530 Subject: [PATCH] marvin,test: fix directdownload template checksum test (#8096) * marvin,test: fix directdownload template checksum test During failure while deploying a VM with wrong checksum template, VM may be left in Error state. This PR adds code to delete such VM. Signed-off-by: Abhishek Kumar * remove unnecessary logs --------- Signed-off-by: Abhishek Kumar --- test/integration/smoke/test_templates.py | 32 +++++++++++++----------- tools/marvin/marvin/lib/base.py | 2 ++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index bd5f522e440..66008b1a8f3 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -989,6 +989,8 @@ class TestTemplates(cloudstackTestCase): ) for template in list_template_response: + if template.directdownload == True: + continue self.assertNotEqual( len(template.downloaddetails), 0, @@ -1248,11 +1250,7 @@ class TestCreateTemplateWithDirectDownload(cloudstackTestCase): @classmethod def tearDownClass(cls): - try: - cleanup_resources(cls.apiclient, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestCreateTemplateWithDirectDownload, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1264,13 +1262,7 @@ class TestCreateTemplateWithDirectDownload(cloudstackTestCase): return def tearDown(self): - try: - #Clean up, terminate the created templates - cleanup_resources(self.apiclient, self.cleanup) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestCreateTemplateWithDirectDownload, self).tearDown() @attr(tags=["advanced", "smoke"], required_hardware="true") def test_01_register_template_direct_download_flag(self): @@ -1323,10 +1315,11 @@ class TestCreateTemplateWithDirectDownload(cloudstackTestCase): """ Deploy a VM from a Direct Download registered template with wrong checksum """ - self.template["checksum"]="{MD5}XXXXXXX" + self.template["checksum"]="{MD5}" + ("X" * 32) tmpl = Template.register(self.apiclient, self.template, zoneid=self.zone.id, hypervisor=self.hypervisor, randomize_name=False) self.cleanup.append(tmpl) + failed = False try: virtual_machine = VirtualMachine.create( self.apiclient, @@ -1337,8 +1330,19 @@ class TestCreateTemplateWithDirectDownload(cloudstackTestCase): serviceofferingid=self.service_offering.id ) self.cleanup.append(virtual_machine) - self.fail("Expected to fail deployment") + failed = True except Exception as e: self.debug("Expected exception") + list_virtual_machine_response = VirtualMachine.list( + self.apiclient, + templateid=tmpl.id, + listall=True + ) + if type(list_virtual_machine_response) == list and len(list_virtual_machine_response) > 0: + for virtual_machine_response in list_virtual_machine_response: + VirtualMachine.delete(virtual_machine_response, self.apiclient, expunge=True) + + if failed == True: + self.fail("Expected to fail VM deployment with wrong checksum template") return diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py index 9d28d5a3f2a..bf8a6a761b5 100755 --- a/tools/marvin/marvin/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -1518,6 +1518,8 @@ class Template: if "directdownload" in services: cmd.directdownload = services["directdownload"] + if "checksum" in services: + cmd.checksum = services["checksum"] # Register Template template = apiclient.registerTemplate(cmd)