@@ -290,7 +290,14 @@ def addNetworkToVm(self, network, vm, ipaddress=None):
290290 self .debug ("virtual machine nics: %s" % vm_list [0 ].nic )
291291 nics = [x for x in vm_list [0 ].nic if x .networkid == network .id ]
292292 self .debug ("Filtered nics list: %s:" % nics )
293- self .addednics .append (nics [- 1 ])
293+
294+ # Only the nics added to self.virtual_machine should be added to this list
295+ # Nics added to his list are removed before execution of next test case because we are using
296+ # same virtual machine in all test cases, so it is important that the common
297+ # virtual machine should contain only the default nic whenever new test case
298+ # execution starts
299+ if vm .id == self .virtual_machine .id :
300+ self .addednics .append (nics [- 1 ])
294301
295302 self .assertTrue (len (nics ) == 1 , "nics list should contain the nic of added isolated network,\
296303 the number of nics for the network should be 1, instead they are %s" %
@@ -386,12 +393,23 @@ def test_03_add_nw_multiple_times(self, value):
386393 if network is None :
387394 self .skipTest ("Network should not be none. Case not handled for Network of type %s" % value )
388395
396+ try :
397+ virtual_machine = VirtualMachine .create (
398+ self .api_client , self .services ["virtual_machine" ],
399+ accountid = self .account .name , domainid = self .account .domainid ,
400+ serviceofferingid = self .service_offering .id ,
401+ mode = self .zone .networktype ,
402+ networkids = [self .defaultNetworkId ])
403+ self .cleanup .append (virtual_machine )
404+ except Exception as e :
405+ self .fail ("Failed to deply virtual machine: %s" % e )
406+
389407 # Adding network to vm for the first time
390- self .addNetworkToVm (network , self . virtual_machine )
408+ self .addNetworkToVm (network , virtual_machine )
391409
392410 # Trying to add same network to vm for the second time
393411 with self .assertRaises (Exception ) as e :
394- self .addNetworkToVm (network , self . virtual_machine )
412+ self .addNetworkToVm (network , virtual_machine )
395413 self .debug ("Adding same network again failed with exception: %s" % e .exception )
396414
397415 return
@@ -409,8 +427,19 @@ def test_04_vpc_nw_running_vm(self, value):
409427 # Validate the following:
410428 # 1. Adding VPC to vm should fail
411429
430+ try :
431+ virtual_machine = VirtualMachine .create (
432+ self .api_client , self .services ["virtual_machine" ],
433+ accountid = self .account .name , domainid = self .account .domainid ,
434+ serviceofferingid = self .service_offering .id ,
435+ mode = self .zone .networktype ,
436+ networkids = [self .defaultNetworkId ])
437+ self .cleanup .append (virtual_machine )
438+ except Exception as e :
439+ self .fail ("Failed to deply virtual machine: %s" % e )
440+
412441 network = self .isolated_network
413- self .addNetworkToVm (network , self . virtual_machine )
442+ self .addNetworkToVm (network , virtual_machine )
414443
415444 self .debug ("Creating VPC offering" )
416445 vpc_off = VpcOffering .create (self .api_client ,self .services ["vpc_offering" ])
@@ -426,11 +455,10 @@ def test_04_vpc_nw_running_vm(self, value):
426455
427456 self .debug ("Trying to add VPC to vm belonging to isolated network, this should fail" )
428457 with self .assertRaises (Exception ):
429- self . virtual_machine .add_nic (self .apiclient , vpc .id )
458+ virtual_machine .add_nic (self .apiclient , vpc .id )
430459
431460 self .debug ("Disabling vpc offering: %s" % vpc_off .id )
432461 vpc_off .update (self .apiclient , state = 'Disabled' )
433-
434462 return
435463
436464 @attr (tags = ["advanced" ])
@@ -487,10 +515,20 @@ def test_06_add_nw_ipaddress_running_vm(self):
487515 # 2. The newly added nic has the ip address same as
488516 # that passed while adding the network
489517
518+ try :
519+ virtual_machine = VirtualMachine .create (
520+ self .api_client , self .services ["virtual_machine" ],
521+ accountid = self .account .name , domainid = self .account .domainid ,
522+ serviceofferingid = self .service_offering .id ,
523+ mode = self .zone .networktype ,
524+ networkids = [self .defaultNetworkId ])
525+ self .cleanup .append (virtual_machine )
526+ except Exception as e :
527+ self .fail ("Failed to deply virtual machine: %s" % e )
528+
490529 ipaddress = self .shared_nw_endip
491530 self .debug ("Adding network to vm with ip address %s: " % ipaddress )
492- self .addNetworkToVm (self .shared_network , self .virtual_machine ,ipaddress = ipaddress )
493-
531+ self .addNetworkToVm (self .shared_network , virtual_machine ,ipaddress = ipaddress )
494532 return
495533
496534 @attr (tags = ["advanced" ])
@@ -1065,7 +1103,6 @@ def test_13_set_foreign_nic_as_default(self):
10651103 serviceofferingid = self .service_offering .id ,mode = self .zone .networktype )
10661104 time .sleep (self .services ["sleep" ])
10671105 self .debug ("Deployed virtual machine: %s" % virtual_machine .id )
1068-
10691106 foreignNicId = virtual_machine .nic [0 ].id
10701107
10711108 self .debug ("Trying to set nic of new virtual machine as default nic of existing virtual machine, This \
0 commit comments