libcloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1237930 - in /libcloud/trunk: CHANGES libcloud/loadbalancer/drivers/rackspace.py test/loadbalancer/test_rackspace.py
Date Mon, 30 Jan 2012 19:02:16 GMT
Author: tomaz
Date: Mon Jan 30 19:02:16 2012
New Revision: 1237930

URL: http://svn.apache.org/viewvc?rev=1237930&view=rev
Log:
Update protocol name mapping in the Rackspace loadbalancer driver. This patch
has been submitted by Bill Woodward <bill dot woodward at rackspace dot com> and
is part of LIBCLOUD-144.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
    libcloud/trunk/test/loadbalancer/test_rackspace.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1237930&r1=1237929&r2=1237930&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Mon Jan 30 19:02:16 2012
@@ -88,6 +88,9 @@ Changes with Apache Libcloud in developm
       the Rackspace driver.
       [Mark Everett]
 
+    - Fix protocol name maping in the Rackspace driver.
+      [Bill Woodward]
+
 Changes with Apache Libcloud 0.7.1:
 
   *) General:

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py?rev=1237930&r1=1237929&r2=1237930&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py Mon Jan 30 19:02:16 2012
@@ -173,7 +173,7 @@ class RackspaceConnectionThrottle(object
             'maxConnections': self.max_connections,
             'minConnections': self.min_connections,
             'maxConnectionRate': self.max_connection_rate,
-            'rateInterval' : self.rate_interval_seconds
+            'rateInterval': self.rate_interval_seconds
         }
 
 
@@ -214,7 +214,7 @@ class RackspaceAccessRule(object):
 
         as_dict = {
             'type': type_string,
-            'address' : self.address,
+            'address': self.address
         }
 
         if self.id is not None:
@@ -891,7 +891,8 @@ class RackspaceLBDriver(Driver):
         @rtype: C{Balancer}
         @return: Updated Balancer.
         """
-        accepted = self.ex_update_balancer_error_page_no_poll(balancer, page_content)
+        accepted = self.ex_update_balancer_error_page_no_poll(balancer,
+                                                              page_content)
         if not accepted:
             msg = 'Update error page request not accepted'
             raise LibcloudError(msg, driver=self)
@@ -1214,6 +1215,18 @@ class RackspaceLBDriver(Driver):
                 extra=extra)
         return lbmember
 
+    def _protocol_to_value(self, protocol):
+        non_standard_protocols = {'imapv2': 'IMAPv2', 'imapv3': 'IMAPv3',
+                                  'imapv4': 'IMAPv4'}
+        protocol_name = protocol.lower()
+
+        if protocol_name in non_standard_protocols:
+            protocol_value = non_standard_protocols[protocol_name]
+        else:
+            protocol_value = protocol.upper()
+
+        return protocol_value
+
     def _kwargs_to_mutable_attrs(self, **attrs):
         update_attrs = {}
         if "name" in attrs:
@@ -1224,7 +1237,8 @@ class RackspaceLBDriver(Driver):
             update_attrs['algorithm'] = algorithm_value
 
         if "protocol" in attrs:
-            update_attrs['protocol'] = attrs['protocol'].upper()
+            update_attrs['protocol'] = \
+                self._protocol_to_value(attrs['protocol'])
 
         if "port" in attrs:
             update_attrs['port'] = int(attrs['port'])
@@ -1234,7 +1248,8 @@ class RackspaceLBDriver(Driver):
     def _kwargs_to_mutable_member_attrs(self, **attrs):
         update_attrs = {}
         if 'condition' in attrs:
-            update_attrs['condition'] = self.CONDITION_LB_MEMBER_MAP.get(attrs['condition'])
+            update_attrs['condition'] = \
+                self.CONDITION_LB_MEMBER_MAP.get(attrs['condition'])
 
         if 'weight' in attrs:
             update_attrs['weight'] = attrs['weight']

Modified: libcloud/trunk/test/loadbalancer/test_rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/loadbalancer/test_rackspace.py?rev=1237930&r1=1237929&r2=1237930&view=diff
==============================================================================
--- libcloud/trunk/test/loadbalancer/test_rackspace.py (original)
+++ libcloud/trunk/test/loadbalancer/test_rackspace.py Mon Jan 30 19:02:16 2012
@@ -631,6 +631,27 @@ class RackspaceLBTests(unittest.TestCase
         updated_balancer = self.driver.update_balancer(balancer, protocol='HTTPS')
         self.assertEqual('HTTPS', updated_balancer.extra['protocol'])
 
+    def test_update_balancer_protocol_to_imapv2(self):
+        balancer = LoadBalancer(id='3135', name='LB_update',
+            state='PENDING_UPDATE', ip='10.34.4.3',
+            port=80, driver=self.driver)
+        updated_balancer = self.driver.update_balancer(balancer, protocol='imapv2')
+        self.assertEqual('IMAPv2', updated_balancer.extra['protocol'])
+
+    def test_update_balancer_protocol_to_imapv3(self):
+        balancer = LoadBalancer(id='3136', name='LB_update',
+            state='PENDING_UPDATE', ip='10.34.4.3',
+            port=80, driver=self.driver)
+        updated_balancer = self.driver.update_balancer(balancer, protocol='IMAPV3')
+        self.assertEqual('IMAPv3', updated_balancer.extra['protocol'])
+
+    def test_update_balancer_protocol_to_imapv4(self):
+        balancer = LoadBalancer(id='3137', name='LB_update',
+            state='PENDING_UPDATE', ip='10.34.4.3',
+            port=80, driver=self.driver)
+        updated_balancer = self.driver.update_balancer(balancer, protocol='IMAPv4')
+        self.assertEqual('IMAPv4', updated_balancer.extra['protocol'])
+
     def test_update_balancer_port(self):
         balancer = LoadBalancer(id='3131', name='LB_update',
                                          state='PENDING_UPDATE', ip='10.34.4.3',
@@ -1142,6 +1163,42 @@ class RackspaceLBMockHttp(MockHttpTestCa
             return (httplib.BAD_REQUEST, "", {}, httplib.responses[httplib.BAD_REQUEST])
         raise NotImplementedError
 
+    def _v1_0_slug_loadbalancers_3135(self, method, url, body, headers):
+        """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3135') """
+        if method == "PUT":
+            self.assertEqual(json.loads(body), {'protocol': 'IMAPv2'})
+            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
+        elif method == "GET":
+            response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
+            response_body['loadBalancer']['id'] = 3135
+            response_body['loadBalancer']['protocol'] = 'IMAPv2'
+            return (httplib.OK, json.dumps(response_body), {}, httplib.responses[httplib.OK])
+        raise NotImplementedError
+
+    def _v1_0_slug_loadbalancers_3136(self, method, url, body, headers):
+        """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3136') """
+        if method == "PUT":
+            self.assertEqual(json.loads(body), {'protocol': 'IMAPv3'})
+            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
+        elif method == "GET":
+            response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
+            response_body['loadBalancer']['id'] = 3136
+            response_body['loadBalancer']['protocol'] = 'IMAPv3'
+            return (httplib.OK, json.dumps(response_body), {}, httplib.responses[httplib.OK])
+        raise NotImplementedError
+
+    def _v1_0_slug_loadbalancers_3137(self, method, url, body, headers):
+        """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3137') """
+        if method == "PUT":
+            self.assertEqual(json.loads(body), {'protocol': 'IMAPv4'})
+            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
+        elif method == "GET":
+            response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
+            response_body['loadBalancer']['id'] = 3137
+            response_body['loadBalancer']['protocol'] = 'IMAPv4'
+            return (httplib.OK, json.dumps(response_body), {}, httplib.responses[httplib.OK])
+        raise NotImplementedError
+
     def _v1_1_auth(self, method, url, body, headers):
         headers = {'content-type': 'application/json; charset=UTF-8'}
         body = self.auth_fixtures.load('_v1_1__auth.json')



Mime
View raw message