libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1342839 - in /libcloud/trunk: CHANGES libcloud/common/openstack.py test/common/test_openstack.py test/compute/test_base.py
Date Fri, 25 May 2012 23:35:33 GMT
Author: tomaz
Date: Fri May 25 23:35:32 2012
New Revision: 1342839

URL: http://svn.apache.org/viewvc?rev=1342839&view=rev
Log:
Add a timeout of 10 seconds to OpenStackAuthConnection class. This patch has
been contributed by Chris Gilmer and is part of LIBCLOUD-199.

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

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1342839&r1=1342838&r2=1342839&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri May 25 23:35:32 2012
@@ -1,5 +1,12 @@
                                    -*- coding: utf-8 -*-
 
+Changes with Apache Libcloud in development:
+
+  *) Compute:
+    - Add a timeout of 10 seconds to OpenStackAuthConnection class.
+      ; LIBCLOUD-199
+      [Chris Gilmer]
+
 Changes with Apache Libcloud 0.10.1:
 
   *) General:

Modified: libcloud/trunk/libcloud/common/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/openstack.py?rev=1342839&r1=1342838&r2=1342839&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/openstack.py (original)
+++ libcloud/trunk/libcloud/common/openstack.py Fri May 25 23:35:32 2012
@@ -79,14 +79,19 @@ class OpenStackAuthConnection(Connection
 
     responseCls = OpenStackAuthResponse
     name = 'OpenStack Auth'
+    timeout = None
 
-    def __init__(self, parent_conn, auth_url, auth_version, user_id, key, tenant_name=None):
+    def __init__(self, parent_conn, auth_url, auth_version, user_id, key,
+                 tenant_name=None, timeout=None):
         self.parent_conn = parent_conn
         # 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)
+            user_id, key, url=auth_url, timeout=self.timeout)
 
         self.auth_version = auth_version
         self.auth_url = auth_url
@@ -363,7 +368,7 @@ class OpenStackBaseConnection(Connection
     service_region = None
 
     def __init__(self, user_id, key, secure=True,
-                 host=None, port=None,
+                 host=None, port=None, timeout=None,
                  ex_force_base_url=None,
                  ex_force_auth_url=None,
                  ex_force_auth_version=None,
@@ -392,7 +397,7 @@ class OpenStackBaseConnection(Connection
             self._auth_version = AUTH_API_VERSION
 
         super(OpenStackBaseConnection, self).__init__(
-            user_id, key, secure=secure)
+            user_id, key, secure=secure, timeout=timeout)
 
     def get_endpoint(self):
         """
@@ -449,7 +454,9 @@ class OpenStackBaseConnection(Connection
                                     'have auth_url set')
 
             osa = OpenStackAuthConnection(self, aurl, self._auth_version,
-                                          self.user_id, self.key, self._ex_tenant_name)
+                                          self.user_id, self.key,
+                                          tenant_name=self._ex_tenant_name,
+                                          timeout=self.timeout)
 
             # may throw InvalidCreds, etc
             osa.authenticate()

Added: libcloud/trunk/test/common/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/common/test_openstack.py?rev=1342839&view=auto
==============================================================================
--- libcloud/trunk/test/common/test_openstack.py (added)
+++ libcloud/trunk/test/common/test_openstack.py Fri May 25 23:35:32 2012
@@ -0,0 +1,29 @@
+import sys
+import unittest
+
+from mock import Mock
+
+from libcloud.common.openstack import OpenStackBaseConnection
+
+
+class OpenStackBaseConnectionTest(unittest.TestCase):
+
+    def setUp(self):
+        self.timeout = 10
+        OpenStackBaseConnection.conn_classes = (None, Mock())
+        self.connection = OpenStackBaseConnection('foo', 'bar',
+                                                  timeout=self.timeout,
+                                                  ex_force_auth_url='https://127.0.0.1')
+        self.connection.driver = Mock()
+        self.connection.driver.name = 'OpenStackDriver'
+
+    def test_base_connection_timeout(self):
+        self.connection.connect()
+        self.assertEquals(self.connection.timeout, self.timeout)
+        self.connection.conn_classes[1].assert_called_with(host='127.0.0.1',
+                                                           port=443,
+                                                           timeout=10)
+
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())

Modified: libcloud/trunk/test/compute/test_base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_base.py?rev=1342839&r1=1342838&r2=1342839&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_base.py (original)
+++ libcloud/trunk/test/compute/test_base.py Fri May 25 23:35:32 2012
@@ -16,7 +16,7 @@ import sys
 import unittest
 
 from libcloud.common.base import Response
-from libcloud.common.base import ConnectionKey, ConnectionUserAndKey
+from libcloud.common.base import Connection, ConnectionKey, ConnectionUserAndKey
 from libcloud.compute.base import Node, NodeSize, NodeImage, NodeDriver
 
 from test import MockResponse           # pylint: disable-msg=E0611
@@ -49,5 +49,8 @@ class BaseTests(unittest.TestCase):
     def test_base_connection_userkey(self):
         ConnectionUserAndKey('foo', 'bar')
 
+    def test_base_connection_timeout(self):
+        Connection(timeout=10)
+
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message