Avoid dead loop when token is string format
The token needs to be a callable object in http.Client, so we assign a lambda expression to it when it is a string, but current implementation will cause dead loop since it is x = lambda: x. This patch fixes it and improves the corresponding test code. Change-Id: Id41edd705b46196404e5cb3483a290074bde12d0 Closes-Bug: #1301877
This commit is contained in:
@@ -61,8 +61,8 @@ def get_client(api_version, **kwargs):
|
||||
* os_tenant_{name|id}: name or ID of tenant
|
||||
"""
|
||||
token = kwargs.get('os_auth_token')
|
||||
if token:
|
||||
token = (token if six.callable(token) else lambda: token)
|
||||
if token and not six.callable(token):
|
||||
token = lambda: kwargs.get('os_auth_token')
|
||||
|
||||
if token and kwargs.get('ceilometer_url'):
|
||||
endpoint = kwargs.get('ceilometer_url')
|
||||
|
||||
@@ -41,15 +41,17 @@ class ClientTest(utils.BaseTestCase):
|
||||
c2 = self.create_client(api_version=2)
|
||||
self.assertIsInstance(c2, v2client.Client)
|
||||
|
||||
def test_client_auth_lambda(self):
|
||||
FAKE_ENV['os_auth_token'] = lambda: FAKE_ENV['os_auth_token']
|
||||
self.assertIsInstance(FAKE_ENV['os_auth_token'],
|
||||
types.FunctionType)
|
||||
c2 = self.create_client()
|
||||
self.assertIsInstance(c2, v2client.Client)
|
||||
def test_client_auth_token_lambda(self):
|
||||
FAKE_ENV['os_auth_token'] = lambda: '1234'
|
||||
self._test_client_auth_token()
|
||||
|
||||
def test_client_auth_non_lambda(self):
|
||||
def test_client_auth_token_non_lambda(self):
|
||||
FAKE_ENV['os_auth_token'] = "1234"
|
||||
self.assertIsInstance(FAKE_ENV['os_auth_token'], str)
|
||||
self._test_client_auth_token()
|
||||
|
||||
def _test_client_auth_token(self):
|
||||
c2 = self.create_client()
|
||||
self.assertIsInstance(c2, v2client.Client)
|
||||
self.assertIsInstance(c2.http_client.auth_token,
|
||||
types.FunctionType)
|
||||
self.assertEqual('1234', c2.http_client.auth_token())
|
||||
|
||||
Reference in New Issue
Block a user