libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: Modify CloudStack driver to correctly throw InvalidCredsError exception if invalid credentials are provided.
Date Tue, 03 Dec 2013 23:08:26 GMT
Updated Branches:
  refs/heads/trunk cb5901aac -> 74dd72687


Modify CloudStack driver to correctly throw InvalidCredsError exception if
invalid credentials are provided.


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

Branch: refs/heads/trunk
Commit: 75236ec13f0aaa235586ae7e8a82fcc3a12e7f04
Parents: cb5901a
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Tue Dec 3 18:10:33 2013 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Dec 3 18:10:33 2013 +0100

----------------------------------------------------------------------
 CHANGES                                  |  4 ++++
 libcloud/common/cloudstack.py            |  8 +++++++-
 libcloud/test/compute/test_cloudstack.py | 14 +++++++++++++-
 3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/75236ec1/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e0b77cf..852618b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -52,6 +52,10 @@ Changes with Apache Libcloud in development
       Reported by Igor Ajdisek.
       [Tomaz Muraus]
 
+   - Modify CloudStack driver to correctly throw InvalidCredsError exception if
+     invalid credentials are provided.
+     [Tomaz Muraus]
+
   *) Storage
 
     - Allow user to specify 'Content-Disposition' header in the CloudFiles

http://git-wip-us.apache.org/repos/asf/libcloud/blob/75236ec1/libcloud/common/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/cloudstack.py b/libcloud/common/cloudstack.py
index 5f139e2..4a22ba3 100644
--- a/libcloud/common/cloudstack.py
+++ b/libcloud/common/cloudstack.py
@@ -18,16 +18,22 @@ import hashlib
 import copy
 import hmac
 
+from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlencode
 from libcloud.utils.py3 import b
 
 from libcloud.common.base import ConnectionUserAndKey, PollingConnection
 from libcloud.common.base import JsonResponse
 from libcloud.common.types import MalformedResponseError
+from libcloud.compute.types import InvalidCredsError
 
 
 class CloudStackResponse(JsonResponse):
-    pass
+    def parse_error(self):
+        if self.status == httplib.UNAUTHORIZED:
+            raise InvalidCredsError('Invalid provider credentials')
+
+        return self.body
 
 
 class CloudStackConnection(ConnectionUserAndKey, PollingConnection):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/75236ec1/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index e950582..f7c99a4 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -26,7 +26,7 @@ except ImportError:
     import json
 
 from libcloud.compute.drivers.cloudstack import CloudStackNodeDriver
-from libcloud.compute.types import LibcloudError, Provider
+from libcloud.compute.types import LibcloudError, Provider, InvalidCredsError
 from libcloud.compute.providers import get_driver
 
 from libcloud.test import unittest
@@ -46,9 +46,16 @@ class CloudStackCommonTestCase(TestCaseMixin):
                                         host='api.dummy.com')
         self.driver.path = '/test/path'
         self.driver.type = -1
+        CloudStackMockHttp.type = None
         CloudStackMockHttp.fixture_tag = 'default'
         self.driver.connection.poll_interval = 0.0
 
+    def test_invalid_credentials(self):
+        CloudStackMockHttp.type = 'invalid_credentials'
+        driver = self.driver_klass('invalid', 'invalid', path='/test/path',
+                                   host='api.dummy.com')
+        self.assertRaises(InvalidCredsError, driver.list_nodes)
+
     def test_create_node_immediate_failure(self):
         size = self.driver.list_sizes()[0]
         image = self.driver.list_images()[0]
@@ -449,6 +456,11 @@ class CloudStackMockHttp(MockHttpTestCase):
         body = self.fixtures.load(fixture)
         return body, json.loads(body)
 
+    def _test_path_invalid_credentials(self, method, url, body, headers):
+        body = ''
+        return (httplib.UNAUTHORIZED, body, {},
+                httplib.responses[httplib.UNAUTHORIZED])
+
     def _test_path(self, method, url, body, headers):
         url = urlparse.urlparse(url)
         query = dict(parse_qsl(url.query))


Mime
View raw message