diff --git a/test/integration/smoke/test_accounts.py b/test/integration/smoke/test_accounts.py index bec615d6f5ae..1c1cf02f775a 100644 --- a/test/integration/smoke/test_accounts.py +++ b/test/integration/smoke/test_accounts.py @@ -220,6 +220,7 @@ def test_01_create_account(self): account=account.name, domainid=account.domainid ) + self.cleanup.append(user) self.debug("Created user: %s" % user.id) list_users_response = list_users( self.apiclient, @@ -324,20 +325,20 @@ def setUpClass(cls): ) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id + cls._cleanup = [] cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) + cls._cleanup.append(cls.service_offering) # Create an account cls.account = Account.create( cls.api_client, cls.services["account"] ) + cls._cleanup.append(cls.account) - cls._cleanup = [cls.account, - cls.service_offering, - ] return @classmethod @@ -380,6 +381,7 @@ def test_01_user_remove_VM_running(self): domainid=self.account.domainid ) self.debug("Created user: %s" % user_1.id) + self.cleanup.append(user_1) user_2 = User.create( self.apiclient, @@ -419,6 +421,7 @@ def test_01_user_remove_VM_running(self): # Remove one of the user self.debug("Deleting user: %s" % user_1.id) user_1.delete(self.apiclient) + self.cleanup.remove(user_1) # Account should exist after deleting user accounts_response = list_accounts( @@ -991,6 +994,7 @@ def setUpClass(cls): domainid=cls.account_1.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.vm_1) cls.vm_2 = VirtualMachine.create( cls.api_client, @@ -1000,6 +1004,7 @@ def setUpClass(cls): domainid=cls.account_2.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.vm_2) return @classmethod @@ -1812,6 +1817,7 @@ def test_forceDeleteDomain(self): self.services["domain"], parentdomainid=self.domain.id ) + self.cleanup.append(domain) self.debug("Domain is created succesfully.") self.debug( "Checking if the created domain is listed in list domains API") @@ -1828,13 +1834,17 @@ def test_forceDeleteDomain(self): self.services["account"], domainid=domain.id ) + self.cleanup.append(self.account_1) self.account_2 = Account.create( self.apiclient, self.services["account"], domainid=domain.id ) + self.cleanup.append(self.account_2) + vm_1 = None + vm_2 = None try: self.debug("Creating a tiny service offering for VM deployment") self.service_offering = ServiceOffering.create( @@ -1842,6 +1852,7 @@ def test_forceDeleteDomain(self): self.services["service_offering"], domainid=self.domain.id ) + self.cleanup.append(self.service_offering) self.debug("Deploying virtual machine in account 1: %s" % self.account_1.name) @@ -1853,10 +1864,11 @@ def test_forceDeleteDomain(self): domainid=self.account_1.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(vm_1) self.debug("Deploying virtual machine in account 2: %s" % self.account_2.name) - VirtualMachine.create( + vm_2 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, @@ -1864,6 +1876,7 @@ def test_forceDeleteDomain(self): domainid=self.account_2.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(vm_2) networks = Network.list( self.apiclient, @@ -1927,15 +1940,16 @@ def test_forceDeleteDomain(self): "Length of response from listLbRules should not be 0" ) except Exception as e: - self.cleanup.append(self.domain) - self.cleanup.append(self.account_1) - self.cleanup.append(self.account_2) - self.cleanup.append(self.service_offering) self.fail(e) self.debug("Deleting domain with force option") try: domain.delete(self.apiclient, cleanup=True) + self.cleanup.remove(domain) + if vm_1 != None: + self.cleanup.remove(vm_1) + if vm_2 != None: + self.cleanup.remove(vm_2) except Exception as e: self.debug("Waiting for account.cleanup.interval" + " to cleanup any remaining resouces") @@ -2033,10 +2047,11 @@ def test_DeleteDomain(self): domainid=self.account_1.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(vm_1) self.debug("Deploying virtual machine in account 2: %s" % self.account_2.name) - VirtualMachine.create( + vm_2 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, @@ -2044,6 +2059,7 @@ def test_DeleteDomain(self): domainid=self.account_2.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(vm_2) networks = Network.list( self.apiclient, @@ -2110,6 +2126,7 @@ def test_DeleteDomain(self): self.debug("Deleting domain without force option") with self.assertRaises(Exception): domain.delete(self.apiclient, cleanup=False) + # TODO should domain be removed from self.cleanup or can it remain in the list? return class TestMoveUser(cloudstackTestCase): diff --git a/test/integration/smoke/test_affinity_groups_projects.py b/test/integration/smoke/test_affinity_groups_projects.py index 76401c64adf2..d5029528675b 100644 --- a/test/integration/smoke/test_affinity_groups_projects.py +++ b/test/integration/smoke/test_affinity_groups_projects.py @@ -56,11 +56,14 @@ def setUpClass(cls): cls.services["template"] = cls.template.id cls.services["zoneid"] = cls.zone.id + cls._cleanup = [] + cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) projectData = { "name": "Project", @@ -73,6 +76,7 @@ def setUpClass(cls): account=cls.account.name, domainid=cls.account.domainid ) + cls._cleanup.append(cls.project) # Add user to the project cls.project.addAccount( @@ -84,17 +88,22 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering) cls.ag = AffinityGroup.create(cls.apiclient, cls.services["virtual_machine"]["affinity"],projectid=cls.project.id) + cls._cleanup.append(cls.ag) + + return - cls._cleanup = [ - cls.service_offering, - cls.ag, - cls.project, - cls.account, - ] + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] return + def tearDown(self): + super(TestDeployVmWithAffinityGroup,self).tearDown() + @attr(tags=["basic", "advanced", "multihost"], required_hardware="false") def test_DeployVmAntiAffinityGroup_in_project(self): """ @@ -112,6 +121,7 @@ def test_DeployVmAntiAffinityGroup_in_project(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) + self.cleanup.append(vm1) list_vm1 = list_virtual_machines( self.apiclient, @@ -149,6 +159,7 @@ def test_DeployVmAntiAffinityGroup_in_project(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) + self.cleanup.append(vm2) list_vm2 = list_virtual_machines( self.apiclient, id=vm2.id @@ -182,8 +193,4 @@ def test_DeployVmAntiAffinityGroup_in_project(self): @classmethod def tearDownClass(cls): - try: - #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(TestDeployVmWithAffinityGroup,cls).tearDownClass() diff --git a/test/integration/smoke/test_async_job.py b/test/integration/smoke/test_async_job.py index f727dd8d7d3f..b0e06ec4051f 100644 --- a/test/integration/smoke/test_async_job.py +++ b/test/integration/smoke/test_async_job.py @@ -45,28 +45,24 @@ def setUpClass(cls): cls.hypervisor ) + cls._cleanup = [] + # Create service, disk offerings etc cls.service_offering = ServiceOffering.create( cls.api_client, cls.testdata["service_offering"] ) + cls._cleanup.append(cls.service_offering) cls.disk_offering = DiskOffering.create( cls.api_client, cls.testdata["disk_offering"] ) - - cls._cleanup = [ - cls.service_offering, - cls.disk_offering - ] + cls._cleanup.append(cls.disk_offering) @classmethod def tearDownClass(cls): - try: - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as exception: - raise Exception("Warning: Exception during cleanup : %s" % exception) + super(TestAsyncJob,cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -83,12 +79,7 @@ def setUp(self): self.cleanup = [self.account] def tearDown(self): - try: - self.debug("Cleaning up the resources") - cleanup_resources(self.apiclient, self.cleanup) - self.debug("Cleanup complete!") - except Exception as exception: - self.debug("Warning! Exception in tearDown: %s" % exception) + super(TestAsyncJob,self).tearDown() @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") def test_query_async_job_result(self): @@ -106,6 +97,7 @@ def test_query_async_job_result(self): diskofferingid=self.disk_offering.id, hypervisor=self.hypervisor ) + self.cleanup.append(virtual_machine) response = virtual_machine.getState( self.apiclient, diff --git a/test/integration/smoke/test_hostha_simulator.py b/test/integration/smoke/test_hostha_simulator.py index bb25d477d02f..630512fdbe72 100644 --- a/test/integration/smoke/test_hostha_simulator.py +++ b/test/integration/smoke/test_hostha_simulator.py @@ -71,9 +71,9 @@ def tearDown(self): self.dbclient.execute("delete from data_center_details where name='resourceHAEnabled'") self.dbclient.execute("delete from ha_config where resource_type='Host'") self.dbclient.execute("update host set resource_state='Enabled' where type='Routing' and resource_state='Maintenance'") - cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) + raise Exception("Warning: Exception during db cleanup : %s" % e) + super(TestHostHA,self).tearDown() def getFakeMsId(self):