@@ -89,12 +89,7 @@ def setUpClass(cls):
8989
9090 @classmethod
9191 def tearDownClass (cls ):
92- try :
93- # Cleanup resources used
94- cleanup_resources (cls .api_client , cls ._cleanup )
95- except Exception as e :
96- raise Exception ("Warning: Exception during cleanup : %s" % e )
97- return
92+ super (TestMultipleChildDomain , cls ).tearDownClass ()
9893
9994 def setUp (self ):
10095 self .apiclient = self .testClient .getApiClient ()
@@ -106,22 +101,16 @@ def setUp(self):
106101 self .apiclient ,
107102 self .services ["disk_offering" ]
108103 )
104+ self .cleanup .append (self .disk_offering )
109105 self .assertNotEqual (self .disk_offering , None ,
110106 "Disk offering is None" )
111- self .cleanup .append (self .disk_offering )
112107 except Exception as e :
113108 self .tearDown ()
114109 self .skipTest ("Failure while creating disk offering: %s" % e )
115110 return
116111
117112 def tearDown (self ):
118- try :
119- # Clean up, terminate the created instance, volumes and snapshots
120- cleanup_resources (self .apiclient , self .cleanup )
121- pass
122- except Exception as e :
123- raise Exception ("Warning: Exception during cleanup : %s" % e )
124- return
113+ super (TestMultipleChildDomain , self ).tearDown ()
125114
126115 def updateDomainResourceLimits (self , parentdomainlimit , subdomainlimit ):
127116 """Update primary storage limits of the parent domain and its
@@ -151,41 +140,39 @@ def setupAccounts(self):
151140 self .apiclient ,
152141 services = self .services ["domain" ],
153142 parentdomainid = self .domain .id )
143+ self .cleanup .append (self .parent_domain )
154144 self .parentd_admin = Account .create (
155145 self .apiclient ,
156146 self .services ["account" ],
157147 admin = True ,
158148 domainid = self .parent_domain .id )
149+ self .cleanup .append (self .parentd_admin )
159150
160151 # Create sub-domains and their admin accounts
161152 self .cdomain_1 = Domain .create (
162153 self .apiclient ,
163154 services = self .services ["domain" ],
164155 parentdomainid = self .parent_domain .id )
156+ self .cleanup .append (self .cdomain_1 )
165157 self .cdomain_2 = Domain .create (
166158 self .apiclient ,
167159 services = self .services ["domain" ],
168160 parentdomainid = self .parent_domain .id )
161+ self .cleanup .append (self .cdomain_2 )
169162
170163 self .cadmin_1 = Account .create (
171164 self .apiclient ,
172165 self .services ["account" ],
173166 admin = True ,
174167 domainid = self .cdomain_1 .id )
168+ self .cleanup .append (self .cadmin_1 )
175169
176170 self .cadmin_2 = Account .create (
177171 self .apiclient ,
178172 self .services ["account" ],
179173 admin = True ,
180174 domainid = self .cdomain_2 .id )
181-
182- # Cleanup the resources created at end of test
183- self .cleanup .append (self .cadmin_1 )
184175 self .cleanup .append (self .cadmin_2 )
185- self .cleanup .append (self .cdomain_1 )
186- self .cleanup .append (self .cdomain_2 )
187- self .cleanup .append (self .parentd_admin )
188- self .cleanup .append (self .parent_domain )
189176
190177 users = {
191178 self .cdomain_1 : self .cadmin_1 ,
@@ -221,7 +208,6 @@ def test_01_multiple_domains_primary_storage_limits(self):
221208 quantity
222209 4. After step 7, resource count in parent domain should be 0"""
223210
224- # Setting up account and domain hierarchy
225211 result = self .setupAccounts ()
226212 self .assertEqual (
227213 result [0 ],
@@ -233,9 +219,10 @@ def test_01_multiple_domains_primary_storage_limits(self):
233219 disksize = 10
234220 subdomainlimit = (templatesize + disksize )
235221
222+ maxlimit = subdomainlimit * 3 - 1
236223 result = self .updateDomainResourceLimits (
237- (( subdomainlimit * 3 ) - 1 ),
238- subdomainlimit )
224+ int ( maxlimit ),
225+ int ( subdomainlimit ) )
239226 self .assertEqual (
240227 result [0 ],
241228 PASS ,
@@ -279,13 +266,14 @@ def test_01_multiple_domains_primary_storage_limits(self):
279266 "Failed to create api client for account: %s" %
280267 self .cadmin_2 .name )
281268
282- VirtualMachine .create (
269+ vm_1 = VirtualMachine .create (
283270 api_client_cadmin_1 ,
284271 self .services ["virtual_machine" ],
285272 accountid = self .cadmin_1 .name ,
286273 domainid = self .cadmin_1 .domainid ,
287274 diskofferingid = disk_offering_custom .id ,
288275 serviceofferingid = self .service_offering .id )
276+ self .cleanup .append (vm_1 )
289277
290278 self .initialResourceCount = (templatesize + disksize )
291279 result = isDomainResourceCountEqualToExpectedCount (
@@ -302,22 +290,25 @@ def test_01_multiple_domains_primary_storage_limits(self):
302290 domainid = self .cadmin_2 .domainid ,
303291 diskofferingid = disk_offering_custom .id ,
304292 serviceofferingid = self .service_offering .id )
293+ self .cleanup .append (vm_2 )
305294
306295 # Now the VMs in two child domains have exhausted the primary storage limit
307296 # of parent domain, hence VM creation in parent domain with custom disk offering
308297 # should fail
309298 with self .assertRaises (Exception ):
310- VirtualMachine .create (
299+ vm_faulty = VirtualMachine .create (
311300 api_client_admin ,
312301 self .services ["virtual_machine" ],
313302 accountid = self .parentd_admin .name ,
314303 domainid = self .parentd_admin .domainid ,
315304 diskofferingid = disk_offering_custom .id ,
316305 serviceofferingid = self .service_offering .id )
306+ self .cleanup .append (vm_faulty ) # should not happen
317307
318- # Deleting user account
308+ # Deleting user account and remove it's resources from the cleanup list
319309 self .cadmin_1 .delete (self .apiclient )
320310 self .cleanup .remove (self .cadmin_1 )
311+ self .cleanup .remove (vm_1 )
321312
322313 expectedCount = self .initialResourceCount
323314 result = isDomainResourceCountEqualToExpectedCount (
@@ -328,6 +319,7 @@ def test_01_multiple_domains_primary_storage_limits(self):
328319
329320 try :
330321 vm_2 .delete (self .apiclient )
322+ self .cleanup .remove (vm_2 )
331323 except Exception as e :
332324 self .fail ("Failed to delete instance: %s" % e )
333325
@@ -387,6 +379,7 @@ def test_02_multiple_domains_primary_storage_limits(self):
387379 domainid = self .account .domainid ,
388380 diskofferingid = self .disk_offering .id ,
389381 serviceofferingid = self .service_offering .id )
382+ self .cleanup .append (vm )
390383
391384 expectedCount = templatesize + self .disk_offering .disksize
392385 result = isDomainResourceCountEqualToExpectedCount (
@@ -400,7 +393,6 @@ def test_02_multiple_domains_primary_storage_limits(self):
400393 disk_offering_10_GB = DiskOffering .create (
401394 self .apiclient ,
402395 services = self .services ["disk_offering" ])
403-
404396 self .cleanup .append (disk_offering_10_GB )
405397
406398 volume = Volume .create (
@@ -410,11 +402,13 @@ def test_02_multiple_domains_primary_storage_limits(self):
410402 account = self .account .name ,
411403 domainid = self .account .domainid ,
412404 diskofferingid = disk_offering_10_GB .id )
405+ self .cleanup .append (volume ) # we get an exception in the next few lines
413406
414407 volumeSize = (volume .size / (1024 ** 3 ))
415408 expectedCount += volumeSize
416409
417410 vm .attach_volume (apiclient , volume = volume )
411+ self .cleanup .remove (volume ) # we can't cleanup an attached volume
418412 result = isDomainResourceCountEqualToExpectedCount (
419413 self .apiclient , self .domain .id ,
420414 expectedCount , RESOURCE_PRIMARY_STORAGE )
@@ -475,7 +469,9 @@ def test_03_multiple_domains_multiple_volumes(self):
475469 accountid = self .account .name ,
476470 domainid = self .account .domainid ,
477471 diskofferingid = self .disk_offering .id ,
478- serviceofferingid = self .service_offering .id )
472+ serviceofferingid = self .service_offering .id ,
473+ startvm = False )
474+ self .cleanup .append (vm )
479475
480476 expectedCount = templatesize + self .disk_offering .disksize
481477 result = isDomainResourceCountEqualToExpectedCount (
@@ -488,14 +484,12 @@ def test_03_multiple_domains_multiple_volumes(self):
488484 disk_offering_15_GB = DiskOffering .create (
489485 self .apiclient ,
490486 services = self .services ["disk_offering" ])
491-
492487 self .cleanup .append (disk_offering_15_GB )
493488
494489 volume2size = self .services ["disk_offering" ]["disksize" ] = 20
495490 disk_offering_20_GB = DiskOffering .create (
496491 self .apiclient ,
497492 services = self .services ["disk_offering" ])
498-
499493 self .cleanup .append (disk_offering_20_GB )
500494
501495 volume_1 = Volume .create (
@@ -505,6 +499,7 @@ def test_03_multiple_domains_multiple_volumes(self):
505499 account = self .account .name ,
506500 domainid = self .account .domainid ,
507501 diskofferingid = disk_offering_15_GB .id )
502+ self .cleanup .append (volume_1 )
508503
509504 volume_2 = Volume .create (
510505 apiclient ,
@@ -513,9 +508,12 @@ def test_03_multiple_domains_multiple_volumes(self):
513508 account = self .account .name ,
514509 domainid = self .account .domainid ,
515510 diskofferingid = disk_offering_20_GB .id )
511+ self .cleanup .append (volume_2 )
516512
517513 vm .attach_volume (apiclient , volume = volume_1 )
514+ self .cleanup .remove (volume_1 )
518515 vm .attach_volume (apiclient , volume = volume_2 )
516+ self .cleanup .remove (volume_2 )
519517
520518 expectedCount += volume1size + volume2size
521519 result = isDomainResourceCountEqualToExpectedCount (
@@ -584,6 +582,7 @@ def test_04_create_template_snapshot(self):
584582 domainid = self .account .domainid ,
585583 diskofferingid = self .disk_offering .id ,
586584 serviceofferingid = self .service_offering .id )
585+ self .cleanup .append (vm )
587586
588587 templatesize = (self .template .size / (1024 ** 3 ))
589588
@@ -603,6 +602,7 @@ def test_04_create_template_snapshot(self):
603602 vm .id )
604603 self .assertEqual (response [0 ], PASS , response [1 ])
605604 snapshot = response [1 ]
605+ self .cleanup .append (snapshot )
606606
607607 response = snapshot .validateState (
608608 apiclient ,
@@ -617,8 +617,10 @@ def test_04_create_template_snapshot(self):
617617 services = self .services ["volume" ],
618618 account = self .account .name ,
619619 domainid = self .account .domainid )
620+ self .cleanup .append (volume )
620621 volumeSize = (volume .size / (1024 ** 3 ))
621622 vm .attach_volume (apiclient , volume )
623+ self .cleanup .remove (volume )
622624 expectedCount = initialResourceCount + (volumeSize )
623625 result = isDomainResourceCountEqualToExpectedCount (
624626 self .apiclient , self .domain .id ,
@@ -673,6 +675,7 @@ def test_05_assign_virtual_machine_different_domain(self):
673675 domainid = self .cadmin_1 .domainid ,
674676 diskofferingid = self .disk_offering .id ,
675677 serviceofferingid = self .service_offering .id )
678+ self .cleanup .append (vm_1 )
676679
677680 templatesize = (self .template .size / (1024 ** 3 ))
678681
@@ -736,6 +739,7 @@ def test_06_destroy_recover_vm(self):
736739 domainid = self .account .domainid ,
737740 diskofferingid = self .disk_offering .id ,
738741 serviceofferingid = self .service_offering .id )
742+ self .cleanup .append (vm_1 )
739743
740744 templatesize = (self .template .size / (1024 ** 3 ))
741745
@@ -747,6 +751,7 @@ def test_06_destroy_recover_vm(self):
747751 self .assertTrue (result [2 ], "Resource count does not match" )
748752
749753 vm_1 .delete (self .apiclient , expunge = False )
754+ self .cleanup .remove (vm_1 )
750755
751756 result = isDomainResourceCountEqualToExpectedCount (
752757 self .apiclient , self .account .domainid ,
@@ -755,6 +760,7 @@ def test_06_destroy_recover_vm(self):
755760 self .assertTrue (result [2 ], "Resource count does not match" )
756761
757762 vm_1 .recover (self .apiclient )
763+ self .cleanup .append (vm_1 )
758764
759765 result = isDomainResourceCountEqualToExpectedCount (
760766 self .apiclient , self .account .domainid ,
0 commit comments