@@ -177,6 +177,8 @@ def setUpClass(cls):
177177 cls .api_client ,
178178 cls .services ["disk_offering" ]
179179 )
180+ cls ._cleanup .append (cls .disk_offering )
181+
180182 cls .template = get_template (
181183 cls .api_client ,
182184 cls .zone .id ,
@@ -198,31 +200,21 @@ def setUpClass(cls):
198200 cls .api_client ,
199201 cls .services ["service_offering" ]
200202 )
203+ cls ._cleanup .append (cls .service_offering )
201204
202- cls ._cleanup = [
203- cls .service_offering ,
204- cls .disk_offering
205- ]
206205 return
207206
208207 @classmethod
209208 def tearDownClass (cls ):
210- try :
211- # Cleanup resources used
212- cleanup_resources (cls .api_client , cls ._cleanup )
213- except Exception as e :
214- raise Exception ("Warning: Exception during cleanup : %s" % e )
215- return
209+ super (TestSnapshots , cls ).tearDownClass ()
216210
217211 def setUp (self ):
218212 self .apiclient = self .testClient .getApiClient ()
219213 self .dbclient = self .testClient .getDbConnection ()
220214 self .cleanup = []
221215
222216 if self .unsupportedHypervisor :
223- self .skipTest ("Skipping test because unsupported hypervisor: %s" %
224- self .hypervisor )
225-
217+ self .skipTest ("Skipping test because unsupported hypervisor: %s" % self .hypervisor )
226218
227219 # Create VMs, NAT Rules etc
228220 self .account = Account .create (
@@ -245,12 +237,7 @@ def setUp(self):
245237 return
246238
247239 def tearDown (self ):
248- try :
249- # Clean up, terminate the created instance, volumes and snapshots
250- cleanup_resources (self .apiclient , self .cleanup )
251- except Exception as e :
252- raise Exception ("Warning: Exception during cleanup : %s" % e )
253- return
240+ super (TestSnapshots , self ).tearDown ()
254241
255242 @attr (speed = "slow" )
256243 @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
@@ -317,7 +304,6 @@ def test_02_snapshot_data_disk(self):
317304 required_hardware = "true" )
318305 def test_01_volume_from_snapshot (self ):
319306 """Test Creating snapshot from volume having spaces in name(KVM)
320- """
321307 # Validate the following
322308 # 1. Create a virtual machine and data volume
323309 # 2. Attach data volume to VM
@@ -327,14 +313,15 @@ def test_01_volume_from_snapshot(self):
327313 # 5. Create another Volume from snapshot
328314 # 6. Mount/Attach volume to another virtual machine
329315 # 7. Compare data, data should match
316+ """
330317
331318 if self .hypervisor .lower () in ['hyperv' ]:
332319 self .skipTest ("Snapshots feature is not supported on Hyper-V" )
333320
334321 random_data_0 = random_gen (size = 100 )
335322 random_data_1 = random_gen (size = 100 )
336323
337- self .debug ("random_data_0 : %s" % random_data_0 )
324+ self .debug ("random_data_0: %s" % random_data_0 )
338325 self .debug ("random_data_1: %s" % random_data_1 )
339326
340327 try :
@@ -355,7 +342,7 @@ def test_01_volume_from_snapshot(self):
355342 self .virtual_machine .attach_volume (
356343 self .apiclient ,
357344 volume
358- )
345+ ) # volume should be cleanup with `self.virtual_machine`
359346 self .debug ("Attach volume: %s to VM: %s" %
360347 (volume .id , self .virtual_machine .id ))
361348
@@ -483,7 +470,7 @@ def test_01_volume_from_snapshot(self):
483470 mode = self .services ["mode" ]
484471 )
485472 self .debug ("Deployed new VM for account: %s" % self .account .name )
486- # self.cleanup.append(new_virtual_machine)
473+ self .cleanup .append (new_virtual_machine )
487474
488475 self .debug ("Attaching volume: %s to VM: %s" % (
489476 volume_from_snapshot .id ,
@@ -774,15 +761,13 @@ def test_03_snapshot_detachedDisk(self):
774761 required_hardware = "true" )
775762 def test_07_template_from_snapshot (self ):
776763 """Create Template from snapshot
777- """
778-
779764 # 1. Login to machine; create temp/test directories on data volume
780765 # 2. Snapshot the Volume
781766 # 3. Create Template from snapshot
782767 # 4. Deploy Virtual machine using this template
783768 # 5. Login to newly created virtual machine
784- # 6. Compare data in the root disk with the one that was written on the
785- # volume, it should match
769+ # 6. Compare data in the root disk with the one that was written on the volume, it should match
770+ """
786771
787772 if self .hypervisor .lower () in ['hyperv' ]:
788773 self .skipTest ("Snapshots feature is not supported on Hyper-V" )
@@ -865,6 +850,7 @@ def test_07_template_from_snapshot(self):
865850 account = self .account .name ,
866851 domainid = self .account .domainid
867852 )
853+ self .cleanup .append (snapshot )
868854
869855 self .debug ("Snapshot created from volume ID: %s" % volume .id )
870856 # Generate template from the snapshot
@@ -873,7 +859,6 @@ def test_07_template_from_snapshot(self):
873859 snapshot ,
874860 self .services ["templates" ]
875861 )
876- self .cleanup .append (template )
877862 self .debug ("Template created from snapshot ID: %s" % snapshot .id )
878863
879864 # Verify created template
@@ -905,6 +890,7 @@ def test_07_template_from_snapshot(self):
905890 serviceofferingid = self .service_offering .id ,
906891 mode = self .services ["mode" ]
907892 )
893+ self .cleanup .append (new_virtual_machine )
908894 try :
909895 # Login to VM & mount directory
910896 ssh = new_virtual_machine .get_ssh_client ()
@@ -997,25 +983,19 @@ def setUpClass(cls):
997983 cls .services ["account" ],
998984 domainid = cls .domain .id
999985 )
986+ cls ._cleanup .append (cls .account )
1000987
1001988 cls .service_offering = ServiceOffering .create (
1002989 cls .api_client ,
1003990 cls .services ["service_offering" ]
1004991 )
1005- cls ._cleanup = [
1006- cls .service_offering ,
1007- cls .account ,
1008- ]
992+ cls ._cleanup .append (cls .service_offering )
993+
1009994 return
1010995
1011996 @classmethod
1012997 def tearDownClass (cls ):
1013- try :
1014- # Cleanup resources used
1015- cleanup_resources (cls .api_client , cls ._cleanup )
1016- except Exception as e :
1017- raise Exception ("Warning: Exception during cleanup : %s" % e )
1018- return
998+ super (TestCreateVMSnapshotTemplate , cls ).tearDownClass ()
1019999
10201000 def setUp (self ):
10211001 self .apiclient = self .testClient .getApiClient ()
@@ -1027,12 +1007,7 @@ def setUp(self):
10271007 return
10281008
10291009 def tearDown (self ):
1030- try :
1031- # Clean up, terminate the created instance, volumes and snapshots
1032- cleanup_resources (self .apiclient , self .cleanup )
1033- except Exception as e :
1034- raise Exception ("Warning: Exception during cleanup : %s" % e )
1035- return
1010+ super (TestCreateVMSnapshotTemplate , self ).tearDown ()
10361011
10371012 @attr (speed = "slow" )
10381013 @attr (tags = ["advanced" , "advancedns" ], required_hardware = "true" )
@@ -1072,8 +1047,9 @@ def test_01_createVM_snapshotTemplate(self):
10721047 domainid = self .account .domainid ,
10731048 serviceofferingid = self .service_offering .id
10741049 )
1050+ self .cleanup .append (self .virtual_machine )
10751051 self .debug ("Created VM with ID: %s" % self .virtual_machine .id )
1076- # Get the Root disk of VM
1052+
10771053 volumes = list_volumes (
10781054 userapiclient ,
10791055 virtualmachineid = self .virtual_machine .id ,
@@ -1117,8 +1093,8 @@ def test_01_createVM_snapshotTemplate(self):
11171093 snapshot ,
11181094 self .services ["templates" ]
11191095 )
1120- self .debug ("Created template from snapshot: %s" % template .id )
11211096 self .cleanup .append (template )
1097+ self .debug ("Created template from snapshot: %s" % template .id )
11221098
11231099 templates = list_templates (
11241100 userapiclient ,
@@ -1147,11 +1123,11 @@ def test_01_createVM_snapshotTemplate(self):
11471123 domainid = self .account .domainid ,
11481124 serviceofferingid = self .service_offering .id
11491125 )
1126+ self .cleanup .append (new_virtual_machine )
11501127 self .debug ("Created VM with ID: %s from template: %s" % (
11511128 new_virtual_machine .id ,
11521129 template .id
11531130 ))
1154- self .cleanup .append (new_virtual_machine )
11551131
11561132 # Newly deployed VM should be 'Running'
11571133 virtual_machines = list_virtual_machines (
@@ -1219,13 +1195,16 @@ def setUpClass(cls):
12191195 cls .services ["account" ],
12201196 domainid = cls .domain .id
12211197 )
1198+ cls ._cleanup .append (cls .account )
12221199
12231200 cls .services ["account" ] = cls .account .name
12241201
12251202 cls .service_offering = ServiceOffering .create (
12261203 cls .api_client ,
12271204 cls .services ["service_offering" ]
12281205 )
1206+ cls ._cleanup .append (cls .service_offering )
1207+
12291208 cls .virtual_machine = VirtualMachine .create (
12301209 cls .api_client ,
12311210 cls .services ["server" ],
@@ -1234,21 +1213,13 @@ def setUpClass(cls):
12341213 domainid = cls .account .domainid ,
12351214 serviceofferingid = cls .service_offering .id
12361215 )
1216+ cls ._cleanup .append (cls .virtual_machine )
12371217
1238- cls ._cleanup = [
1239- cls .service_offering ,
1240- cls .account ,
1241- ]
12421218 return
12431219
12441220 @classmethod
12451221 def tearDownClass (cls ):
1246- try :
1247- # Cleanup resources used
1248- cleanup_resources (cls .api_client , cls ._cleanup )
1249- except Exception as e :
1250- raise Exception ("Warning: Exception during cleanup : %s" % e )
1251- return
1222+ super (TestSnapshotEvents , cls ).tearDownClass ()
12521223
12531224 def setUp (self ):
12541225 self .apiclient = self .testClient .getApiClient ()
@@ -1260,12 +1231,7 @@ def setUp(self):
12601231 return
12611232
12621233 def tearDown (self ):
1263- try :
1264- # Clean up, terminate the created instance, volumes and snapshots
1265- cleanup_resources (self .apiclient , self .cleanup )
1266- except Exception as e :
1267- raise Exception ("Warning: Exception during cleanup : %s" % e )
1268- return
1234+ super (TestSnapshotEvents , self ).tearDown ()
12691235
12701236 @attr (speed = "slow" )
12711237 @attr (tags = ["advanced" , "advancedns" ], required_hardware = "false" )
0 commit comments