Browse Source

More fixes for orderly resource cleanup and added comments

Nuwan Goonasekera 9 năm trước cách đây
mục cha
commit
6aefd0c54b

+ 4 - 0
test/test_block_store_service.py

@@ -98,6 +98,8 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         instance_name = "CBVolOps-{0}-{1}".format(
             self.provider.name,
             uuid.uuid4())
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         net = None
         test_instance = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
@@ -129,6 +131,8 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
             self.provider.name,
             uuid.uuid4())
         vol_desc = 'newvoldesc1'
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         test_instance = None
         net = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(

+ 6 - 0
test/test_compute_service.py

@@ -20,6 +20,8 @@ class CloudComputeServiceTestCase(ProviderTestBase):
         name = "CBInstCrud-{0}-{1}".format(
             self.provider.name,
             uuid.uuid4())
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         inst = None
         net = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
@@ -98,6 +100,8 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.provider.name,
             uuid.uuid4())
 
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         test_instance = None
         net = None
         sg = None
@@ -330,6 +334,8 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.provider.name,
             uuid.uuid4())
 
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         test_inst = None
         net = None
         sg = None

+ 3 - 0
test/test_image_service.py

@@ -22,6 +22,9 @@ class CloudImageServiceTestCase(ProviderTestBase):
         instance_name = "CBImageTest-{0}-{1}".format(
             self.provider.name,
             uuid.uuid4())
+
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         test_instance = None
         net = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(

+ 12 - 6
test/test_network_service.py

@@ -152,13 +152,19 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
             net.delete()
 
         name = 'cbtestrouter-{0}'.format(uuid.uuid4())
-        router = self.provider.network.create_router(name=name)
-        net = self.provider.network.create(name=name)
-        cidr = '10.0.1.0/24'
-        sn = net.create_subnet(
-            cidr_block=cidr, name=name,
-            zone=helpers.get_provider_test_data(self.provider, 'placement'))
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
+        net = None
+        sn = None
+        router = None
         with helpers.cleanup_action(lambda: _cleanup(net, sn, router)):
+            router = self.provider.network.create_router(name=name)
+            net = self.provider.network.create(name=name)
+            cidr = '10.0.1.0/24'
+            sn = net.create_subnet(cidr_block=cidr, name=name,
+                                   zone=helpers.get_provider_test_data(
+                                       self.provider, 'placement'))
+
             # Check basic router properties
             self.assertIn(
                 router, self.provider.network.routers(),

+ 12 - 0
test/test_security_service.py

@@ -106,6 +106,9 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
     @helpers.skipIfNoService(['security.security_groups'])
     def test_crud_security_group_service(self):
         name = 'CBTestSecurityGroupA-{0}'.format(uuid.uuid4())
+
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         net = None
         sg = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
@@ -165,6 +168,9 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
     def test_security_group(self):
         """Test for proper creation of a security group."""
         name = 'CBTestSecurityGroupB-{0}'.format(uuid.uuid4())
+
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         net = None
         sg = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
@@ -225,6 +231,9 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
                 "Value security_group is invalid for parameter.")
 
         name = 'CBTestSecurityGroupC-{0}'.format(uuid.uuid4())
+
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         net = None
         sg = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
@@ -248,6 +257,9 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
     def test_security_group_group_rule(self):
         """Test for proper creation of a security group rule."""
         name = 'CBTestSecurityGroupD-{0}'.format(uuid.uuid4())
+
+        # Declare these variables and late binding will allow
+        # the cleanup method access to the most current values
         net = None
         sg = None
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(