Преглед на файлове

Improved test coverage for base classes. Removed unused code.

nuwan_ag преди 10 години
родител
ревизия
8d0ec53062

+ 10 - 9
cloudbridge/cloud/base.py

@@ -131,16 +131,13 @@ class BaseObjectLifeCycleMixin(ObjectLifeCycleMixin):
     def wait_for(self, target_states, terminal_states=None, timeout=600,
                  interval=5):
         assert timeout > 0
-        assert timeout > interval
+        assert interval >= 0
+        assert timeout >= interval
 
         end_time = time.time() + timeout
-        while True:
-            if self.state in target_states:
-                log.debug(
-                    "Object: {0} successfully reached target state:"
-                    " {1}".format(self, self.state))
-                return True
-            elif self.state in terminal_states:
+
+        while self.state not in target_states:
+            if self.state in (terminal_states or []):
                 raise WaitStateException(
                     "Object: {0} is in state: {1} which is a terminal state"
                     " and cannot be waited on.".format(self, self.state))
@@ -158,6 +155,9 @@ class BaseObjectLifeCycleMixin(ObjectLifeCycleMixin):
                         "Waited too long for object: {0} to become ready. It's"
                         " still in state: {1}".format(self, self.state))
             self.refresh()
+        log.debug("Object: {0} successfully reached target state:"
+                  " {1}".format(self, self.state))
+        return True
 
 
 class BaseResultList(ResultList):
@@ -686,7 +686,8 @@ class BaseInstanceTypesService(
         if name:
             return (itype for itype in self.list() if itype.name == name)
         else:
-            return None
+            raise TypeError(
+                "Invalid parameters for search. Supported attributes: {name}")
 
 
 class BaseInstanceService(

+ 10 - 10
cloudbridge/cloud/interfaces/impl.py

@@ -50,16 +50,16 @@ class CloudProvider(object):
         """
         pass
 
-    @abstractproperty
-    def account(self):
-        """
-        Provides access to all user account related services in this provider.
-        This includes listing available tenancies.
-
-        :rtype: ``object`` of :class:`.ComputeService`
-        :return:  a ComputeService object
-        """
-        pass
+#     @abstractproperty
+#     def account(self):
+#         """
+#         Provides access to all user account related services in this
+#         provider. This includes listing available tenancies.
+#
+#         :rtype: ``object`` of :class:`.ComputeService`
+#         :return:  a ComputeService object
+#         """
+#         pass
 
     @abstractproperty
     def compute(self):

+ 0 - 5
cloudbridge/cloud/providers/aws/impl.py

@@ -59,11 +59,6 @@ class AWSCloudProvider(BaseCloudProvider):
             self._s3_conn = self._connect_s3()
         return self._s3_conn
 
-    @property
-    def account(self):
-        raise NotImplementedError(
-            'account not implemented by this provider')
-
     @property
     def compute(self):
         return self._compute

+ 0 - 5
cloudbridge/cloud/providers/openstack/impl.py

@@ -81,11 +81,6 @@ class OpenStackCloudProvider(BaseCloudProvider):
             self._neutron = self._connect_neutron()
         return self._neutron
 
-    @property
-    def account(self):
-        raise NotImplementedError(
-            'account not implemented by this provider')
-
     @property
     def compute(self):
         return self._compute

+ 2 - 0
test/__init__.py

@@ -33,6 +33,7 @@ from test.test_compute_service import CloudComputeServiceTestCase
 from test.test_image_service import CloudImageServiceTestCase
 from test.test_instance_types_service import CloudInstanceTypesServiceTestCase
 from test.test_interface import CloudInterfaceTestCase
+from test.test_object_life_cycle import CloudObjectLifeCycleTestCase
 from test.test_object_store_service import CloudObjectStoreServiceTestCase
 from test.test_region_service import CloudRegionServiceTestCase
 from test.test_security_service import CloudSecurityServiceTestCase
@@ -41,6 +42,7 @@ from test.test_security_service import CloudSecurityServiceTestCase
 PROVIDER_TESTS = [
     CloudHelpersTestCase,
     CloudInterfaceTestCase,
+    CloudObjectLifeCycleTestCase,
     CloudSecurityServiceTestCase,
     CloudInstanceTypesServiceTestCase,
     CloudComputeServiceTestCase,

+ 6 - 1
test/test_compute_service.py

@@ -122,7 +122,12 @@ class CloudComputeServiceTestCase(ProviderTestBase):
         # specifying an invalid size should raise
         # an exception
         with self.assertRaises(InvalidConfigurationException):
-            lc.add_volume_device(-1)
+            lc.add_volume_device(size=-1)
+
+        # Attempting to add a blank volume without specifying a size
+        # should raise an exception
+        with self.assertRaises(InvalidConfigurationException):
+            lc.add_volume_device(source=None)
 
         # block_devices should be empty so far
         self.assertListEqual(

+ 5 - 1
test/test_instance_types_service.py

@@ -88,4 +88,8 @@ class CloudInstanceTypesServiceTestCase(ProviderTestBase):
 
         with self.assertRaises(StopIteration):
             inst_type = next(self.provider.compute.instance_types.find(
-                name="Non_Existent_Instance_Type"))
+                name="non_existent_instance_type"))
+
+        with self.assertRaises(TypeError):
+            self.provider.compute.instance_types.find(
+                non_existent_param="random_value")

+ 45 - 0
test/test_object_life_cycle.py

@@ -0,0 +1,45 @@
+import uuid
+
+from cloudbridge.cloud.interfaces import VolumeState
+from cloudbridge.cloud.interfaces.resources import WaitStateException
+from test.helpers import ProviderTestBase
+import test.helpers as helpers
+
+
+class CloudObjectLifeCycleTestCase(ProviderTestBase):
+
+    def __init__(self, methodName, provider):
+        super(CloudObjectLifeCycleTestCase, self).__init__(
+            methodName=methodName, provider=provider)
+
+    def test_object_life_cycle(self):
+        """
+        Test object life cycle methods by using a volume.
+        """
+        name = "CBUnitTestLifeCycle-{0}".format(uuid.uuid4())
+        test_vol = self.provider.block_store.volumes.create(
+            name,
+            1,
+            helpers.get_provider_test_data(self.provider, "placement"))
+
+        # Waiting for an invalid timeout should raise an exception
+        with self.assertRaises(AssertionError):
+            test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
+        with self.assertRaises(AssertionError):
+            test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)
+
+        # If interval < timeout, an exception should be raised
+        with self.assertRaises(AssertionError):
+            test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
+
+        with helpers.cleanup_action(lambda: test_vol.delete()):
+            test_vol.wait_till_ready()
+            # Hitting a terminal state should raise an exception
+            with self.assertRaises(WaitStateException):
+                test_vol.wait_for(
+                    [VolumeState.ERROR],
+                    terminal_states=[VolumeState.AVAILABLE])
+
+            # Hitting the timeout should raise an exception
+            with self.assertRaises(WaitStateException):
+                test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=1)

+ 2 - 0
test/test_security_service.py

@@ -81,6 +81,8 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
             lambda:
                 self.provider.security.security_groups.delete(group_id=sg.id)
         ):
+            self.assertEqual(name, sg.description)
+
             sgl = self.provider.security.security_groups.get(
                 group_names=[
                     sg.name])