Przeglądaj źródła

Increased test coverage + code cleanup.

nuwan_ag 10 lat temu
rodzic
commit
7491799c60

+ 4 - 9
cloudbridge/cloud/base.py

@@ -260,7 +260,7 @@ class BaseLaunchConfig(LaunchConfig):
     def __init__(self, provider):
         self.provider = provider
         self.block_devices = []
-        self.net_ids = []
+        self.network_interfaces = []
 
     class BlockDeviceMapping(object):
         """
@@ -275,12 +275,6 @@ class BaseLaunchConfig(LaunchConfig):
             self.size = size
             self.delete_on_terminate = delete_on_terminate
 
-        def __repr__(self):
-            return "<CB-{0}: Dest: {1}, Src: {2}, IsRoot: {3}, Size: {4}>" \
-                .format(self.__class__.__name__,
-                        "volume" if self.is_volume else "ephemeral",
-                        self.source, self.is_root, self.size)
-
     def add_ephemeral_device(self):
         block_device = BaseLaunchConfig.BlockDeviceMapping()
         self.block_devices.append(block_device)
@@ -323,7 +317,7 @@ class BaseLaunchConfig(LaunchConfig):
             delete_on_terminate=delete_on_terminate)
 
     def add_network_interface(self, net_id):
-        self.net_ids.append(net_id)
+        self.network_interfaces.append(net_id)
 
 
 class BaseMachineImage(BaseObjectLifeCycleMixin, MachineImage):
@@ -496,7 +490,8 @@ class BaseSecurityGroup(SecurityGroup):
         return self._security_group.delete()
 
     def __repr__(self):
-        return "<CBSecurityGroup: {0}>".format(self.name)
+        return "<CB-{0}: {1}>".format(self.__class__.__name__,
+                                      self.id)
 
 
 class BaseSecurityGroupRule(SecurityGroupRule):

+ 36 - 36
cloudbridge/cloud/interfaces/resources.py

@@ -427,15 +427,15 @@ class Instance(ObjectLifeCycleMixin):
         """
         pass
 
-    @abstractproperty
-    def mac_address(self):
-        """
-        Get the MAC address for this instance.
-
-        :rtype: str
-        :return: MAC address for ths instance.
-        """
-        pass
+#     @abstractproperty
+#     def mac_address(self):
+#         """
+#         Get the MAC address for this instance.
+#
+#         :rtype: str
+#         :return: MAC address for ths instance.
+#         """
+#         pass
 
     @abstractproperty
     def security_groups(self):
@@ -880,33 +880,33 @@ class Snapshot(ObjectLifeCycleMixin):
         """
         pass
 
-    @abstractmethod
-    def share(self, user_ids=None):
-        """
-        Share this Snapshot.
-
-        :type user_ids: list of strings
-        :param user_ids: A list of cloud provider compatible user IDs. If no
-                         IDs are specified, the snapshot is made public.
-
-        :rtype: bool
-        :return: ``True`` if successful.
-        """
-        pass
-
-    @abstractmethod
-    def unshare(self, user_ids=None):
-        """
-        Unshare this Snapshot.
-
-        :type user_ids: list of strings
-        :param user_ids: A list of cloud provider compatible user IDs. If no
-                         IDs are specified, the snapshot is made private.
-
-        :rtype: bool
-        :return: ``True`` if successful.
-        """
-        pass
+#     @abstractmethod
+#     def share(self, user_ids=None):
+#         """
+#         Share this Snapshot.
+#
+#         :type user_ids: list of strings
+#         :param user_ids: A list of cloud provider compatible user IDs. If no
+#                          IDs are specified, the snapshot is made public.
+#
+#         :rtype: bool
+#         :return: ``True`` if successful.
+#         """
+#         pass
+#
+#     @abstractmethod
+#     def unshare(self, user_ids=None):
+#         """
+#         Unshare this Snapshot.
+#
+#         :type user_ids: list of strings
+#         :param user_ids: A list of cloud provider compatible user IDs. If no
+#                          IDs are specified, the snapshot is made private.
+#
+#         :rtype: bool
+#         :return: ``True`` if successful.
+#         """
+#         pass
 
     @abstractmethod
     def delete(self):

+ 3 - 2
cloudbridge/cloud/providers/aws/services.py

@@ -514,8 +514,9 @@ class AWSInstanceService(BaseInstanceService):
         return bdm
 
     def _get_net_id(self, launch_config):
-        return launch_config.net_ids[0] if len(launch_config.net_ids) > 0 \
-            else None
+        return (launch_config.network_interfaces[0]
+                if len(launch_config.network_interfaces) > 0
+                else None)
 
     def create_launch_config(self):
         return BaseLaunchConfig(self.provider)

+ 1 - 1
cloudbridge/cloud/providers/openstack/services.py

@@ -595,7 +595,7 @@ class OpenStackInstanceService(BaseInstanceService):
         Format network IDs for the API call.
         """
         nics = []
-        for net_id in launch_config.net_ids:
+        for net_id in launch_config.network_interfaces:
             nics.append({'net-id': net_id})
         return nics
 

+ 0 - 1
requirements.txt

@@ -1,3 +1,2 @@
 -e ".[full]"
-git+git://github.com/spulec/moto.git@ab3682a55c1c4f2983819e73a8cc59c0159a33f3
 git+git://github.com/openstack/python-keystoneclient.git@227e1b54cfc4a6a68268f9d5935d258b7490b7a3

+ 2 - 2
setup.py

@@ -5,14 +5,14 @@ openstack_reqs = ['python-novaclient', 'python-cinderclient',
                   'python-swiftclient', 'python-neutronclient']
 aws_reqs = ['boto']
 full_reqs = base_reqs + aws_reqs + openstack_reqs
-dev_reqs = ['tox'] + full_reqs
+dev_reqs = ['tox', 'moto>=0.4.18'] + full_reqs
 
 setup(name='cloudbridge',
       version=0.1,
       description='A simple layer of abstraction over multiple cloud'
       'providers.',
       author='Galaxy and GVL Projects',
-      author_email='support@genome.edu.au',
+      author_email='help@genome.edu.au',
       url='http://cloudbridge.readthedocs.org/',
       install_requires=full_reqs,
       extras_require={

+ 3 - 3
test/__init__.py

@@ -45,11 +45,11 @@ PROVIDER_TESTS = [
     CloudObjectLifeCycleTestCase,
     CloudSecurityServiceTestCase,
     CloudInstanceTypesServiceTestCase,
+    CloudBlockStoreServiceTestCase,
+    CloudObjectStoreServiceTestCase,
     CloudComputeServiceTestCase,
     CloudRegionServiceTestCase,
-    CloudImageServiceTestCase,
-    CloudBlockStoreServiceTestCase,
-    CloudObjectStoreServiceTestCase
+    CloudImageServiceTestCase
 ]
 
 

+ 4 - 4
test/test_block_store_service.py

@@ -54,8 +54,8 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
             get_vol = self.provider.block_store.volumes.get(
                 test_vol.id)
             self.assertTrue(
-                found_volumes[0].id ==
-                get_vol.id == test_vol.id,
+                found_volumes[0] ==
+                get_vol == test_vol,
                 "Ids returned by list: {0} and get: {1} are not as "
                 " expected: {2}" .format(found_volumes[0].id,
                                          get_vol.id,
@@ -152,8 +152,8 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                 get_snap = self.provider.block_store.snapshots.get(
                     test_snap.id)
                 self.assertTrue(
-                    found_snaps[0].id ==
-                    get_snap.id == test_snap.id,
+                    found_snaps[0] ==
+                    get_snap == test_snap,
                     "Ids returned by list: {0} and get: {1} are not as "
                     " expected: {2}" .format(found_snaps[0].id,
                                              get_snap.id,

+ 2 - 2
test/test_image_service.py

@@ -67,8 +67,8 @@ class CloudImageServiceTestCase(ProviderTestBase):
                 get_img = self.provider.compute.images.get(
                     test_image.id)
                 self.assertTrue(
-                    found_images[0].id == get_img.id == test_image.id,
-                    "Ids returned by list: {0} and get: {1} are not as "
+                    found_images[0] == get_img == test_image,
+                    "Objects returned by list: {0} and get: {1} are not as "
                     " expected: {2}" .format(found_images[0].id,
                                              get_img.id,
                                              test_image.id))

+ 3 - 2
test/test_object_life_cycle.py

@@ -33,12 +33,13 @@ class CloudObjectLifeCycleTestCase(ProviderTestBase):
             test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
 
         with helpers.cleanup_action(lambda: test_vol.delete()):
-            test_vol.wait_till_ready()
+            test_vol.wait_till_ready(interval=self.get_test_wait_interval())
             # Hitting a terminal state should raise an exception
             with self.assertRaises(WaitStateException):
                 test_vol.wait_for(
                     [VolumeState.ERROR],
-                    terminal_states=[VolumeState.AVAILABLE])
+                    terminal_states=[VolumeState.AVAILABLE],
+                    interval=self.get_test_wait_interval())
 
             # Hitting the timeout should raise an exception
             with self.assertRaises(WaitStateException):

+ 10 - 3
test/test_object_store_service.py

@@ -43,9 +43,9 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
             get_container = self.provider.object_store.get(
                 test_container.id)
             self.assertTrue(
-                found_containers[0].id ==
-                get_container.id == test_container.id,
-                "Names returned by list: {0} and get: {1} are not as "
+                found_containers[0] ==
+                get_container == test_container,
+                "Objects returned by list: {0} and get: {1} are not as "
                 " expected: {2}" .format(found_containers[0].id,
                                          get_container.id,
                                          test_container.name))
@@ -96,6 +96,13 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
                     len(found_objs) == 1,
                     "List container objects does not return the expected"
                     " object %s" % obj_name)
+
+                self.assertTrue(
+                    found_objs[0] == obj,
+                    "Objects returned by list: {0} are not as "
+                    " expected: {1}" .format(found_objs[0].id,
+                                             obj.id))
+
             objs = test_container.list()
             found_objs = [o for o in objs if o.name == obj_name]
             self.assertTrue(