Fix "Add API version to identity endpoint URLs"

Change Ieff5a6cdd1ad352a9731d46785802e8c36adcdd1 introduced an
uncomplete fix when trying to fix the auth_url.
Given the case that a auth url already has a version included, an extra
version was added. This leads to messages in the keystone.log that
horizon is trying to authenticate with "POST /v3/v3/auth/tokens
HTTP/1.1".
Use urlparse correctly and also add a testcase for fix_auth_url_version().

Change-Id: I80fb310d95e8fdab1212fc5b092a37fd7b26a37a
Closes-Bug: 1508421
This commit is contained in:
Thomas Bechtold 2016-02-05 22:52:32 +01:00
parent d779eb6fe3
commit e008112d0f
2 changed files with 30 additions and 1 deletions

View File

@ -1127,3 +1127,32 @@ class RoleTestCaseAdmin(test.TestCase):
self.assertSetEqual({'openstack.roles.foo',
'openstack.roles.bar',
'openstack.roles.admin'}, admin_permissions)
class UtilsTestCase(test.TestCase):
def test_fix_auth_url_version_v20(self):
settings.OPENSTACK_API_VERSIONS['identity'] = 2.0
test_urls = [
("http://a/", "http://a/v2.0"),
("http://a", "http://a/v2.0"),
("http://a:8080/", "http://a:8080/v2.0"),
("http://a/v2.0", "http://a/v2.0"),
("http://a/v2.0/", "http://a/v2.0/"),
]
for src, expected in test_urls:
self.assertEqual(expected, utils.fix_auth_url_version(src))
def test_fix_auth_url_version_v3(self):
settings.OPENSTACK_API_VERSIONS['identity'] = 3
test_urls = [
("http://a/", "http://a/v3"),
("http://a", "http://a/v3"),
("http://a:8080/", "http://a:8080/v3"),
("http://a/v3", "http://a/v3"),
("http://a/v3/", "http://a/v3/"),
("http://a/v2.0/", "http://a/v3/"),
("http://a/v2.0", "http://a/v3"),
]
for src, expected in test_urls:
self.assertEqual(expected, utils.fix_auth_url_version(src))

View File

@ -265,7 +265,7 @@ def fix_auth_url_version(auth_url):
# Check for empty path component in endpoint URL and add keystone version
# to endpoint: as of Kilo, the identity URLs returned by Keystone might no
# longer contain API versions, leaving the version choice up to the user.
if urlparse.urlparse(auth_url)[3] == '':
if urlparse.urlparse(auth_url).path.rstrip('/') == '':
if get_keystone_version() >= 3:
auth_url = urlparse.urljoin(auth_url, 'v3')
else: