Bläddra i källkod

Removed redundant cleanup_function

Nuwan Goonasekera 7 år sedan
förälder
incheckning
abeb31db6c

+ 27 - 64
test/helpers/__init__.py

@@ -2,14 +2,10 @@ import functools
 import operator
 import os
 import sys
-import traceback
 import unittest
 import uuid
-from contextlib import contextmanager
 
-import six
-
-from cloudbridge.cloud.base.helpers import get_env
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.factory import CloudProviderFactory
 from cloudbridge.cloud.interfaces import InstanceState
 from cloudbridge.cloud.interfaces import TestMockHelperMixin
@@ -25,41 +21,6 @@ def parse_bool(val):
         return False
 
 
-@contextmanager
-def cleanup_action(cleanup_func):
-    """
-    Context manager to carry out a given
-    cleanup action after carrying out a set
-    of tasks, or when an exception occurs.
-    If any errors occur during the cleanup
-    action, those are ignored, and the original
-    traceback is preserved.
-
-    :params func: This function is called if
-    an exception occurs or at the end of the
-    context block. If any exceptions raised
-        by func are ignored.
-    Usage:
-        with cleanup_action(lambda e: print("Oops!")):
-            do_something()
-    """
-    try:
-        yield
-    except Exception:
-        ex_class, ex_val, ex_traceback = sys.exc_info()
-        try:
-            cleanup_func()
-        except Exception as e:
-            print("Error during exception cleanup: {0}".format(e))
-            traceback.print_exc()
-        six.reraise(ex_class, ex_val, ex_traceback)
-    try:
-        cleanup_func()
-    except Exception as e:
-        print("Error during cleanup: {0}".format(e))
-        traceback.print_exc()
-
-
 def skipIfNoService(services):
     """
     A decorator for skipping tests if the provider
@@ -118,31 +79,32 @@ def skipIfPython(op, major, minor):
 TEST_DATA_CONFIG = {
     "AWSCloudProvider": {
         # Match the ami value with entry in custom_amis.json for use with moto
-        "image": get_env('CB_IMAGE_AWS', 'ami-aa2ea6d0'),
-        "vm_type": get_env('CB_VM_TYPE_AWS', 't2.nano'),
-        "placement": get_env('CB_PLACEMENT_AWS', 'us-east-1a'),
+        "image": cb_helpers.get_env('CB_IMAGE_AWS', 'ami-aa2ea6d0'),
+        "vm_type": cb_helpers.get_env('CB_VM_TYPE_AWS', 't2.nano'),
+        "placement": cb_helpers.get_env('CB_PLACEMENT_AWS', 'us-east-1a'),
     },
     'OpenStackCloudProvider': {
-        'image': os.environ.get('CB_IMAGE_OS',
-                                'c66bdfa1-62b1-43be-8964-e9ce208ac6a5'),
-        "vm_type": os.environ.get('CB_VM_TYPE_OS', 'm1.tiny'),
-        "placement": os.environ.get('CB_PLACEMENT_OS', 'nova'),
+        'image': cb_helpers.get_env('CB_IMAGE_OS',
+                                    'c66bdfa1-62b1-43be-8964-e9ce208ac6a5'),
+        "vm_type": cb_helpers.get_env('CB_VM_TYPE_OS', 'm1.tiny'),
+        "placement": cb_helpers.get_env('CB_PLACEMENT_OS', 'nova'),
     },
     'GCPCloudProvider': {
-        'image': ('https://www.googleapis.com/compute/v1/'
-                  'projects/ubuntu-os-cloud/global/images/'
-                  'ubuntu-1710-artful-v20180126'),
-        'vm_type': 'f1-micro',
-        'placement': os.environ.get('GCP_DEFAULT_ZONE', 'us-central1-a'),
+        'image': cb_helpers.get_env(
+            'CB_IMAGE_GCP',
+            'https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/'
+            'global/images/ubuntu-1710-artful-v20180126'),
+        'vm_type': cb_helpers.get_env('CB_VM_TYPE_GCP', 'f1-micro'),
+        'placement': cb_helpers.get_env('GCP_DEFAULT_ZONE', 'us-central1-a'),
     },
     "AzureCloudProvider": {
         "placement":
-            get_env('CB_PLACEMENT_AZURE', 'eastus'),
+            cb_helpers.get_env('CB_PLACEMENT_AZURE', 'eastus'),
         "image":
-            get_env('CB_IMAGE_AZURE',
-                    'Canonical:UbuntuServer:16.04.0-LTS:latest'),
+            cb_helpers.get_env('CB_IMAGE_AZURE',
+                               'Canonical:UbuntuServer:16.04.0-LTS:latest'),
         "vm_type":
-            get_env('CB_VM_TYPE_AZURE', 'Basic_A2'),
+            cb_helpers.get_env('CB_VM_TYPE_AZURE', 'Basic_A2'),
     }
 }
 
@@ -181,7 +143,7 @@ def cleanup_network(network):
     if network:
         try:
             for sn in network.subnets:
-                with cleanup_action(lambda: cleanup_subnet(sn)):
+                with cb_helpers.cleanup_action(lambda: cleanup_subnet(sn)):
                     pass
         finally:
             network.delete()
@@ -211,7 +173,7 @@ def cleanup_gateway(gateway):
     """
     Delete the supplied network and gateway.
     """
-    with cleanup_action(lambda: gateway.delete()):
+    with cb_helpers.cleanup_action(lambda: gateway.delete()):
         pass
 
 
@@ -261,11 +223,12 @@ def delete_instance(instance):
 def cleanup_test_resources(instance=None, vm_firewall=None,
                            key_pair=None, network=None):
     """Clean up any combination of supplied resources."""
-    with cleanup_action(lambda: cleanup_network(network)
-                        if network else None):
-        with cleanup_action(lambda: key_pair.delete() if key_pair else None):
-            with cleanup_action(lambda: vm_firewall.delete()
-                                if vm_firewall else None):
+    with cb_helpers.cleanup_action(
+            lambda: cleanup_network(network) if network else None):
+        with cb_helpers.cleanup_action(
+                lambda: key_pair.delete() if key_pair else None):
+            with cb_helpers.cleanup_action(
+                    lambda: vm_firewall.delete() if vm_firewall else None):
                 delete_instance(instance)
 
 
@@ -293,7 +256,7 @@ class ProviderTestBase(unittest.TestCase):
             return 1
 
     def create_provider_instance(self):
-        provider_name = get_env("CB_TEST_PROVIDER", "aws")
+        provider_name = cb_helpers.get_env("CB_TEST_PROVIDER", "aws")
         factory = CloudProviderFactory()
         provider_class = factory.get_provider_class(provider_name)
         config = {'default_wait_interval':

+ 2 - 1
test/helpers/standard_interface_tests.py

@@ -9,6 +9,7 @@ import uuid
 
 import tenacity
 
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.interfaces.exceptions \
     import InvalidNameException
 from cloudbridge.cloud.interfaces.exceptions import InvalidParamException
@@ -330,7 +331,7 @@ def check_crud(test, service, iface, label_prefix,
     """
 
     obj = None
-    with helpers.cleanup_action(lambda: cleanup_func(obj)):
+    with cb_helpers.cleanup_action(lambda: cleanup_func(obj)):
         label = "{0}-{1}".format(label_prefix, helpers.get_uuid())
         if not skip_name_check:
             check_create(test, service, iface, label_prefix,

+ 10 - 9
test/test_block_store_service.py

@@ -2,6 +2,7 @@ import time
 
 import six
 
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.factory import ProviderList
 from cloudbridge.cloud.interfaces import SnapshotState
 from cloudbridge.cloud.interfaces import VolumeState
@@ -68,7 +69,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         test_instance = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 test_instance)):
             subnet = helpers.get_or_create_default_subnet(
                 self.provider)
@@ -77,7 +78,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
 
             test_vol = self.provider.storage.volumes.create(
                 label, 1, test_instance.zone_id)
-            with helpers.cleanup_action(lambda: test_vol.delete()):
+            with cb_helpers.cleanup_action(lambda: test_vol.delete()):
                 test_vol.wait_till_ready()
                 test_vol.attach(test_instance, '/dev/sda2')
                 test_vol.wait_for(
@@ -95,7 +96,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         test_instance = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 test_instance)):
             subnet = helpers.get_or_create_default_subnet(
                 self.provider)
@@ -104,7 +105,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
 
             test_vol = self.provider.storage.volumes.create(
                 label, 1, test_instance.zone_id, description=vol_desc)
-            with helpers.cleanup_action(lambda: test_vol.delete()):
+            with cb_helpers.cleanup_action(lambda: test_vol.delete()):
                 test_vol.wait_till_ready()
                 self.assertTrue(
                     isinstance(test_vol.size, six.integer_types) and
@@ -155,7 +156,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         test_vol = self.provider.storage.volumes.create(
             label, 1,
             helpers.get_provider_test_data(self.provider, "placement"))
-        with helpers.cleanup_action(lambda: test_vol.delete()):
+        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
             test_vol.wait_till_ready()
 
             def create_snap(label):
@@ -194,7 +195,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         test_vol = self.provider.storage.volumes.create(
             label, 1,
             helpers.get_provider_test_data(self.provider, "placement"))
-        with helpers.cleanup_action(lambda: test_vol.delete()):
+        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
             test_vol.wait_till_ready()
             snap_label = "cb-snap-{0}".format(label)
             test_snap = test_vol.create_snapshot(label=snap_label,
@@ -206,7 +207,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                     snap.wait_for([SnapshotState.UNKNOWN],
                                   terminal_states=[SnapshotState.ERROR])
 
-            with helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
+            with cb_helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
                 test_snap.wait_till_ready()
                 self.assertTrue(isinstance(test_vol.size, six.integer_types))
                 self.assertEqual(
@@ -232,11 +233,11 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                     sv_label, 1,
                     helpers.get_provider_test_data(self.provider, "placement"),
                     snapshot=test_snap)
-                with helpers.cleanup_action(lambda: snap_vol.delete()):
+                with cb_helpers.cleanup_action(lambda: snap_vol.delete()):
                     snap_vol.wait_till_ready()
 
                 # Test volume creation from a snapshot (via Snapshot)
                 snap_vol2 = test_snap.create_volume(
                     helpers.get_provider_test_data(self.provider, "placement"))
-                with helpers.cleanup_action(lambda: snap_vol2.delete()):
+                with cb_helpers.cleanup_action(lambda: snap_vol2.delete()):
                     snap_vol2.wait_till_ready()

+ 13 - 11
test/test_compute_service.py

@@ -2,6 +2,7 @@ import ipaddress
 
 import six
 
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.base.resources import BaseNetwork
 from cloudbridge.cloud.factory import ProviderList
 from cloudbridge.cloud.interfaces import InstanceState
@@ -90,7 +91,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
         test_instance = None
         fw = None
         kp = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 test_instance, fw, kp)):
             subnet = helpers.get_or_create_default_subnet(self.provider)
             net = subnet.network
@@ -243,7 +244,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
            label, 1,
            helpers.get_provider_test_data(self.provider,
                                           "placement"))
-        with helpers.cleanup_action(lambda: test_vol.delete()):
+        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
             test_vol.wait_till_ready()
             test_snap = test_vol.create_snapshot(label=label,
                                                  description=label)
@@ -254,7 +255,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                     snap.wait_for([SnapshotState.UNKNOWN],
                                   terminal_states=[SnapshotState.ERROR])
 
-            with helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
+            with cb_helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
                 test_snap.wait_till_ready()
 
                 lc = self.provider.compute.instances.create_launch_config()
@@ -301,7 +302,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                     self.provider)
 
                 inst = None
-                with helpers.cleanup_action(
+                with cb_helpers.cleanup_action(
                         lambda: helpers.delete_instance(inst)):
                     inst = helpers.create_test_instance(
                         self.provider,
@@ -326,7 +327,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
         net = None
         test_inst = None
         fw = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 instance=test_inst, vm_firewall=fw, network=net)):
             net = self.provider.networking.networks.create(
                 label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
@@ -361,18 +362,19 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             gateway = net.gateways.get_or_create()
 
             def cleanup_router(router, gateway):
-                with helpers.cleanup_action(lambda: router.delete()):
-                    with helpers.cleanup_action(lambda: gateway.delete()):
+                with cb_helpers.cleanup_action(lambda: router.delete()):
+                    with cb_helpers.cleanup_action(lambda: gateway.delete()):
                         router.detach_subnet(subnet)
                         router.detach_gateway(gateway)
 
-            with helpers.cleanup_action(lambda: cleanup_router(router,
-                                                               gateway)):
+            with cb_helpers.cleanup_action(lambda: cleanup_router(router,
+                                                                  gateway)):
                 router.attach_subnet(subnet)
                 router.attach_gateway(gateway)
                 fip = None
 
-                with helpers.cleanup_action(lambda: helpers.cleanup_fip(fip)):
+                with cb_helpers.cleanup_action(
+                        lambda: helpers.cleanup_fip(fip)):
                     # check whether adding an elastic ip works
                     fip = gateway.floating_ips.create()
                     self.assertFalse(
@@ -380,7 +382,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                         "Newly created floating IP %s should not be in use." %
                         fip.public_ip)
 
-                    with helpers.cleanup_action(
+                    with cb_helpers.cleanup_action(
                             lambda: test_inst.remove_floating_ip(fip)):
                         test_inst.add_floating_ip(fip)
                         test_inst.refresh()

+ 4 - 3
test/test_image_service.py

@@ -1,3 +1,4 @@
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.interfaces import MachineImageState
 from cloudbridge.cloud.interfaces.resources import Instance
 from cloudbridge.cloud.interfaces.resources import MachineImage
@@ -56,8 +57,8 @@ class CloudImageServiceTestCase(ProviderTestBase):
 
         def create_instance_from_image(img):
             img_instance = None
-            with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
-                    img_instance)):
+            with cb_helpers.cleanup_action(
+                    lambda: helpers.cleanup_test_resources(img_instance)):
                 img_instance = self.provider.compute.instances.create(
                     img_inst_label, img,
                     helpers.get_provider_test_data(self.provider, 'vm_type'),
@@ -86,7 +87,7 @@ class CloudImageServiceTestCase(ProviderTestBase):
                                 "private ip should"
                                 " contain a valid value")
 
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 test_instance)):
             subnet = helpers.get_or_create_default_subnet(
                 self.provider)

+ 4 - 0
test/test_middleware_system.py

@@ -15,6 +15,8 @@ from .helpers import skipIfPython
 
 class ExceptionWrappingMiddlewareTestCase(unittest.TestCase):
 
+    _multiprocess_can_split_ = True
+
     def test_unknown_exception_is_wrapped(self):
         EVENT_NAME = "an.exceptional.event"
 
@@ -60,6 +62,8 @@ class ExceptionWrappingMiddlewareTestCase(unittest.TestCase):
 
 class EventDebugLoggingMiddlewareTestCase(unittest.TestCase):
 
+    _multiprocess_can_split_ = True
+
     # Only python 3 has assertLogs support
     @skipIfPython("<", 3, 0)
     def test_messages_logged(self):

+ 14 - 10
test/test_network_service.py

@@ -1,3 +1,4 @@
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.base.resources import BaseNetwork
 from cloudbridge.cloud.interfaces.resources import FloatingIP
 from cloudbridge.cloud.interfaces.resources import Network
@@ -75,7 +76,7 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
         subnet_label = 'cb-propsubnet-{0}'.format(helpers.get_uuid())
         net = self.provider.networking.networks.create(
             label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
-        with helpers.cleanup_action(lambda: helpers.cleanup_network(net)):
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_network(net)):
             net.wait_till_ready()
             self.assertEqual(
                 net.state, 'available',
@@ -93,7 +94,7 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
                 label=subnet_label, cidr_block=cidr,
                 zone=helpers.get_provider_test_data(self.provider,
                                                     'placement'))
-            with helpers.cleanup_action(lambda: helpers.cleanup_subnet(sn)):
+            with cb_helpers.cleanup_action(lambda: helpers.cleanup_subnet(sn)):
                 self.assertTrue(
                     sn in net.subnets,
                     "Subnet ID %s should be listed in network subnets %s."
@@ -176,7 +177,7 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
             if fip:
                 gw.floating_ips.delete(fip.id)
 
-        with helpers.cleanup_action(
+        with cb_helpers.cleanup_action(
                 lambda: helpers.cleanup_gateway(gw)):
             sit.check_crud(self, gw.floating_ips, FloatingIP,
                            "cb-crudfip", create_fip, cleanup_fip,
@@ -187,9 +188,9 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
         gw = helpers.get_test_gateway(
             self.provider)
         fip = gw.floating_ips.create()
-        with helpers.cleanup_action(
+        with cb_helpers.cleanup_action(
                 lambda: helpers.cleanup_gateway(gw)):
-            with helpers.cleanup_action(lambda: fip.delete()):
+            with cb_helpers.cleanup_action(lambda: fip.delete()):
                 fipl = list(gw.floating_ips)
                 self.assertIn(fip, fipl)
                 # 2016-08: address filtering not implemented in moto
@@ -210,11 +211,13 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
     def test_crud_router(self):
 
         def _cleanup(net, subnet, router, gateway):
-            with helpers.cleanup_action(lambda: helpers.cleanup_network(net)):
-                with helpers.cleanup_action(
+            with cb_helpers.cleanup_action(
+                    lambda: helpers.cleanup_network(net)):
+                with cb_helpers.cleanup_action(
                         lambda: helpers.cleanup_subnet(subnet)):
-                    with helpers.cleanup_action(lambda: router.delete()):
-                        with helpers.cleanup_action(
+                    with cb_helpers.cleanup_action(
+                            lambda: router.delete()):
+                        with cb_helpers.cleanup_action(
                                 lambda: helpers.cleanup_gateway(gateway)):
                             router.detach_subnet(subnet)
                             router.detach_gateway(gateway)
@@ -226,7 +229,8 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
         sn = None
         router = None
         gteway = None
-        with helpers.cleanup_action(lambda: _cleanup(net, sn, router, gteway)):
+        with cb_helpers.cleanup_action(
+                lambda: _cleanup(net, sn, router, gteway)):
             net = self.provider.networking.networks.create(
                 label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
             router = self.provider.networking.routers.create(label=label,

+ 2 - 1
test/test_object_life_cycle.py

@@ -1,3 +1,4 @@
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.interfaces import VolumeState
 from cloudbridge.cloud.interfaces.exceptions import WaitStateException
 
@@ -14,7 +15,7 @@ class CloudObjectLifeCycleTestCase(ProviderTestBase):
         # Test object life cycle methods by using a volume.
         label = "cb-objlifecycle-{0}".format(helpers.get_uuid())
         test_vol = None
-        with helpers.cleanup_action(lambda: test_vol.delete()):
+        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
             test_vol = self.provider.storage.volumes.create(
                 label, 1,
                 helpers.get_provider_test_data(self.provider, "placement"))

+ 14 - 13
test/test_object_store_service.py

@@ -7,6 +7,7 @@ from unittest import skip
 
 import requests
 
+from cloudbridge.cloud.base import helpers as cb_helpers
 from cloudbridge.cloud.interfaces.exceptions import DuplicateResourceException
 from cloudbridge.cloud.interfaces.provider import TestMockHelperMixin
 from cloudbridge.cloud.interfaces.resources import Bucket
@@ -78,7 +79,7 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
             if bucket_obj:
                 bucket_obj.delete()
 
-        with helpers.cleanup_action(lambda: test_bucket.delete()):
+        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
             name = "cb-crudbucketobj-{0}".format(helpers.get_uuid())
             test_bucket = self.provider.storage.buckets.create(name)
 
@@ -98,12 +99,12 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
         objects = test_bucket.objects.list()
         self.assertEqual([], objects)
 
-        with helpers.cleanup_action(lambda: test_bucket.delete()):
+        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
             obj_name_prefix = "hello"
             obj_name = obj_name_prefix + "_world.txt"
             obj = test_bucket.objects.create(obj_name)
 
-            with helpers.cleanup_action(lambda: obj.delete()):
+            with cb_helpers.cleanup_action(lambda: obj.delete()):
                 # TODO: This is wrong. We shouldn't have to have a separate
                 # call to upload some content before being able to delete
                 # the content. Maybe the create_object method should accept
@@ -152,11 +153,11 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
         name = "cbtestbucketobjs-{0}".format(helpers.get_uuid())
         test_bucket = self.provider.storage.buckets.create(name)
 
-        with helpers.cleanup_action(lambda: test_bucket.delete()):
+        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
             obj_name = "hello_upload_download.txt"
             obj = test_bucket.objects.create(obj_name)
 
-            with helpers.cleanup_action(lambda: obj.delete()):
+            with cb_helpers.cleanup_action(lambda: obj.delete()):
                 content = b"Hello World. Here's some content."
                 # TODO: Upload and download methods accept different parameter
                 # types. Need to make this consistent - possibly provider
@@ -175,11 +176,11 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
         name = "cbtestbucketobjs-{0}".format(helpers.get_uuid())
         test_bucket = self.provider.storage.buckets.create(name)
 
-        with helpers.cleanup_action(lambda: test_bucket.delete()):
+        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
             obj_name = "hello_upload_download.txt"
             obj = test_bucket.objects.create(obj_name)
 
-            with helpers.cleanup_action(lambda: obj.delete()):
+            with cb_helpers.cleanup_action(lambda: obj.delete()):
                 content = b"Hello World. Generate a url."
                 obj.upload(content)
                 target_stream = BytesIO()
@@ -197,11 +198,11 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
         name = "cbtestbucketobjs-{0}".format(helpers.get_uuid())
         test_bucket = self.provider.storage.buckets.create(name)
 
-        with helpers.cleanup_action(lambda: test_bucket.delete()):
+        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
             obj_name = "hello_upload_download.txt"
             obj = test_bucket.objects.create(obj_name)
 
-            with helpers.cleanup_action(lambda: obj.delete()):
+            with cb_helpers.cleanup_action(lambda: obj.delete()):
                 test_file = os.path.join(
                     helpers.get_test_fixtures_folder(), 'logo.jpg')
                 obj.upload_from_file(test_file)
@@ -221,17 +222,17 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
         six_gig_file = os.path.join(temp_dir, file_name)
         with open(six_gig_file, "wb") as out:
             out.truncate(6 * 1024 * 1024 * 1024)  # 6 Gig...
-        with helpers.cleanup_action(lambda: os.remove(six_gig_file)):
+        with cb_helpers.cleanup_action(lambda: os.remove(six_gig_file)):
             download_file = "{0}/cbtestfile-{1}".format(temp_dir, file_name)
             bucket_name = "cbtestbucketlargeobjs-{0}".format(
                                                             helpers.get_uuid())
             test_bucket = self.provider.storage.buckets.create(bucket_name)
-            with helpers.cleanup_action(lambda: test_bucket.delete()):
+            with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
                 test_obj = test_bucket.objects.create(file_name)
-                with helpers.cleanup_action(lambda: test_obj.delete()):
+                with cb_helpers.cleanup_action(lambda: test_obj.delete()):
                     file_uploaded = test_obj.upload_from_file(six_gig_file)
                     self.assertTrue(file_uploaded, "Could not upload object?")
-                    with helpers.cleanup_action(
+                    with cb_helpers.cleanup_action(
                             lambda: os.remove(download_file)):
                         with open(download_file, 'wb') as f:
                             test_obj.save_content(f)

+ 7 - 7
test/test_security_service.py

@@ -59,7 +59,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
     def test_key_pair_properties(self):
         name = 'cb-kpprops-{0}'.format(helpers.get_uuid())
         kp = self.provider.security.key_pairs.create(name=name)
-        with helpers.cleanup_action(lambda: kp.delete()):
+        with cb_helpers.cleanup_action(lambda: kp.delete()):
             self.assertIsNotNone(
                 kp.material,
                 "KeyPair material is empty but it should not be.")
@@ -75,7 +75,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         public_key, _ = cb_helpers.generate_key_pair()
         kp = self.provider.security.key_pairs.create(
             name=name, public_key_material=public_key)
-        with helpers.cleanup_action(lambda: kp.delete()):
+        with cb_helpers.cleanup_action(lambda: kp.delete()):
             self.assertIsNone(kp.material, "Private KeyPair material should"
                               " be None when key is imported.")
 
@@ -108,7 +108,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         fw = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 vm_firewall=fw)):
             subnet = helpers.get_or_create_default_subnet(self.provider)
             net = subnet.network
@@ -125,7 +125,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         net = subnet.network
 
         fw = None
-        with helpers.cleanup_action(lambda: fw.delete()):
+        with cb_helpers.cleanup_action(lambda: fw.delete()):
             fw = self.provider.security.vm_firewalls.create(
                 label=label, description=label, network=net.id)
 
@@ -149,7 +149,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         fw = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 vm_firewall=fw)):
             subnet = helpers.get_or_create_default_subnet(self.provider)
             net = subnet.network
@@ -172,7 +172,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         fw = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 vm_firewall=fw)):
 
             subnet = helpers.get_or_create_default_subnet(self.provider)
@@ -196,7 +196,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
         fw = None
-        with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+        with cb_helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 vm_firewall=fw)):
             subnet = helpers.get_or_create_default_subnet(self.provider)
             net = subnet.network