@@ -182,30 +182,24 @@ def setUpClass(cls):
182182 )
183183 cls .services ["virtual_machine" ]["zoneid" ] = cls .zone .id
184184 cls .services ["virtual_machine" ]["template" ] = cls .template .id
185+ cls ._cleanup = []
185186
186187 cls .service_offering = ServiceOffering .create (
187188 cls .api_client ,
188189 cls .services ["service_offering" ]
189190 )
191+ cls ._cleanup .append (cls .service_offering )
190192 cls .vpc_off = VpcOffering .create (
191193 cls .api_client ,
192194 cls .services ["vpc_offering" ]
193195 )
196+ cls ._cleanup .append (cls .vpc_off )
194197 cls .vpc_off .update (cls .api_client , state = 'Enabled' )
195- cls ._cleanup = [
196- cls .service_offering ,
197- cls .vpc_off
198- ]
199198 return
200199
201200 @classmethod
202201 def tearDownClass (cls ):
203- try :
204- #Cleanup resources used
205- cleanup_resources (cls .api_client , cls ._cleanup )
206- except Exception as e :
207- raise Exception ("Warning: Exception during cleanup : %s" % e )
208- return
202+ super (TestVMDeployVPC , cls ).tearDownClass ()
209203
210204 def setUp (self ):
211205 self .apiclient = self .testClient .getApiClient ()
@@ -220,12 +214,7 @@ def setUp(self):
220214 return
221215
222216 def tearDown (self ):
223- try :
224- #Clean up, terminate the created network offerings
225- cleanup_resources (self .apiclient , self .cleanup )
226- except Exception as e :
227- raise Exception ("Warning: Exception during cleanup : %s" % e )
228- return
217+ super (TestVMDeployVPC , self ).tearDown ()
229218
230219 def validate_vpc_offering (self , vpc_offering ):
231220 """Validates the VPC offering"""
@@ -286,44 +275,10 @@ def acquire_publicip(self, network):
286275 networkid = network .id ,
287276 vpcid = self .vpc .id
288277 )
278+ self .cleanup .append (public_ip )
289279 self .debug ("Associated {} with network {}" .format (public_ip .ipaddress .ipaddress , network .id ))
290280 return public_ip
291281
292- def create_natrule (self , vm , public_ip , network , services = None ):
293- self .debug ("Creating NAT rule in network for vm with public IP" )
294- if not services :
295- services = self .services ["natrule" ]
296- nat_rule = NATRule .create (self .apiclient ,
297- vm ,
298- services ,
299- ipaddressid = public_ip .ipaddress .id ,
300- openfirewall = False ,
301- networkid = network .id ,
302- vpcid = self .vpc .id
303- )
304- self .debug ("Adding NetworkACL rules to make NAT rule accessible" )
305- nwacl_nat = NetworkACL .create (self .apiclient ,
306- networkid = network .id ,
307- services = services ,
308- traffictype = 'Ingress'
309- )
310- self .debug ('nwacl_nat=%s' % nwacl_nat .__dict__ )
311- return nat_rule
312-
313- def check_ssh_into_vm (self , vm , public_ip , testnegative = False ):
314- self .debug ("Checking if we can SSH into VM={} on public_ip={}" .format (vm .name , public_ip .ipaddress .ipaddress ))
315- try :
316- vm .get_ssh_client (ipaddress = public_ip .ipaddress .ipaddress )
317- if not testnegative :
318- self .debug ("SSH into VM={} on public_ip={} is successful" .format (vm .name , public_ip .ipaddress .ipaddress ))
319- else :
320- self .fail ("SSH into VM={} on public_ip={} is successful" .format (vm .name , public_ip .ipaddress .ipaddress ))
321- except :
322- if not testnegative :
323- self .fail ("Failed to SSH into VM - %s" % (public_ip .ipaddress .ipaddress ))
324- else :
325- self .debug ("Failed to SSH into VM - %s" % (public_ip .ipaddress .ipaddress ))
326-
327282 def deployVM_and_verify_ssh_access (self , network , ip ):
328283 # Spawn an instance in that network
329284 vm = VirtualMachine .create (
@@ -335,6 +290,7 @@ def deployVM_and_verify_ssh_access(self, network, ip):
335290 networkids = [str (network .id )],
336291 ipaddress = ip ,
337292 )
293+ self .cleanup .append (vm )
338294 self .assertIsNotNone (
339295 vm ,
340296 "Failed to deploy vm with ip address {} and hostname {}" .format (ip , self .services ["virtual_machine" ]["name" ])
@@ -351,10 +307,11 @@ def deployVM_and_verify_ssh_access(self, network, ip):
351307 )
352308 public_ip_1 = self .acquire_publicip (network )
353309 #ensure vm is accessible over public ip
354- nat_rule = self .create_natrule (vm , public_ip_1 , network )
310+ nat_rule = self .create_natrule_for_services (vm , public_ip_1 , network )
355311 self .check_ssh_into_vm (vm , public_ip_1 , testnegative = False )
356312 #remove the nat rule
357313 nat_rule .delete (self .apiclient )
314+ self .cleanup .remove (nat_rule )
358315 return vm
359316
360317 @attr (tags = ["advanced" , "intervlan" ], required_hardware = "false" )
@@ -2381,15 +2338,15 @@ def test_08_ip_reallocation_CS5986(self):
23812338 account = self .account .name ,
23822339 domainid = self .account .domainid
23832340 )
2341+ self .cleanup .append (self .vpc )
23842342 self .validate_vpc_network (self .vpc )
23852343 self .nw_off = NetworkOffering .create (
23862344 self .apiclient ,
23872345 self .services ["network_offering" ],
23882346 conservemode = False
23892347 )
2390- # Enable Network offering
2391- self .nw_off .update (self .apiclient , state = 'Enabled' )
23922348 self ._cleanup .append (self .nw_off )
2349+ self .nw_off .update (self .apiclient , state = 'Enabled' )
23932350 # Creating network using the network offering created
23942351 self .debug ("Creating network with network offering: %s" % self .nw_off .id )
23952352 network_1 = Network .create (
@@ -2402,6 +2359,7 @@ def test_08_ip_reallocation_CS5986(self):
24022359 gateway = '10.1.1.1' ,
24032360 vpcid = self .vpc .id
24042361 )
2362+ self .cleanup .append (network_1 )
24052363 self .debug ("Created network with ID: %s" % network_1 .id )
24062364 # Spawn vm1 in that network
24072365 vm1_ip = "10.1.1.10"
@@ -2416,7 +2374,9 @@ def test_08_ip_reallocation_CS5986(self):
24162374 #Destroy both the vms
24172375 try :
24182376 vm1 .delete (self .apiclient , expunge = True )
2377+ self .cleanup .remove (vm1 )
24192378 vm2 .delete (self .apiclient , expunge = True )
2379+ self .cleanup .remove (vm2 )
24202380 except Exception as e :
24212381 raise Exception ("Warning: Exception in expunging vms: %s" % e )
24222382 """
@@ -2437,10 +2397,9 @@ def test_08_ip_reallocation_CS5986(self):
24372397 vm4 = self .deployVM_and_verify_ssh_access (network_1 , vm2_ip )
24382398 try :
24392399 vm3 .delete (self .apiclient , expunge = True )
2400+ self .cleanup .remove (vm3 )
24402401 vm4 .delete (self .apiclient , expunge = True )
2402+ self .cleanup .remove (vm4 )
24412403 except Exception as e :
24422404 raise Exception ("Warning: Excepting in expunging vms vm3 and vm4: %s" % e )
24432405 return
2444-
2445-
2446-
0 commit comments