Skip to content

Commit 59a9883

Browse files
Gaurav AradhyeGirish Shilamkar
authored andcommitted
CLOUDSTACK-6887: Fixing account cleanup issue across multiple test cases
1 parent 0c28f36 commit 59a9883

8 files changed

Lines changed: 176 additions & 148 deletions

File tree

test/integration/component/test_add_remove_network.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,22 +924,25 @@ def setUpClass(cls):
924924
# Create Accounts & networks
925925
cls.services["isolated_network"]["zoneid"] = cls.zone.id
926926
cls.services["shared_network"]["zoneid"] = cls.zone.id
927+
cls._cleanup = []
927928

928929
cls.account = Account.create(cls.api_client,cls.services["account"],domainid = cls.domain.id)
930+
cls._cleanup.append(cls.account)
929931

930932
cls.service_offering = ServiceOffering.create(cls.api_client,cls.services["service_offering"])
933+
cls._cleanup.append(cls.service_offering)
931934

932935
cls.virtual_machine = VirtualMachine.create(cls.api_client,cls.services["virtual_machine"],
933936
accountid=cls.account.name,domainid=cls.account.domainid,
934937
serviceofferingid=cls.service_offering.id,
935938
mode=cls.zone.networktype)
936939
# Create Shared Network Offering
937-
cls.isolated_network_offering = NetworkOffering.create(cls.api_client,cls.services["isolated_network_offering"],)
940+
cls.isolated_network_offering = NetworkOffering.create(cls.api_client,cls.services["isolated_network_offering"])
941+
cls._cleanup.append(cls.isolated_network_offering)
938942
# Enable Isolated Network offering
939943
cls.isolated_network_offering.update(cls.api_client, state='Enabled')
940944
cls.isolated_network = Network.create(cls.api_client,cls.services["isolated_network"],cls.account.name,
941945
cls.account.domainid,networkofferingid=cls.isolated_network_offering.id)
942-
cls._cleanup = [cls.account,cls.service_offering,cls.isolated_network_offering,]
943946
return
944947

945948
def setUp(self):

test/integration/component/test_persistent_networks.py

Lines changed: 125 additions & 89 deletions
Large diffs are not rendered by default.

test/integration/component/test_projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ def setUpClass(cls):
14741474
cls._cleanup = [
14751475
cls.project,
14761476
cls.account,
1477+
cls.user,
14771478
cls.disk_offering,
14781479
cls.service_offering
14791480
]

test/integration/component/test_snapshot_gc.py

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616
# under the License.
1717

1818
from nose.plugins.attrib import attr
19-
from marvin.cloudstackTestCase import *
20-
from marvin.cloudstackAPI import *
21-
from marvin.lib.utils import *
22-
from marvin.lib.base import *
23-
from marvin.lib.common import *
24-
from marvin.lib.utils import is_snapshot_on_nfs
25-
19+
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
20+
#from marvin.cloudstackAPI import *
21+
from marvin.lib.utils import (
22+
is_snapshot_on_nfs,
23+
cleanup_resources)
24+
from marvin.lib.base import (Account,
25+
Snapshot,
26+
ServiceOffering,
27+
VirtualMachine)
28+
from marvin.lib.common import (get_domain,
29+
get_zone,
30+
get_template,
31+
list_volumes,
32+
list_accounts,
33+
list_snapshots,
34+
wait_for_cleanup)
2635

2736
class Services:
2837
"""Test Snapshots Services
@@ -177,7 +186,7 @@ def setUpClass(cls):
177186
volume = volumes[0]
178187

179188
# Create a snapshot from the ROOTDISK
180-
cls.snapshot = Snapshot.create(cls.api_client, volumes[0].id)
189+
cls.snapshot = Snapshot.create(cls.api_client, volume.id)
181190
except Exception, e:
182191
cls.tearDownClass()
183192
unittest.SkipTest("setupClass fails for %s" % cls.__name__)
@@ -223,70 +232,50 @@ def test_02_accountSnapshotClean(self):
223232
# b) snapshot image($snapshot_id) should be deleted from the
224233
# /secondary/snapshots/$accountid/$volumeid/
225234

226-
accounts = list_accounts(
235+
try:
236+
accounts = list_accounts(
227237
self.apiclient,
228238
id=self.account.id
229239
)
230-
self.assertEqual(
240+
self.assertEqual(
231241
isinstance(accounts, list),
232242
True,
233243
"Check list response returns a valid list"
234244
)
235-
self.assertNotEqual(
245+
self.assertNotEqual(
236246
len(accounts),
237247
0,
238248
"Check list Accounts response"
239249
)
240250

241-
# VM should be in 'Running' state
242-
virtual_machines = list_virtual_machines(
243-
self.apiclient,
244-
id=self.virtual_machine.id
245-
)
246-
self.assertEqual(
247-
isinstance(virtual_machines, list),
248-
True,
249-
"Check list response returns a valid list"
250-
)
251-
self.assertNotEqual(
252-
len(virtual_machines),
253-
0,
254-
"Check list virtual machines response"
255-
)
256-
for virtual_machine in virtual_machines:
257-
self.debug("VM ID: %s, VM state: %s" % (
258-
virtual_machine.id,
259-
virtual_machine.state
260-
))
261-
self.assertEqual(
262-
virtual_machine.state,
263-
'Running',
264-
"Check list VM response for Running state"
265-
)
266-
267-
# Verify the snapshot was created or not
268-
snapshots = list_snapshots(
251+
# Verify the snapshot was created or not
252+
snapshots = list_snapshots(
269253
self.apiclient,
270254
id=self.snapshot.id
271255
)
272-
self.assertEqual(
256+
self.assertEqual(
273257
isinstance(snapshots, list),
274258
True,
275259
"Check list response returns a valid list"
276260
)
277-
self.assertNotEqual(
261+
self.assertNotEqual(
278262
snapshots,
279263
None,
280264
"No such snapshot %s found" % self.snapshot.id
281265
)
282-
self.assertEqual(
266+
self.assertEqual(
283267
snapshots[0].id,
284268
self.snapshot.id,
285269
"Check snapshot id in list resources call"
286270
)
287271

288-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
289-
"Snapshot was not found on NFS")
272+
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
273+
"Snapshot was not found on NFS")
274+
275+
raise Exception("self raised exception")
276+
except Exception as e:
277+
self._cleanup.append(self.account)
278+
self.fail("Exception occured: %s" % e)
290279

291280
self.debug("Deleting account: %s" % self.account.name)
292281
# Delete account

test/integration/component/test_snapshot_limits.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ def setUpClass(cls):
173173
cls.tearDownClass()
174174
unittest.SkipTest("setupClass fails for %s" % cls.__name__)
175175
raise e
176-
else:
177-
cls._cleanup.remove(cls.account)
178176
return
179177

180178
@classmethod

test/integration/component/test_usage.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ def setUpClass(cls):
14621462
cls.services["server"]["zoneid"] = cls.zone.id
14631463

14641464
cls.services["template"] = template.id
1465+
cls._cleanup = []
14651466

14661467
# Create Service offerings, VMs etc
14671468
cls.account = Account.create(
@@ -1470,13 +1471,15 @@ def setUpClass(cls):
14701471
admin=True,
14711472
domainid=cls.domain.id
14721473
)
1474+
cls._cleanup.append(cls.account)
14731475

14741476
cls.services["account"] = cls.account.name
14751477

14761478
cls.service_offering = ServiceOffering.create(
14771479
cls.api_client,
14781480
cls.services["service_offering"]
14791481
)
1482+
cls._cleanup.append(cls.sevice_offering)
14801483
cls.virtual_machine = VirtualMachine.create(
14811484
cls.api_client,
14821485
cls.services["server"],
@@ -1492,10 +1495,6 @@ def setUpClass(cls):
14921495
domainid=cls.virtual_machine.domainid,
14931496
services=cls.services["server"]
14941497
)
1495-
cls._cleanup = [
1496-
cls.service_offering,
1497-
cls.account,
1498-
]
14991498
return
15001499

15011500
@classmethod

test/integration/component/test_volumes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ def test_create_volume_under_domain(self):
10411041
name="NROOT",
10421042
parentdomainid=self.domain.id
10431043
)
1044+
self.cleanup.append(dom)
10441045
self.assertTrue(dom is not None, msg="Domain creation failed")
10451046

10461047
domuser = Account.create(
@@ -1049,6 +1050,7 @@ def test_create_volume_under_domain(self):
10491050
admin=False,
10501051
domainid=dom.id
10511052
)
1053+
self.cleanup.insert(-2, domuser)
10521054
self.assertTrue(domuser is not None)
10531055

10541056
domapiclient = self.testClient.getUserApiClient(UserName=domuser.name, DomainName=dom.name)

test/integration/smoke/test_affinity_groups.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ def test_DeployVmAntiAffinityGroup(self):
152152
msg="Both VMs of affinity group %s are on the same host" % self.ag.name)
153153

154154

155-
@classmethod
156-
def tearDownClass(cls):
157-
try:
158-
#Clean up, terminate the created templates
159-
cleanup_resources(cls.apiclient, cls._cleanup)
160-
except Exception as e:
161-
raise Exception("Warning: Exception during cleanup : %s" % e)
155+
@classmethod
156+
def tearDownClass(cls):
157+
try:
158+
#Clean up, terminate the created templates
159+
cleanup_resources(cls.apiclient, cls._cleanup)
160+
except Exception as e:
161+
raise Exception("Warning: Exception during cleanup : %s" % e)

0 commit comments

Comments
 (0)