You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/08/17 18:06:12 UTC

[3/6] git commit: Modify CloudStackLB driver to throw if user instantiates it directly, but doesn't pass in host and path.

Modify CloudStackLB driver to throw if user instantiates it directly, but
doesn't pass in host and path.


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

Branch: refs/heads/trunk
Commit: 2b5f467e4985b764ebe93d0f0315e5fb37473145
Parents: 670ef06
Author: Tomaz Muraus <to...@apache.org>
Authored: Sat Aug 17 16:59:52 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sat Aug 17 16:59:52 2013 +0200

----------------------------------------------------------------------
 libcloud/loadbalancer/drivers/cloudstack.py   | 22 +++++++++++++++++--
 libcloud/test/loadbalancer/test_cloudstack.py | 25 +++++++++++++++++++---
 2 files changed, 42 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b5f467e/libcloud/loadbalancer/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/cloudstack.py b/libcloud/loadbalancer/drivers/cloudstack.py
index 0a4e8a7..1cedfcc 100644
--- a/libcloud/loadbalancer/drivers/cloudstack.py
+++ b/libcloud/loadbalancer/drivers/cloudstack.py
@@ -16,6 +16,7 @@
 from libcloud.common.cloudstack import CloudStackDriverMixIn
 from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
 from libcloud.loadbalancer.base import DEFAULT_ALGORITHM
+from libcloud.loadbalancer.types import Provider
 from libcloud.loadbalancer.types import State
 from libcloud.utils.misc import reverse_dict
 
@@ -26,6 +27,7 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
     api_name = 'cloudstack_lb'
     name = 'CloudStack'
     website = 'http://cloudstack.org/'
+    type = Provider.CLOUDSTACK
 
     _VALUE_TO_ALGORITHM_MAP = {
         'roundrobin': Algorithm.ROUND_ROBIN,
@@ -37,11 +39,27 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
         'Active': State.RUNNING,
     }
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, key, secret=None, secure=True, host=None,
+                 path=None, port=None, *args, **kwargs):
         """
         @inherits: L{Driver.__init__}
         """
-        super(CloudStackLBDriver, self).__init__(*args, **kwargs)
+        host = host if host else self.host
+        path = path if path else self.path
+
+        if path is not None:
+            self.path = path
+
+        if host is not None:
+            self.host = host
+
+        if (self.type == Provider.CLOUDSTACK) and (not host or not path):
+            raise Exception('When instantiating CloudStack driver directly ' +
+                            'you also need to provide host and path argument')
+
+        super(CloudStackLBDriver, self).__init__(key=key, secret=secret,
+                                                 secure=secure,
+                                                 host=host, port=port)
 
     def list_protocols(self):
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b5f467e/libcloud/test/loadbalancer/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_cloudstack.py b/libcloud/test/loadbalancer/test_cloudstack.py
index 6c924b9..25b9cfb 100644
--- a/libcloud/test/loadbalancer/test_cloudstack.py
+++ b/libcloud/test/loadbalancer/test_cloudstack.py
@@ -11,6 +11,8 @@ from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import parse_qsl
 
 from libcloud.common.types import LibcloudError
+from libcloud.loadbalancer.types import Provider
+from libcloud.loadbalancer.providers import get_driver
 from libcloud.loadbalancer.base import LoadBalancer, Member, Algorithm
 from libcloud.loadbalancer.drivers.cloudstack import CloudStackLBDriver
 
@@ -21,13 +23,30 @@ class CloudStackLBTests(unittest.TestCase):
     def setUp(self):
         CloudStackLBDriver.connectionCls.conn_classes = \
             (None, CloudStackMockHttp)
+
+        CloudStackLBDriver.path = '/test/path'
+        CloudStackLBDriver.type = -1
+        CloudStackLBDriver.name = 'CloudStack'
         self.driver = CloudStackLBDriver('apikey', 'secret')
-        self.driver.path = '/test/path'
-        self.driver.type = -1
-        self.driver.name = 'CloudStack'
         CloudStackMockHttp.fixture_tag = 'default'
         self.driver.connection.poll_interval = 0.0
 
+    def test_user_must_provide_host_and_path(self):
+        CloudStackLBDriver.path = None
+        CloudStackLBDriver.type = Provider.CLOUDSTACK
+
+        expected_msg = 'When instantiating CloudStack driver directly ' + \
+                       'you also need to provide host and path argument'
+        cls = get_driver(Provider.CLOUDSTACK)
+
+        self.assertRaisesRegexp(Exception, expected_msg, cls,
+                                'key', 'secret')
+
+        try:
+            cls('key', 'secret', True, 'localhost', '/path')
+        except Exception:
+             self.fail('host and path provided but driver raised an exception')
+
     def test_list_supported_algorithms(self):
         algorithms = self.driver.list_supported_algorithms()