libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1392147 - in /libcloud/trunk/libcloud: compute/providers.py compute/types.py test/compute/test_rackspace.py
Date Mon, 01 Oct 2012 00:39:51 GMT
Author: tomaz
Date: Mon Oct  1 00:39:50 2012
New Revision: 1392147

URL: http://svn.apache.org/viewvc?rev=1392147&view=rev
Log:
Throw an exception if user wants to use old, now deprecated Rackspace provider
constant.

Modified:
    libcloud/trunk/libcloud/compute/providers.py
    libcloud/trunk/libcloud/compute/types.py
    libcloud/trunk/libcloud/test/compute/test_rackspace.py

Modified: libcloud/trunk/libcloud/compute/providers.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/providers.py?rev=1392147&r1=1392146&r2=1392147&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/providers.py (original)
+++ libcloud/trunk/libcloud/compute/providers.py Mon Oct  1 00:39:50 2012
@@ -17,7 +17,8 @@ Provider related utilities
 """
 
 from libcloud.utils.misc import get_driver as _get_provider_driver
-from libcloud.compute.types import Provider
+from libcloud.compute.types import Provider, DEPRECATED_RACKSPACE_PROVIDERS
+from libcloud.compute.types import OLD_CONSTANT_TO_NEW_MAPPING
 
 __all__ = [
     "Provider",
@@ -119,4 +120,15 @@ DRIVERS = {
 
 
 def get_driver(provider):
+    if provider in DEPRECATED_RACKSPACE_PROVIDERS:
+        id_to_name_map = dict([(v, k) for k, v in Provider.__dict__.items()])
+        old_name = id_to_name_map[provider]
+        new_name = id_to_name_map[OLD_CONSTANT_TO_NEW_MAPPING[provider]]
+
+        msg = 'Provider constant %s has been removed. New constant ' \
+              'is now called %s.\n' \
+              'For more information on this change and how to modify your ' \
+              'code to work with it, please visit: TODO' % (old_name, new_name)
+        raise Exception(msg)
+
     return _get_provider_driver(DRIVERS, provider)

Modified: libcloud/trunk/libcloud/compute/types.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/types.py?rev=1392147&r1=1392146&r2=1392147&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/types.py (original)
+++ libcloud/trunk/libcloud/compute/types.py Mon Oct  1 00:39:50 2012
@@ -18,6 +18,7 @@ Base types used by other parts of libclo
 
 from libcloud.common.types import LibcloudError, MalformedResponseError
 from libcloud.common.types import InvalidCredsError, InvalidCredsException
+
 __all__ = [
     "Provider",
     "NodeState",
@@ -28,7 +29,9 @@ __all__ = [
     "LibcloudError",
     "MalformedResponseError",
     "InvalidCredsError",
-    "InvalidCredsException"
+    "InvalidCredsException",
+    "DEPRECATED_RACKSPACE_PROVIDERS",
+    "OLD_CONSTANT_TO_NEW_MAPPING"
     ]
 
 
@@ -117,6 +120,29 @@ class Provider(object):
     GRIDSPOT = 49
     RACKSPACE_FIRST_GEN = 51
 
+    # Deprecated constants
+    RACKSPACE_UK = 23
+    RACKSPACE_NOVA_BETA = 40
+    RACKSPACE_NOVA_DFW = 41
+    RACKSPACE_NOVA_LON = 48
+    RACKSPACE_NOVA_ORD = 50
+
+
+DEPRECATED_RACKSPACE_PROVIDERS = [Provider.RACKSPACE_UK,
+                                  Provider.RACKSPACE_NOVA_BETA,
+                                  Provider.RACKSPACE_NOVA_DFW,
+                                  Provider.RACKSPACE_NOVA_LON,
+                                  Provider.RACKSPACE_NOVA_ORD]
+OLD_CONSTANT_TO_NEW_MAPPING = {
+    Provider.RACKSPACE: Provider.RACKSPACE_FIRST_GEN,
+    Provider.RACKSPACE_UK: Provider.RACKSPACE_FIRST_GEN,
+
+    Provider.RACKSPACE_NOVA_BETA: Provider.RACKSPACE,
+    Provider.RACKSPACE_NOVA_DFW: Provider.RACKSPACE,
+    Provider.RACKSPACE_NOVA_LON: Provider.RACKSPACE,
+    Provider.RACKSPACE_NOVA_ORD: Provider.RACKSPACE
+}
+
 
 class NodeState(object):
     """

Modified: libcloud/trunk/libcloud/test/compute/test_rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_rackspace.py?rev=1392147&r1=1392146&r2=1392147&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_rackspace.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_rackspace.py Mon Oct  1 00:39:50 2012
@@ -17,6 +17,8 @@ import unittest
 
 from libcloud.utils.py3 import method_type
 from libcloud.utils.py3 import httplib
+from libcloud.compute.providers import DEPRECATED_RACKSPACE_PROVIDERS
+from libcloud.compute.providers import get_driver
 from libcloud.compute.drivers.rackspace import RackspaceFirstGenNodeDriver
 from libcloud.compute.drivers.rackspace import RackspaceNodeDriver
 from libcloud.test.compute.test_openstack import OpenStack_1_0_Tests
@@ -37,6 +39,16 @@ class RackspaceusFirstGenUsTests(OpenSta
     driver_args = RACKSPACE_PARAMS
     driver_kwargs = {'region': 'us'}
 
+    def test_error_is_thrown_on_accessing_old_constant(self):
+        for provider in DEPRECATED_RACKSPACE_PROVIDERS:
+            try:
+                get_driver(provider)
+            except Exception:
+                e = sys.exc_info()[1]
+                self.assertTrue(str(e).find('has been removed') != -1)
+            else:
+                self.fail('Exception was not thrown')
+
     def test_list_sizes_pricing(self):
         sizes = self.driver.list_sizes()
 



Mime
View raw message