From 7729380f83063c13efa8262e0c7ac1152cf23754 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Mon, 11 Apr 2016 15:14:54 -0500 Subject: [PATCH] Fix version replacement when path When an API server is on an unversioned path (for example, keystone is on http://localhost/identity), verify-config would fail with a 404 Not Found because the version wasn't put on the URL as required (for example, the v2.0 keystone url should have been http://localhost/identity/v2.0 but was instead http://localhost/identity). This is because the version replacement code wasn't adding the version when it wasn't present and a path was there. Change-Id: I559bd967a87b646906f37df81a7db096148488db --- tempest/lib/auth.py | 12 +++++++----- tempest/tests/lib/test_auth.py | 9 +++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tempest/lib/auth.py b/tempest/lib/auth.py index 5fc78b9566..a6833bede3 100644 --- a/tempest/lib/auth.py +++ b/tempest/lib/auth.py @@ -34,13 +34,15 @@ LOG = logging.getLogger(__name__) def replace_version(url, new_version): parts = urlparse.urlparse(url) version_path = '/%s' % new_version - path = re.sub(r'(^|/)+v\d+(?:\.\d+)?', - version_path, - parts.path, - count=1) + path, subs = re.subn(r'(^|/)+v\d+(?:\.\d+)?', + version_path, + parts.path, + count=1) + if not subs: + path = '%s%s' % (parts.path.rstrip('/'), version_path) url = urlparse.urlunparse((parts.scheme, parts.netloc, - path or version_path, + path, parts.params, parts.query, parts.fragment)) diff --git a/tempest/tests/lib/test_auth.py b/tempest/tests/lib/test_auth.py index 9ad3152bd3..d9b2b4af43 100644 --- a/tempest/tests/lib/test_auth.py +++ b/tempest/tests/lib/test_auth.py @@ -599,21 +599,18 @@ class TestReplaceVersion(base.TestCase): auth.replace_version('http://localhost:35357', 'v2.0')) def test_no_version_base_solidus(self): - # TODO(blk-u): This doesn't look like it works as expected. self.assertEqual( - 'http://localhost:35357/', + 'http://localhost:35357/v2.0', auth.replace_version('http://localhost:35357/', 'v2.0')) def test_no_version_path(self): - # TODO(blk-u): This doesn't look like it works as expected. self.assertEqual( - 'http://localhost/identity', + 'http://localhost/identity/v2.0', auth.replace_version('http://localhost/identity', 'v2.0')) def test_no_version_path_solidus(self): - # TODO(blk-u): This doesn't look like it works as expected. self.assertEqual( - 'http://localhost/identity/', + 'http://localhost/identity/v2.0', auth.replace_version('http://localhost/identity/', 'v2.0')) def test_path_version(self):