From ad99c77d3b051a04a16eb7452362206a1e46039f Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Fri, 10 Feb 2023 09:57:55 +0100 Subject: [PATCH 1/6] cleanup in resource housekeeping --- .../smoke/test_deploy_vm_extra_config_data.py | 43 ++++++------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/test/integration/smoke/test_deploy_vm_extra_config_data.py b/test/integration/smoke/test_deploy_vm_extra_config_data.py index 80b046102ca9..e6866865ef85 100644 --- a/test/integration/smoke/test_deploy_vm_extra_config_data.py +++ b/test/integration/smoke/test_deploy_vm_extra_config_data.py @@ -63,34 +63,27 @@ def setUpClass(cls): cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls._cleanup = [] + # Create an account, network, and IP addresses cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) + cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"] ) - - cls.cleanup = [ - cls.account, - cls.service_offering - ] + cls._cleanup.append(cls.service_offering) cls.hosts_hugepages = cls.set_hosts_hugepages() @classmethod def tearDownClass(cls): - try: - cls.apiclient = super(TestAddConfigtoDeployVM, cls).getClsTestClient().getApiClient() - cls.reset_hosts_hugepages() - # Clean up, terminate the created templates - cleanup_resources(cls.apiclient, cls.cleanup) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) + super(TestAddConfigtoDeployVM, cls).tearDownClass() @classmethod def set_hosts_hugepages(cls): @@ -130,6 +123,10 @@ def setUp(self): updateConfigurationResponse = self.apiclient.updateConfiguration(updateConfigurationCmd) self.debug("updated the parameter %s with value %s" % ( updateConfigurationResponse.name, updateConfigurationResponse.value)) + self.cleanup = [] + + def tearDown(self): + super(TestAddConfigtoDeployVM, self).tearDown() # Ste Global Config value def add_global_config(self, name, value): @@ -152,12 +149,6 @@ def elements_equal(self, e1, e2): return False return all(self.elements_equal(c1, c2) for c1, c2 in zip(e1, e2)) - def destroy_vm(self, vm_id): - cmd = destroyVirtualMachine.destroyVirtualMachineCmd() - cmd.expunge = True - cmd.id = vm_id - return self.apiclient.destroyVirtualMachine(cmd) - def deploy_vm(self, hypervisor, extra_config=None): cmd = deployVirtualMachine.deployVirtualMachineCmd() if extra_config is not None: @@ -171,7 +162,9 @@ def deploy_vm(self, hypervisor, extra_config=None): cmd.zoneid = self.zone.id cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id - return self.apiclient.deployVirtualMachine(cmd) + vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) + return vm def list_vm(self): cmd = listVirtualMachines.listVirtualMachinesCmd() @@ -245,8 +238,6 @@ def test_01_deploy_vm_with_extraconfig_throws_exception_kvm(self): "Exception was not thrown, check kvm global configuration") except Exception as e: logging.debug(e) - finally: - self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_02_deploy_vm_with_extraconfig_kvm(self): @@ -316,7 +307,6 @@ def test_02_deploy_vm_with_extraconfig_kvm(self): 'The element from tags from extra config do not match with those found in domain xml' ) finally: - self.destroy_vm(response.id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -395,7 +385,6 @@ def test_03_update_vm_with_extraconfig_kvm(self): 'The element from tags from extra config do not match with those found in domain xml' ) finally: - self.destroy_vm(vm_id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -424,8 +413,6 @@ def test_04_deploy_vm_with_extraconfig_throws_exception_vmware(self): "Exception was not thrown, check VMWARE global configuration") except Exception as e: logging.debug(e) - finally: - self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_05_deploy_vm_with_extraconfig_vmware(self): @@ -478,7 +465,6 @@ def test_05_deploy_vm_with_extraconfig_vmware(self): 'Extra configuration not found in instance vmx file' ) finally: - self.destroy_vm(response.id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -511,8 +497,6 @@ def test_06_deploy_vm_with_extraconfig_throws_exception_xenserver(self): except Exception as e: logging.debug(e) - finally: - self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_07_deploy_vm_with_extraconfig_xenserver(self): @@ -564,5 +548,4 @@ def test_07_deploy_vm_with_extraconfig_xenserver(self): 'Extra configuration not found in VM param list' ) finally: - self.destroy_vm(response.id) self.add_global_config(name, "") From 1d140bd215b29c7a5ec4cbfb9eabf0465a8864d9 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Fri, 10 Feb 2023 10:13:29 +0100 Subject: [PATCH 2/6] cleanup in resource housekeeping --- .../smoke/test_vm_deployment_planner.py | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/test/integration/smoke/test_vm_deployment_planner.py b/test/integration/smoke/test_vm_deployment_planner.py index 636eaaceb5a6..24a6457d0ce2 100644 --- a/test/integration/smoke/test_vm_deployment_planner.py +++ b/test/integration/smoke/test_vm_deployment_planner.py @@ -45,26 +45,30 @@ def setUpClass(cls): cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls._cleanup = [] # Create an account, network, VM and IP addresses cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) - - cls._cleanup = [ - cls.account, - cls.service_offering - ] + cls._cleanup.append(cls.service_offering) @classmethod def tearDownClass(cls): super(TestVMDeploymentPlanner, cls).tearDownClass() + def setUp(self): + self.cleanup = [] + + def tearDown(self): + super(TestVMDeploymentPlanner, self).tearDown() + def deploy_vm(self, destination_id): cmd = deployVirtualMachine.deployVirtualMachineCmd() template = get_template( @@ -76,13 +80,9 @@ def deploy_vm(self, destination_id): cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id cmd.hostid = destination_id - return self.apiclient.deployVirtualMachine(cmd) - - def destroy_vm(self, vm_id): - cmd = destroyVirtualMachine.destroyVirtualMachineCmd() - cmd.expunge = True - cmd.id = vm_id - return self.apiclient.destroyVirtualMachine(cmd) + vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) + return vm @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_01_deploy_vm_on_specific_host(self): @@ -100,8 +100,6 @@ def test_01_deploy_vm_on_specific_host(self): vm.hostid, "VM instance was not deployed on target host ID") - self.destroy_vm(vm.id) - @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_02_deploy_vm_on_specific_cluster(self): @@ -125,6 +123,7 @@ def test_02_deploy_vm_on_specific_cluster(self): cmd.templateid = template.id cmd.clusterid = target_id vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -135,7 +134,6 @@ def test_02_deploy_vm_on_specific_cluster(self): vm_host[0].clusterid, "VM was not deployed on the provided cluster" ) - self.destroy_vm(vm.id) @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_03_deploy_vm_on_specific_pod(self): @@ -162,6 +160,7 @@ def test_03_deploy_vm_on_specific_pod(self): cmd.templateid = template.id cmd.podid = target_pod.id vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -172,7 +171,6 @@ def test_03_deploy_vm_on_specific_pod(self): vm_host[0].podid, "VM was not deployed on the target pod" ) - self.destroy_vm(vm.id) @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_04_deploy_vm_on_host_override_pod_and_cluster(self): @@ -203,6 +201,7 @@ def test_04_deploy_vm_on_host_override_pod_and_cluster(self): cmd.hostid = host.id vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) self.assertEqual( vm.hostid, @@ -210,8 +209,6 @@ def test_04_deploy_vm_on_host_override_pod_and_cluster(self): "VM was not deployed on the target host ID" ) - self.destroy_vm(vm.id) - @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_05_deploy_vm_on_cluster_override_pod(self): @@ -238,6 +235,7 @@ def test_05_deploy_vm_on_cluster_override_pod(self): cmd.clusterid = clusters[0].id vm = self.apiclient.deployVirtualMachine(cmd) + self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -248,5 +246,3 @@ def test_05_deploy_vm_on_cluster_override_pod(self): clusters[0].id, "VM was not deployed on the target cluster" ) - - self.destroy_vm(vm.id) From 73a9ec191d09d99f78093bc4356ec6b2bd98d1e4 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 10 Feb 2023 11:07:51 +0100 Subject: [PATCH 3/6] Update test/integration/smoke/test_deploy_vm_extra_config_data.py Co-authored-by: dahn --- test/integration/smoke/test_deploy_vm_extra_config_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/smoke/test_deploy_vm_extra_config_data.py b/test/integration/smoke/test_deploy_vm_extra_config_data.py index e6866865ef85..f31d80ef1f78 100644 --- a/test/integration/smoke/test_deploy_vm_extra_config_data.py +++ b/test/integration/smoke/test_deploy_vm_extra_config_data.py @@ -84,6 +84,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): super(TestAddConfigtoDeployVM, cls).tearDownClass() + cls.reset_hosts_hugepages() @classmethod def set_hosts_hugepages(cls): From 278d56d68aeb9d0a8470e3cea2190ab5f26952d2 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 13 Feb 2023 11:16:52 +0100 Subject: [PATCH 4/6] revert most cleanup code --- .../smoke/test_deploy_vm_extra_config_data.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/integration/smoke/test_deploy_vm_extra_config_data.py b/test/integration/smoke/test_deploy_vm_extra_config_data.py index f31d80ef1f78..318febb7a1ee 100644 --- a/test/integration/smoke/test_deploy_vm_extra_config_data.py +++ b/test/integration/smoke/test_deploy_vm_extra_config_data.py @@ -64,7 +64,6 @@ def setUpClass(cls): cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls._cleanup = [] - # Create an account, network, and IP addresses cls.account = Account.create( cls.apiclient, @@ -72,7 +71,6 @@ def setUpClass(cls): domainid=cls.domain.id ) cls._cleanup.append(cls.account) - cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"] @@ -83,8 +81,8 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - super(TestAddConfigtoDeployVM, cls).tearDownClass() cls.reset_hosts_hugepages() + super(TestAddConfigtoDeployVM, cls).tearDownClass() @classmethod def set_hosts_hugepages(cls): @@ -124,10 +122,6 @@ def setUp(self): updateConfigurationResponse = self.apiclient.updateConfiguration(updateConfigurationCmd) self.debug("updated the parameter %s with value %s" % ( updateConfigurationResponse.name, updateConfigurationResponse.value)) - self.cleanup = [] - - def tearDown(self): - super(TestAddConfigtoDeployVM, self).tearDown() # Ste Global Config value def add_global_config(self, name, value): @@ -150,6 +144,12 @@ def elements_equal(self, e1, e2): return False return all(self.elements_equal(c1, c2) for c1, c2 in zip(e1, e2)) + def destroy_vm(self, vm_id): + cmd = destroyVirtualMachine.destroyVirtualMachineCmd() + cmd.expunge = True + cmd.id = vm_id + return self.apiclient.destroyVirtualMachine(cmd) + def deploy_vm(self, hypervisor, extra_config=None): cmd = deployVirtualMachine.deployVirtualMachineCmd() if extra_config is not None: @@ -163,9 +163,7 @@ def deploy_vm(self, hypervisor, extra_config=None): cmd.zoneid = self.zone.id cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id - vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) - return vm + return self.apiclient.deployVirtualMachine(cmd) def list_vm(self): cmd = listVirtualMachines.listVirtualMachinesCmd() @@ -239,6 +237,8 @@ def test_01_deploy_vm_with_extraconfig_throws_exception_kvm(self): "Exception was not thrown, check kvm global configuration") except Exception as e: logging.debug(e) + finally: + self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_02_deploy_vm_with_extraconfig_kvm(self): @@ -308,6 +308,7 @@ def test_02_deploy_vm_with_extraconfig_kvm(self): 'The element from tags from extra config do not match with those found in domain xml' ) finally: + self.destroy_vm(response.id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -386,6 +387,7 @@ def test_03_update_vm_with_extraconfig_kvm(self): 'The element from tags from extra config do not match with those found in domain xml' ) finally: + self.destroy_vm(vm_id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -414,6 +416,8 @@ def test_04_deploy_vm_with_extraconfig_throws_exception_vmware(self): "Exception was not thrown, check VMWARE global configuration") except Exception as e: logging.debug(e) + finally: + self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_05_deploy_vm_with_extraconfig_vmware(self): @@ -466,6 +470,7 @@ def test_05_deploy_vm_with_extraconfig_vmware(self): 'Extra configuration not found in instance vmx file' ) finally: + self.destroy_vm(response.id) self.add_global_config(name, "") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") @@ -498,6 +503,8 @@ def test_06_deploy_vm_with_extraconfig_throws_exception_xenserver(self): except Exception as e: logging.debug(e) + finally: + self.destroy_vm(self.list_vm().id) @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true") def test_07_deploy_vm_with_extraconfig_xenserver(self): @@ -549,4 +556,5 @@ def test_07_deploy_vm_with_extraconfig_xenserver(self): 'Extra configuration not found in VM param list' ) finally: + self.destroy_vm(response.id) self.add_global_config(name, "") From c26ff09f1bdf4a899d47559487a6fe8cea284eb6 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 13 Feb 2023 12:09:35 +0100 Subject: [PATCH 5/6] Revert "cleanup in resource housekeeping" This reverts commit 1d140bd215b29c7a5ec4cbfb9eabf0465a8864d9. --- .../smoke/test_vm_deployment_planner.py | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/test/integration/smoke/test_vm_deployment_planner.py b/test/integration/smoke/test_vm_deployment_planner.py index 24a6457d0ce2..636eaaceb5a6 100644 --- a/test/integration/smoke/test_vm_deployment_planner.py +++ b/test/integration/smoke/test_vm_deployment_planner.py @@ -45,30 +45,26 @@ def setUpClass(cls): cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls._cleanup = [] # Create an account, network, VM and IP addresses cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - cls._cleanup.append(cls.account) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) - cls._cleanup.append(cls.service_offering) + + cls._cleanup = [ + cls.account, + cls.service_offering + ] @classmethod def tearDownClass(cls): super(TestVMDeploymentPlanner, cls).tearDownClass() - def setUp(self): - self.cleanup = [] - - def tearDown(self): - super(TestVMDeploymentPlanner, self).tearDown() - def deploy_vm(self, destination_id): cmd = deployVirtualMachine.deployVirtualMachineCmd() template = get_template( @@ -80,9 +76,13 @@ def deploy_vm(self, destination_id): cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id cmd.hostid = destination_id - vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) - return vm + return self.apiclient.deployVirtualMachine(cmd) + + def destroy_vm(self, vm_id): + cmd = destroyVirtualMachine.destroyVirtualMachineCmd() + cmd.expunge = True + cmd.id = vm_id + return self.apiclient.destroyVirtualMachine(cmd) @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_01_deploy_vm_on_specific_host(self): @@ -100,6 +100,8 @@ def test_01_deploy_vm_on_specific_host(self): vm.hostid, "VM instance was not deployed on target host ID") + self.destroy_vm(vm.id) + @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_02_deploy_vm_on_specific_cluster(self): @@ -123,7 +125,6 @@ def test_02_deploy_vm_on_specific_cluster(self): cmd.templateid = template.id cmd.clusterid = target_id vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -134,6 +135,7 @@ def test_02_deploy_vm_on_specific_cluster(self): vm_host[0].clusterid, "VM was not deployed on the provided cluster" ) + self.destroy_vm(vm.id) @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_03_deploy_vm_on_specific_pod(self): @@ -160,7 +162,6 @@ def test_03_deploy_vm_on_specific_pod(self): cmd.templateid = template.id cmd.podid = target_pod.id vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -171,6 +172,7 @@ def test_03_deploy_vm_on_specific_pod(self): vm_host[0].podid, "VM was not deployed on the target pod" ) + self.destroy_vm(vm.id) @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_04_deploy_vm_on_host_override_pod_and_cluster(self): @@ -201,7 +203,6 @@ def test_04_deploy_vm_on_host_override_pod_and_cluster(self): cmd.hostid = host.id vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) self.assertEqual( vm.hostid, @@ -209,6 +210,8 @@ def test_04_deploy_vm_on_host_override_pod_and_cluster(self): "VM was not deployed on the target host ID" ) + self.destroy_vm(vm.id) + @attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false") def test_05_deploy_vm_on_cluster_override_pod(self): @@ -235,7 +238,6 @@ def test_05_deploy_vm_on_cluster_override_pod(self): cmd.clusterid = clusters[0].id vm = self.apiclient.deployVirtualMachine(cmd) - self.cleanup.append(vm) vm_host = Host.list(self.apiclient, id=vm.hostid @@ -246,3 +248,5 @@ def test_05_deploy_vm_on_cluster_override_pod(self): clusters[0].id, "VM was not deployed on the target cluster" ) + + self.destroy_vm(vm.id) From 2692fed702cf3402d6324881a88744437d730261 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 13 Feb 2023 12:12:45 +0100 Subject: [PATCH 6/6] add extra config to VirtualMachine.create(..) --- tools/marvin/marvin/lib/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py index a9f8e06cdddc..9d28d5a3f2a0 100755 --- a/tools/marvin/marvin/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -522,7 +522,8 @@ def create(cls, apiclient, services, templateid=None, accountid=None, method='GET', hypervisor=None, customcpunumber=None, customcpuspeed=None, custommemory=None, rootdisksize=None, rootdiskcontroller=None, vpcid=None, macaddress=None, datadisktemplate_diskoffering_list={}, - properties=None, nicnetworklist=None, bootmode=None, boottype=None, dynamicscalingenabled=None, userdataid=None, userdatadetails=None): + properties=None, nicnetworklist=None, bootmode=None, boottype=None, dynamicscalingenabled=None, + userdataid=None, userdatadetails=None, extraconfig=None): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -678,6 +679,9 @@ def create(cls, apiclient, services, templateid=None, accountid=None, if boottype: cmd.boottype = boottype + if extraconfig: + cmd.extraconfig = extraconfig + virtual_machine = apiclient.deployVirtualMachine(cmd, method=method) if 'password' in list(virtual_machine.__dict__.keys()):