@@ -235,8 +235,9 @@ def test_create_portable_ip_range_non_root_admin(self):
235235
236236 self .debug ("Trying to create portable ip range with non root-admin api client, should raise exception" )
237237 with self .assertRaises (Exception ):
238- PortablePublicIpRange .create (self .api_client_user ,
238+ portable_ip_range = PortablePublicIpRange .create (self .api_client_user ,
239239 portable_ip_range_services )
240+ self .cleanup .append (portable_ip_range )
240241
241242 return
242243
@@ -258,8 +259,9 @@ def test_create_portable_ip_range_invalid_region(self):
258259 self .debug ("Trying to create portable ip range with wrong region id" )
259260
260261 with self .assertRaises (Exception ):
261- PortablePublicIpRange .create (self .apiclient ,
262+ portable_ip_range = PortablePublicIpRange .create (self .apiclient ,
262263 portable_ip_range_services )
264+ self .cleanup .append (portable_ip_range )
263265
264266 return
265267
@@ -687,8 +689,6 @@ def test_associate_ip_address(self):
687689
688690 self .debug ("Associated default public ip address: %s" % publicipaddress .ipaddress .ipaddress )
689691
690-
691-
692692 self .debug ("Associating public ip address with network: %s with isportable=False" % self .network .id )
693693 publicipaddressnotportable = PublicIPAddress .create (
694694 self .apiclient ,
@@ -727,14 +727,15 @@ def test_associate_ip_address_invalid_zone(self):
727727 self .debug ("Trying to associate portable public ip with invalid zone id, this should fail" )
728728
729729 with self .assertRaises (Exception ):
730- PublicIPAddress .create (
730+ publicipaddress = PublicIPAddress .create (
731731 self .apiclient ,
732732 accountid = self .account .name ,
733733 zoneid = - 1 ,
734734 domainid = self .account .domainid ,
735735 regionid = self .region .id ,
736736 isportable = True
737737 )
738+ publicipaddress .delete (self .apiclient )
738739 self .debug ("Associating ip address failed" )
739740 return
740741
@@ -815,14 +816,15 @@ def test_associate_ip_address_services_enable_disable(self):
815816 except Exception as e :
816817 self .fail ("Exception while SSHing : %s" % e )
817818
818- self .debug ("Deleting firewall rule" )
819- fw_rule .delete (self .apiclient )
819+ finally :
820+ self .debug ("Deleting firewall rule" )
821+ fw_rule .delete (self .apiclient )
820822
821- self .debug ("Deleting NAT rule" )
822- nat_rule .delete (self .apiclient )
823+ self .debug ("Deleting NAT rule" )
824+ nat_rule .delete (self .apiclient )
823825
824- self .debug ("disassocoating portable ip: %s" % portableip .ipaddress .ipaddress )
825- portableip .delete (self .apiclient )
826+ self .debug ("disassocoating portable ip: %s" % portableip .ipaddress .ipaddress )
827+ portableip .delete (self .apiclient )
826828 return
827829
828830 @attr (tags = ["advanced" ])
@@ -858,14 +860,15 @@ def test_associate_ip_address_no_free_ip(self):
858860
859861 self .debug ("Trying to associate portable public ip when no free ips available, this should fail" )
860862 with self .assertRaises (Exception ):
861- PublicIPAddress .create (
863+ portableipaddress = PublicIPAddress .create (
862864 self .apiclient ,
863865 accountid = self .account .name ,
864866 zoneid = self .zone .id ,
865867 domainid = self .account .domainid ,
866868 networkid = self .network .id ,
867869 isportable = True
868870 )
871+ portableipaddress .delete (self .apiclient )
869872
870873 self .debug ("Associating portable ip address failed" )
871874
@@ -1338,7 +1341,6 @@ def test_delete_account_services_enabled(self):
13381341
13391342 return
13401343
1341-
13421344class TestPortableIpTransferAcrossNetworks (cloudstackTestCase ):
13431345 """Test Transfer Portable IP Across Networks
13441346 """
@@ -1390,7 +1392,6 @@ def setUpClass(cls):
13901392 cls .services ["service_offering" ]
13911393 )
13921394
1393- cls .debug ("creating networks and virtual machines in each network for portable ip transfer tests: " )
13941395 cls .network1 = Network .create (
13951396 cls .api_client ,
13961397 cls .services ["network1" ],
@@ -1538,11 +1539,6 @@ def test_list_portable_ip_range_non_root_admin(self):
15381539 except Exception as e :
15391540 self .fail ("Exception while SSHing : %s" % e )
15401541
1541- self .debug ("disassociating portable ip: %s" % portableip .ipaddress .ipaddress )
1542- portableip .delete (self .apiclient )
1543-
1544-
1545-
1546-
1547-
1548-
1542+ finally :
1543+ self .debug ("disassociating portable ip: %s" % portableip .ipaddress .ipaddress )
1544+ portableip .delete (self .apiclient )
0 commit comments