libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [4/6] libcloud git commit: - fixes for tests Closes #936
Date Thu, 10 Nov 2016 01:04:11 GMT
- fixes for tests
Closes #936


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/4454f736
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/4454f736
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/4454f736

Branch: refs/heads/trunk
Commit: 4454f736a9a7e56236bba8d9a9584cb72a59efd2
Parents: 74e3398
Author: Anton Kozyrev <anton.kozyrev@gmail.com>
Authored: Wed Nov 2 13:35:42 2016 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Thu Nov 10 11:32:09 2016 +1100

----------------------------------------------------------------------
 libcloud/loadbalancer/drivers/alb.py   | 52 +++++++++++++++++++++--------
 libcloud/test/loadbalancer/test_alb.py |  1 +
 2 files changed, 40 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4454f736/libcloud/loadbalancer/drivers/alb.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/alb.py b/libcloud/loadbalancer/drivers/alb.py
index fb90515..f712fa9 100644
--- a/libcloud/loadbalancer/drivers/alb.py
+++ b/libcloud/loadbalancer/drivers/alb.py
@@ -17,7 +17,6 @@ __all__ = [
     'ApplicationLBDriver'
 ]
 
-from libcloud.utils.py3 import httplib
 from libcloud.utils.xml import findtext, findall
 from libcloud.loadbalancer.types import State
 from libcloud.loadbalancer.base import Driver, LoadBalancer, Member
@@ -54,7 +53,9 @@ class ApplicationLBDriver(Driver):
 
     def __init__(self, access_id, secret, region, token=None):
         self.token = token
-        super(ApplicationLBDriver, self).__init__(access_id, secret, token=token)
+        super(ApplicationLBDriver, self).__init__(
+            access_id, secret, token=token
+        )
         self.region = region
         self.region_name = region
         self.connection.host = HOST % (region)
@@ -83,7 +84,9 @@ class ApplicationLBDriver(Driver):
 
     def _to_listeners(self, data):
         xpath = 'DescribeListenersResult/Listeners/member'
-        return [self._to_listener(el) for el in findall(element=data, xpath=xpath, namespace=NS)]
+        return [self._to_listener(el) for el in findall(
+            element=data, xpath=xpath, namespace=NS
+        )]
 
     def _to_listener(self, el):
         listener_arn = findtext(element=el, xpath='ListenerArn', namespace=NS)
@@ -97,10 +100,16 @@ class ApplicationLBDriver(Driver):
 
     def _to_targets(self, data):
         xpath = 'DefaultActions/member'
-        return [self._to_target(el) for el in findall(element=data, xpath=xpath, namespace=NS)]
+        return [self._to_target(el) for el in findall(
+            element=data, xpath=xpath, namespace=NS
+        )]
 
     def _to_target(self, el):
-        return findtext(element=el, xpath='DefaultActions/member/TargetGroupArn', namespace=NS)
+        return findtext(
+            element=el,
+            xpath='DefaultActions/member/TargetGroupArn',
+            namespace=NS
+        )
 
     def _to_balancer(self, el):
         name = findtext(element=el, xpath='LoadBalancerName', namespace=NS)
@@ -122,7 +131,10 @@ class ApplicationLBDriver(Driver):
             'tags': self._ex_get_balancer_tags(balancer)
         }
         balancer.extra = extra
-        balancer.port = extra['listeners'][0]['port'] if len(extra['listeners']) > 0 else
None
+        if len(extra['listeners']) > 0:
+            balancer.port = extra['listeners'][0]['port']
+        else:
+            balancer.port = None
         balancer._members = self._ex_get_balancer_memebers(balancer)
 
         return balancer
@@ -154,13 +166,22 @@ class ApplicationLBDriver(Driver):
         id = findtext(element=el, xpath='RuleArn', namespace=NS)
         is_default = findtext(element=el, xpath='IsDefault', namespace=NS)
         priority = findtext(element=el, xpath='Priority', namespace=NS)
-        target_group = findtext(element=el, xpath='Actions/member/TargetGroupArn', namespace=NS)
+        target_group = findtext(
+            element=el,
+            xpath='Actions/member/TargetGroupArn',
+            namespace=NS
+        )
         conditions = {}
-
-        for cond_member in findall(element=el, xpath='Conditions/member', namespace=NS):
+        cond_members = findall(
+            element=el, xpath='Conditions/member', namespace=NS
+        )
+        for cond_member in cond_members:
             field = findtext(element=cond_member, xpath='Field', namespace=NS)
             conditions[field] = []
-            for value_member in findall(element=cond_member, xpath='Values/member', namespace=NS):
+            value_members = findall(
+                element=cond_member, xpath='Values/member', namespace=NS
+            )
+            for value_member in value_members:
                 conditions[field].append(value_member.text)
 
         rule = {
@@ -184,7 +205,9 @@ class ApplicationLBDriver(Driver):
                 for el in findall(element=data, xpath=xpath, namespace=NS)]
 
     def _to_target_group(self, el):
-        target_group_arn = findtext(element=el, xpath='TargetGroupArn', namespace=NS)
+        target_group_arn = findtext(
+            element=el, xpath='TargetGroupArn', namespace=NS
+        )
         name = findtext(element=el, xpath='TargetGroupName', namespace=NS)
         members = self._ex_get_target_group_members(target_group_arn)
 
@@ -198,7 +221,9 @@ class ApplicationLBDriver(Driver):
     def _to_target_group_member(self, el):
         id = findtext(element=el, xpath='Target/Id', namespace=NS)
         port = findtext(element=el, xpath='Target/Port', namespace=NS)
-        health = findtext(element=el, xpath='TargetHealth/State', namespace=NS)
+        health = findtext(
+            element=el, xpath='TargetHealth/State', namespace=NS
+        )
 
         return {'id': id, 'port': port, 'health': health}
 
@@ -277,7 +302,8 @@ class ApplicationLBDriver(Driver):
         return self._to_rules(data)
 
     def _ex_connection_class_kwargs(self):
-        kwargs = super(ApplicationLBDriver, self)._ex_connection_class_kwargs()
+        pdriver = super(ApplicationLBDriver, self)
+        kwargs = pdriver._ex_connection_class_kwargs()
         if hasattr(self, 'token') and self.token is not None:
             kwargs['token'] = self.token
             kwargs['signature_version'] = '4'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4454f736/libcloud/test/loadbalancer/test_alb.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_alb.py b/libcloud/test/loadbalancer/test_alb.py
index 700c5a3..0f1d293 100644
--- a/libcloud/test/loadbalancer/test_alb.py
+++ b/libcloud/test/loadbalancer/test_alb.py
@@ -126,6 +126,7 @@ class ApplicationLBTests(unittest.TestCase):
         self.assertTrue(('target_group' in listener_rules[0]), 'Rule is missing "target_group"
field')
         self.assertTrue(('conditions' in listener_rules[0]), 'Rule is missing "conditions"
field')
 
+
 class ApplicationLBMockHttp(MockHttpTestCase):
     fixtures = LoadBalancerFileFixtures('alb')
 


Mime
View raw message