libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1484979 - in /libcloud/trunk/libcloud: common/openstack.py test/compute/test_openstack.py
Date Tue, 21 May 2013 21:44:10 GMT
Author: tomaz
Date: Tue May 21 21:44:10 2013
New Revision: 1484979

URL: http://svn.apache.org/r1484979
Log:
Modify authenticate() method to return self and add some tests for
OpenStackAuthConnection class.

Modified:
    libcloud/trunk/libcloud/common/openstack.py
    libcloud/trunk/libcloud/test/compute/test_openstack.py

Modified: libcloud/trunk/libcloud/common/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/openstack.py?rev=1484979&r1=1484978&r2=1484979&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/openstack.py (original)
+++ libcloud/trunk/libcloud/common/openstack.py Tue May 21 21:44:10 2013
@@ -35,8 +35,8 @@ AUTH_API_VERSION = '1.1'
 
 __all__ = [
     "OpenStackBaseConnection",
-    "OpenStackAuthConnection",
-    ]
+    "OpenStackAuthConnection"
+]
 
 
 # @TODO: Refactor for re-use by other openstack drivers
@@ -87,17 +87,18 @@ class OpenStackAuthConnection(Connection
         # enable tests to use the same mock connection classes.
         self.conn_classes = parent_conn.conn_classes
 
-        if timeout:
-            self.timeout = timeout
-
         super(OpenStackAuthConnection, self).__init__(
-            user_id, key, url=auth_url, timeout=self.timeout)
+            user_id, key, url=auth_url, timeout=timeout)
 
         self.auth_version = auth_version
         self.auth_url = auth_url
-        self.urls = {}
         self.driver = self.parent_conn.driver
         self.tenant_name = tenant_name
+        self.timeout = timeout
+
+        self.urls = {}
+        self.auth_token = None
+        self.auth_user_info = None
 
     def morph_action_hook(self, action):
         return action
@@ -153,6 +154,8 @@ class OpenStackAuthConnection(Connection
                 raise MalformedResponseError('Missing X-Auth-Token in \
                                               response headers')
 
+        return self
+
     def authenticate_1_1(self):
         reqbody = json.dumps({'credentials': {'username': self.user_id,
                                               'key': self.key}})
@@ -184,6 +187,8 @@ class OpenStackAuthConnection(Connection
                 raise MalformedResponseError('Auth JSON response is \
                                              missing required elements', e)
 
+        return self
+
     def authenticate_2_0_with_apikey(self):
         # API Key based authentication uses the RAX-KSKEY extension.
         # http://s.apache.org/oAi
@@ -237,6 +242,7 @@ class OpenStackAuthConnection(Connection
                 raise MalformedResponseError('Auth JSON response is \
                                              missing required elements', e)
 
+        return self
 
 class OpenStackServiceCatalog(object):
     """
@@ -421,6 +427,8 @@ class OpenStackBaseConnection(Connection
         self._ex_force_service_name = ex_force_service_name
         self._ex_force_service_region = ex_force_service_region
 
+        self._osa = None
+
         if ex_force_auth_token:
             self.auth_token = ex_force_auth_token
 
@@ -487,7 +495,7 @@ class OpenStackBaseConnection(Connection
         if not self.auth_token:
             aurl = self.auth_url
 
-            if self._ex_force_auth_url != None:
+            if self._ex_force_auth_url is not None:
                 aurl = self._ex_force_auth_url
 
             if aurl == None:

Modified: libcloud/trunk/libcloud/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_openstack.py?rev=1484979&r1=1484978&r2=1484979&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_openstack.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_openstack.py Tue May 21 21:44:10 2013
@@ -27,6 +27,7 @@ from libcloud.utils.py3 import u
 from libcloud.common.types import InvalidCredsError, MalformedResponseError, \
                                   LibcloudError
 from libcloud.common.openstack import OpenStackBaseConnection
+from libcloud.common.openstack import OpenStackAuthConnection
 from libcloud.compute.types import Provider
 from libcloud.compute.providers import get_driver
 from libcloud.compute.drivers.openstack import (
@@ -70,6 +71,7 @@ class OpenStack_1_0_ResponseTestCase(uni
 
 
 class OpenStackServiceCatalogTests(unittest.TestCase):
+    # TODO refactor and move into libcloud/test/common
     def test_connection_get_service_catalog(self):
         connection = OpenStackBaseConnection(*OPENSTACK_PARAMS)
         connection.conn_classes = (OpenStackMockHttp, OpenStackMockHttp)
@@ -92,6 +94,50 @@ class OpenStackServiceCatalogTests(unitt
         self.assertEqual(public_urls, expected_urls)
 
 
+class OpenStackAuthConnectionTests(unittest.TestCase):
+    # TODO refactor and move into libcloud/test/common
+    def test_basic_authentication(self):
+        tuples = [
+           ('1.0', OpenStackMockHttp),
+           ('1.1', OpenStackMockHttp),
+           ('2.0', OpenStack_2_0_MockHttp),
+           ('2.0_apikey', OpenStack_2_0_MockHttp),
+           ('2.0_password', OpenStack_2_0_MockHttp)
+        ]
+
+        user_id = OPENSTACK_PARAMS[0]
+        key = OPENSTACK_PARAMS[1]
+
+        for (auth_version, mock_http_class) in tuples:
+            connection = \
+                    self._get_mock_connection(mock_http_class=mock_http_class)
+            auth_url = connection.auth_url
+
+            osa = OpenStackAuthConnection(connection, auth_url, auth_version,
+                                          user_id, key)
+
+            self.assertEqual(osa.urls, {})
+            self.assertEqual(osa.auth_token, None)
+            self.assertEqual(osa.auth_user_info, None)
+            osa = osa.authenticate()
+
+            self.assertTrue(len(osa.urls) >= 1)
+            self.assertTrue(osa.auth_token is not None)
+
+    def test_token_expiration_and_force_reuath(self):
+        # TODO
+        pass
+
+    def _get_mock_connection(self, mock_http_class):
+        connection = OpenStackBaseConnection(*OPENSTACK_PARAMS)
+        connection.conn_classes = (mock_http_class, mock_http_class)
+        connection.auth_url = "https://auth.api.example.com/v1.1/"
+        connection._ex_force_base_url = "https://www.foo.com"
+        connection.driver = OpenStack_1_0_NodeDriver(*OPENSTACK_PARAMS)
+
+        return connection
+
+
 class OpenStack_1_0_Tests(unittest.TestCase, TestCaseMixin):
     should_list_locations = False
 



Mime
View raw message