Added tests and updated arguement options

Closes #631

Signed-off-by: Tomaz Muraus <to...@apache.org>


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

Branch: refs/heads/trunk
Commit: e0be27910b1426d087c4056420b9ce854adeb6d9
Parents: 84501da
Author: Anthony Shaw <anthony.p.s...@gmail.com>
Authored: Thu Nov 12 13:50:10 2015 +1100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Nov 12 23:45:56 2015 +0100

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py               |  5 ++---
 libcloud/compute/drivers/dimensiondata.py      | 24 ++++++---------------
 libcloud/loadbalancer/drivers/dimensiondata.py |  8 +++----
 libcloud/test/compute/test_dimensiondata.py    |  6 ++++++
 4 files changed, 19 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e0be2791/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 817ae7a..e5476e2 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -218,7 +218,7 @@ class DimensionDataConnection(ConnectionUserAndKey):
         return ("%s/%s/%s" % (self.api_path_version_2, self.api_version_2,
                               self._get_orgId()))
 
-    def wait_for_state(self, state, func, **kwargs):
+    def wait_for_state(self, state, func, *args, **kwargs):
         """
         Wait for the function which returns a instance
         with field status to match
@@ -234,9 +234,8 @@ class DimensionDataConnection(ConnectionUserAndKey):
         :param  kwargs: The arguments for func
         :type   kwargs: Keyword arguments
         """
-        response = func(kwargs)
         while(True):
-            response = func(kwargs)
+            response = func(*args, **kwargs)
             if response.status is state or response.status in state:
                 break
             sleep(2)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e0be2791/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py 
b/libcloud/compute/drivers/dimensiondata.py
index 6161f7a..39bbb1c 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -815,7 +815,7 @@ class DimensionDataNodeDriver(NodeDriver):
                 filter(lambda x: x.id == id, self.list_locations()))[0]
         return location
 
-    def ex_wait_for_state(self, state, func, **kwargs):
+    def ex_wait_for_state(self, state, func, *args, **kwargs):
         """
         Wait for the function which returns a instance
         with field status to match
@@ -831,7 +831,7 @@ class DimensionDataNodeDriver(NodeDriver):
         :param  kwargs: The arguments for func
         :type   kwargs: Keyword arguments
         """
-        self.connection.wait_for_state(state, func, kwargs)
+        self.connection.wait_for_state(state, func, *args, **kwargs)
 
     def _to_nat_rules(self, object, network_domain):
         rules = []
@@ -842,14 +842,12 @@ class DimensionDataNodeDriver(NodeDriver):
         return rules
 
     def _to_nat_rule(self, element, network_domain):
-        status = element.find(fixxpath('state', TYPES_URN))
-
         return DimensionDataNatRule(
             id=element.get('id'),
             network_domain=network_domain,
             internal_ip=findtext(element, 'internalIp', TYPES_URN),
             external_ip=findtext(element, 'externalIp', TYPES_URN),
-            status=status)
+            status=findtext(element, 'state', TYPES_URN))
 
     def _to_firewall_rules(self, object, network_domain):
         rules = []
@@ -861,8 +859,6 @@ class DimensionDataNodeDriver(NodeDriver):
         return rules
 
     def _to_firewall_rule(self, element, locations, network_domain):
-        status = element.find(fixxpath('state', TYPES_URN))
-
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
                                locations))[0]
@@ -880,7 +876,7 @@ class DimensionDataNodeDriver(NodeDriver):
             destination=self._to_firewall_address(
                 element.find(fixxpath('destination', TYPES_URN))),
             location=location,
-            status=status)
+            status=findtext(element, 'state', TYPES_URN))
 
     def _to_firewall_address(self, element):
         ip = element.find(fixxpath('ip', TYPES_URN))
@@ -902,8 +898,6 @@ class DimensionDataNodeDriver(NodeDriver):
         return blocks
 
     def _to_ip_block(self, element, locations):
-        status = element.find(fixxpath('state', TYPES_URN))
-
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
                                locations))[0]
@@ -916,7 +910,7 @@ class DimensionDataNodeDriver(NodeDriver):
             base_ip=findtext(element, 'baseIp', TYPES_URN),
             size=findtext(element, 'size', TYPES_URN),
             location=location,
-            status=status)
+            status=findtext(element, 'state', TYPES_URN))
 
     def _to_networks(self, object):
         networks = []
@@ -957,8 +951,6 @@ class DimensionDataNodeDriver(NodeDriver):
         return network_domains
 
     def _to_network_domain(self, element, locations):
-        status = element.find(fixxpath('state', TYPES_URN))
-
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
                                locations))[0]
@@ -973,7 +965,7 @@ class DimensionDataNodeDriver(NodeDriver):
             description=findtext(element, 'description', TYPES_URN),
             plan=plan_type,
             location=location,
-            status=status)
+            status=findtext(element, 'state', TYPES_URN))
 
     def _to_vlans(self, object):
         vlans = []
@@ -984,8 +976,6 @@ class DimensionDataNodeDriver(NodeDriver):
         return vlans
 
     def _to_vlan(self, element, locations):
-        status = element.find(fixxpath('state', TYPES_URN))
-
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
                                locations))[0]
@@ -998,7 +988,7 @@ class DimensionDataNodeDriver(NodeDriver):
             private_ipv4_range_address=ip_range.get('address'),
             private_ipv4_range_size=ip_range.get('prefixSize'),
             location=location,
-            status=status)
+            status=findtext(element, 'state', TYPES_URN))
 
     def _to_locations(self, object):
         locations = []

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e0be2791/libcloud/loadbalancer/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/dimensiondata.py 
b/libcloud/loadbalancer/drivers/dimensiondata.py
index 5d0fbf7..05b260b 100644
--- a/libcloud/loadbalancer/drivers/dimensiondata.py
+++ b/libcloud/loadbalancer/drivers/dimensiondata.py
@@ -823,10 +823,10 @@ class DimensionDataLBDriver(Driver):
         response_code = findtext(result, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'OK']
 
-    def ex_wait_for_state(self, state, func, **kwargs):
+    def ex_wait_for_state(self, state, func, *args, **kwargs):
         """
-        Wait for the function which returns a instance with
-        field status to match
+        Wait for the function which returns a instance
+        with field status to match
 
         Keep polling func until one of the desired states is matched
 
@@ -839,7 +839,7 @@ class DimensionDataLBDriver(Driver):
         :param  kwargs: The arguments for func
         :type   kwargs: Keyword arguments
         """
-        self.connection.wait_for_state(state, func, kwargs)
+        self.connection.wait_for_state(state, func, *args, **kwargs)
 
     def _to_nodes(self, object):
         nodes = []

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e0be2791/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py 
b/libcloud/test/compute/test_dimensiondata.py
index cbaa22f..07c160c 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -270,10 +270,16 @@ class DimensionDataTests(unittest.TestCase, 
TestCaseMixin):
         vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
         self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')
         self.assertEqual(vlan.description, 'test2')
+        self.assertEqual(vlan.status, 'NORMAL')
         self.assertEqual(vlan.name, 'Production VLAN')
         self.assertEqual(vlan.private_ipv4_range_address, '10.0.3.0')
         self.assertEqual(vlan.private_ipv4_range_size, '24')
 
+    def test_ex_wait_for_state(self):
+        self.driver.ex_wait_for_state('NORMAL',
+                                      self.driver.ex_get_vlan,
+                                      
vlan_id='0e56433f-d808-4669-821d-812769517ff8')
+
     def test_ex_update_vlan(self):
         vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
         vlan.name = 'new name'

Reply via email to