Make auth_token lazy load the auth_version.

Updates recent changes to the auth_token middleware (this
is a regression in d782a99) so that self.auth_version is
lazy loaded.

This fixes issues where other openstack services would fail
to startup correctly if Keystone is not running. The issue
was auth_token was trying to make a request to '/' to get
versions information on startup to "autodetect" the correct
version to use.

This patch fixes startup issues by moving the version detection
so that it is lazy loaded right before it is actually used.

This issue should fix SmokeStack :)

Fixes LP Bug #1154806.

Change-Id: Ib24f5386fa1ffe0e0365548840f0cfeaae36f548
This commit is contained in:
Dan Prince
2013-03-13 17:33:22 -04:00
parent d782a99847
commit db7603824f
2 changed files with 20 additions and 3 deletions

View File

@@ -333,9 +333,7 @@ class AuthProtocol(object):
http_connect_timeout_cfg = self._conf_get('http_connect_timeout')
self.http_connect_timeout = (http_connect_timeout_cfg and
int(http_connect_timeout_cfg))
# Determine the highest api version we can use.
self.auth_version = self._choose_api_version()
self.auth_version = None
def _assert_valid_memcache_protection_config(self):
if self._memcache_security_strategy:
@@ -982,6 +980,10 @@ class AuthProtocol(object):
:raise ServiceError if unable to authenticate token
"""
# Determine the highest api version we can use.
if not self.auth_version:
self.auth_version = self._choose_api_version()
if self.auth_version == 'v3.0':
headers = {'X-Auth-Token': self.get_admin_token(),
'X-Subject-Token': safe_quote(user_token)}

View File

@@ -542,6 +542,13 @@ class v3FakeHTTPConnection(FakeHTTPConnection):
self.resp = FakeHTTPResponse(status, body)
class RaisingHTTPConnection(FakeHTTPConnection):
""" An HTTPConnection that always raises."""
def request(self, method, path, **kwargs):
raise AssertionError("HTTP request was called.")
class FakeApp(object):
"""This represents a WSGI app protected by the auth_token middleware."""
def __init__(self, expected_env=None):
@@ -788,6 +795,14 @@ class DiabloAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest):
class AuthTokenMiddlewareTest(test.NoModule, BaseAuthTokenMiddlewareTest):
def test_init_does_not_call_http(self):
conf = {
'auth_host': 'keystone.example.com',
'auth_port': 1234
}
self.set_fake_http(RaisingHTTPConnection)
self.set_middleware(conf=conf, fake_http=RaisingHTTPConnection)
def assert_valid_last_url(self, token_id):
# Default version (v2) has id in the token, override this
# method for v3 and other versions