Skip to content

Commit 7e769db

Browse files
author
Daan Hoogland
committed
test accounts cleanup
1 parent 7f408ec commit 7e769db

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

test/integration/smoke/test_accounts.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def test_01_create_account(self):
220220
account=account.name,
221221
domainid=account.domainid
222222
)
223+
self.cleanup.append(user)
223224
self.debug("Created user: %s" % user.id)
224225
list_users_response = list_users(
225226
self.apiclient,
@@ -324,20 +325,20 @@ def setUpClass(cls):
324325
)
325326
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
326327
cls.services["virtual_machine"]["template"] = cls.template.id
328+
cls._cleanup = []
327329

328330
cls.service_offering = ServiceOffering.create(
329331
cls.api_client,
330332
cls.services["service_offering"]
331333
)
334+
cls._cleanup.append(cls.service_offering)
332335
# Create an account
333336
cls.account = Account.create(
334337
cls.api_client,
335338
cls.services["account"]
336339
)
340+
cls._cleanup.append(cls.account)
337341

338-
cls._cleanup = [cls.account,
339-
cls.service_offering,
340-
]
341342
return
342343

343344
@classmethod
@@ -380,6 +381,7 @@ def test_01_user_remove_VM_running(self):
380381
domainid=self.account.domainid
381382
)
382383
self.debug("Created user: %s" % user_1.id)
384+
self.cleanup.append(user_1)
383385

384386
user_2 = User.create(
385387
self.apiclient,
@@ -419,6 +421,7 @@ def test_01_user_remove_VM_running(self):
419421
# Remove one of the user
420422
self.debug("Deleting user: %s" % user_1.id)
421423
user_1.delete(self.apiclient)
424+
self.cleanup.remove(user_1)
422425

423426
# Account should exist after deleting user
424427
accounts_response = list_accounts(
@@ -991,6 +994,7 @@ def setUpClass(cls):
991994
domainid=cls.account_1.domainid,
992995
serviceofferingid=cls.service_offering.id
993996
)
997+
cls._cleanup.append(cls.vm_1)
994998

995999
cls.vm_2 = VirtualMachine.create(
9961000
cls.api_client,
@@ -1000,6 +1004,7 @@ def setUpClass(cls):
10001004
domainid=cls.account_2.domainid,
10011005
serviceofferingid=cls.service_offering.id
10021006
)
1007+
cls._cleanup.append(cls.vm_2)
10031008
return
10041009

10051010
@classmethod
@@ -1812,6 +1817,7 @@ def test_forceDeleteDomain(self):
18121817
self.services["domain"],
18131818
parentdomainid=self.domain.id
18141819
)
1820+
self.cleanup.append(domain)
18151821
self.debug("Domain is created succesfully.")
18161822
self.debug(
18171823
"Checking if the created domain is listed in list domains API")
@@ -1828,12 +1834,14 @@ def test_forceDeleteDomain(self):
18281834
self.services["account"],
18291835
domainid=domain.id
18301836
)
1837+
self.cleanup.append(self.account_1)
18311838

18321839
self.account_2 = Account.create(
18331840
self.apiclient,
18341841
self.services["account"],
18351842
domainid=domain.id
18361843
)
1844+
self.cleanup.append(self.account_2)
18371845

18381846
try:
18391847
self.debug("Creating a tiny service offering for VM deployment")
@@ -1842,6 +1850,7 @@ def test_forceDeleteDomain(self):
18421850
self.services["service_offering"],
18431851
domainid=self.domain.id
18441852
)
1853+
self.cleanup.append(self.service_offering)
18451854

18461855
self.debug("Deploying virtual machine in account 1: %s" %
18471856
self.account_1.name)
@@ -1853,17 +1862,19 @@ def test_forceDeleteDomain(self):
18531862
domainid=self.account_1.domainid,
18541863
serviceofferingid=self.service_offering.id
18551864
)
1865+
self.cleanup.append(vm_1)
18561866

18571867
self.debug("Deploying virtual machine in account 2: %s" %
18581868
self.account_2.name)
1859-
VirtualMachine.create(
1869+
vm_2 = VirtualMachine.create(
18601870
self.apiclient,
18611871
self.services["virtual_machine"],
18621872
templateid=self.template.id,
18631873
accountid=self.account_2.name,
18641874
domainid=self.account_2.domainid,
18651875
serviceofferingid=self.service_offering.id
18661876
)
1877+
self.cleanup.append(vm_2)
18671878

18681879
networks = Network.list(
18691880
self.apiclient,
@@ -1927,15 +1938,12 @@ def test_forceDeleteDomain(self):
19271938
"Length of response from listLbRules should not be 0"
19281939
)
19291940
except Exception as e:
1930-
self.cleanup.append(self.domain)
1931-
self.cleanup.append(self.account_1)
1932-
self.cleanup.append(self.account_2)
1933-
self.cleanup.append(self.service_offering)
19341941
self.fail(e)
19351942

19361943
self.debug("Deleting domain with force option")
19371944
try:
19381945
domain.delete(self.apiclient, cleanup=True)
1946+
self.cleanup.remove(domain)
19391947
except Exception as e:
19401948
self.debug("Waiting for account.cleanup.interval" +
19411949
" to cleanup any remaining resouces")
@@ -2033,17 +2041,19 @@ def test_DeleteDomain(self):
20332041
domainid=self.account_1.domainid,
20342042
serviceofferingid=self.service_offering.id
20352043
)
2044+
self.cleanup.append(vm_1)
20362045

20372046
self.debug("Deploying virtual machine in account 2: %s" %
20382047
self.account_2.name)
2039-
VirtualMachine.create(
2048+
vm_2 = VirtualMachine.create(
20402049
self.apiclient,
20412050
self.services["virtual_machine"],
20422051
templateid=self.template.id,
20432052
accountid=self.account_2.name,
20442053
domainid=self.account_2.domainid,
20452054
serviceofferingid=self.service_offering.id
20462055
)
2056+
self.cleanup.append(vm_2)
20472057

20482058
networks = Network.list(
20492059
self.apiclient,
@@ -2110,6 +2120,7 @@ def test_DeleteDomain(self):
21102120
self.debug("Deleting domain without force option")
21112121
with self.assertRaises(Exception):
21122122
domain.delete(self.apiclient, cleanup=False)
2123+
# TODO should domain be removed from self.cleanup or can it remain in the list?
21132124
return
21142125

21152126
class TestMoveUser(cloudstackTestCase):

0 commit comments

Comments
 (0)