Make default get_auth timeout be None
Setting timeout to a default of False in get_auth() results in a requests timeout of 0.0 in keystoneclient, which causes a connection failure. This bug will cause func tests to not run when using keystoneauth. Added unit tests to verify correct default timeout is set in get_auth(). Drive-by: remove what seems like a stale TODO comment Change-Id: I17c781ce160a682b1768d315422ade0cdd2df198
This commit is contained in:
parent
49483a3b11
commit
f0cc3be2ac
@ -394,7 +394,7 @@ def get_auth(auth_url, user, key, **kwargs):
|
|||||||
storage_url, token = None, None
|
storage_url, token = None, None
|
||||||
cacert = kwargs.get('cacert', None)
|
cacert = kwargs.get('cacert', None)
|
||||||
insecure = kwargs.get('insecure', False)
|
insecure = kwargs.get('insecure', False)
|
||||||
timeout = kwargs.get('timeout', False)
|
timeout = kwargs.get('timeout', None)
|
||||||
if auth_version in AUTH_VERSIONS_V1:
|
if auth_version in AUTH_VERSIONS_V1:
|
||||||
storage_url, token = get_auth_1_0(auth_url,
|
storage_url, token = get_auth_1_0(auth_url,
|
||||||
user,
|
user,
|
||||||
|
@ -200,8 +200,6 @@ class TestHttpHelpers(MockHttpTest):
|
|||||||
ua = req_headers.get('user-agent', 'XXX-MISSING-XXX')
|
ua = req_headers.get('user-agent', 'XXX-MISSING-XXX')
|
||||||
self.assertEqual(ua, 'a-new-default')
|
self.assertEqual(ua, 'a-new-default')
|
||||||
|
|
||||||
# TODO: following tests are placeholders, need more tests, better coverage
|
|
||||||
|
|
||||||
|
|
||||||
class TestGetAuth(MockHttpTest):
|
class TestGetAuth(MockHttpTest):
|
||||||
|
|
||||||
@ -239,6 +237,59 @@ class TestGetAuth(MockHttpTest):
|
|||||||
# the full plumbing into the requests's 'verify' option
|
# the full plumbing into the requests's 'verify' option
|
||||||
self.assertIn('invalid_certificate', str(e))
|
self.assertIn('invalid_certificate', str(e))
|
||||||
|
|
||||||
|
def test_auth_v1_timeout(self):
|
||||||
|
# this test has some overlap with
|
||||||
|
# TestConnection.test_timeout_passed_down but is required to check that
|
||||||
|
# get_auth does the right thing when it is not passed a timeout arg
|
||||||
|
orig_http_connection = c.http_connection
|
||||||
|
timeouts = []
|
||||||
|
|
||||||
|
def fake_request_handler(*a, **kw):
|
||||||
|
if 'timeout' in kw:
|
||||||
|
timeouts.append(kw['timeout'])
|
||||||
|
else:
|
||||||
|
timeouts.append(None)
|
||||||
|
return MockHttpResponse(
|
||||||
|
status=200,
|
||||||
|
headers={
|
||||||
|
'x-auth-token': 'a_token',
|
||||||
|
'x-storage-url': 'http://files.example.com/v1/AUTH_user'})
|
||||||
|
|
||||||
|
def fake_connection(*a, **kw):
|
||||||
|
url, conn = orig_http_connection(*a, **kw)
|
||||||
|
conn._request = fake_request_handler
|
||||||
|
return url, conn
|
||||||
|
|
||||||
|
with mock.patch('swiftclient.client.http_connection', fake_connection):
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
auth_version="1.0", timeout=42.0)
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
auth_version="1.0", timeout=None)
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
auth_version="1.0")
|
||||||
|
|
||||||
|
self.assertEqual(timeouts, [42.0, None, None])
|
||||||
|
|
||||||
|
def test_auth_v2_timeout(self):
|
||||||
|
# this test has some overlap with
|
||||||
|
# TestConnection.test_timeout_passed_down but is required to check that
|
||||||
|
# get_auth does the right thing when it is not passed a timeout arg
|
||||||
|
fake_ks = FakeKeystone(endpoint='http://some_url', token='secret')
|
||||||
|
with mock.patch('swiftclient.client._import_keystone_client',
|
||||||
|
_make_fake_import_keystone_client(fake_ks)):
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
os_options=dict(tenant_name='tenant'),
|
||||||
|
auth_version="2.0", timeout=42.0)
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
os_options=dict(tenant_name='tenant'),
|
||||||
|
auth_version="2.0", timeout=None)
|
||||||
|
c.get_auth('http://www.test.com', 'asdf', 'asdf',
|
||||||
|
os_options=dict(tenant_name='tenant'),
|
||||||
|
auth_version="2.0")
|
||||||
|
self.assertEqual(3, len(fake_ks.calls))
|
||||||
|
timeouts = [call['timeout'] for call in fake_ks.calls]
|
||||||
|
self.assertEqual([42.0, None, None], timeouts)
|
||||||
|
|
||||||
def test_auth_v2_with_tenant_name(self):
|
def test_auth_v2_with_tenant_name(self):
|
||||||
os_options = {'tenant_name': 'asdf'}
|
os_options = {'tenant_name': 'asdf'}
|
||||||
req_args = {'auth_version': '2.0'}
|
req_args = {'auth_version': '2.0'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user