Merge "Avoid dead loop when token is string format"

This commit is contained in:
Jenkins
2014-05-02 09:38:08 +00:00
committed by Gerrit Code Review
2 changed files with 12 additions and 10 deletions

View File

@@ -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')

View File

@@ -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())