test cleanup (#4473)

* test accounts cleanup

* cleanup VMs to let offering go

* cleanup VM to let template go

* conditionally un-register VMs for cleanup

* cleanup durin python3 port of tests

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2021-04-06 11:26:58 +02:00 committed by GitHub
parent ca5c11a29a
commit 2621c3d287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 37 deletions

View File

@ -220,6 +220,7 @@ class TestAccounts(cloudstackTestCase):
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 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
)
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 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
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 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
# 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 @@ class TestAddVmToSubDomain(cloudstackTestCase):
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 @@ class TestAddVmToSubDomain(cloudstackTestCase):
domainid=cls.account_2.domainid,
serviceofferingid=cls.service_offering.id
)
cls._cleanup.append(cls.vm_2)
return
@classmethod
@ -1812,6 +1817,7 @@ class TestDomainForceRemove(cloudstackTestCase):
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 @@ class TestDomainForceRemove(cloudstackTestCase):
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 @@ class TestDomainForceRemove(cloudstackTestCase):
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 @@ class TestDomainForceRemove(cloudstackTestCase):
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 @@ class TestDomainForceRemove(cloudstackTestCase):
domainid=self.account_2.domainid,
serviceofferingid=self.service_offering.id
)
self.cleanup.append(vm_2)
networks = Network.list(
self.apiclient,
@ -1927,15 +1940,16 @@ class TestDomainForceRemove(cloudstackTestCase):
"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 @@ class TestDomainForceRemove(cloudstackTestCase):
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 @@ class TestDomainForceRemove(cloudstackTestCase):
domainid=self.account_2.domainid,
serviceofferingid=self.service_offering.id
)
self.cleanup.append(vm_2)
networks = Network.list(
self.apiclient,
@ -2110,6 +2126,7 @@ class TestDomainForceRemove(cloudstackTestCase):
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):

View File

@ -56,11 +56,14 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
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 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
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 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
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)
cls._cleanup = [
cls.service_offering,
cls.ag,
cls.project,
cls.account,
]
return
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 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
serviceofferingid=self.service_offering.id,
affinitygroupnames=[self.ag.name]
)
self.cleanup.append(vm1)
list_vm1 = list_virtual_machines(
self.apiclient,
@ -149,6 +159,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
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 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
@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()

View File

@ -45,28 +45,24 @@ class TestAsyncJob(cloudstackTestCase):
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 @@ class TestAsyncJob(cloudstackTestCase):
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 @@ class TestAsyncJob(cloudstackTestCase):
diskofferingid=self.disk_offering.id,
hypervisor=self.hypervisor
)
self.cleanup.append(virtual_machine)
response = virtual_machine.getState(
self.apiclient,

View File

@ -71,9 +71,9 @@ class TestHostHA(cloudstackTestCase):
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):