From 823a00433fe6622f25a3c9dacf86fcd66b3e819b Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 2 Mar 2016 18:33:24 -0600 Subject: [PATCH] Use urlunparse to reconstruct base_url Using string replace to replace the new path back onto the old path fails when there is no path setup in the catalog initially. Instead of this lets use the inverse to the urlparse previously performed. Change-Id: I931f0c558aafc8dfaa5519744c6e4e7fcffc3205 Closes-Bug: #1552475 --- tempest/lib/auth.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tempest/lib/auth.py b/tempest/lib/auth.py index e269fd1807..2d20a0be6a 100644 --- a/tempest/lib/auth.py +++ b/tempest/lib/auth.py @@ -325,13 +325,24 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider): parts = urlparse.urlparse(_base_url) if filters.get('api_version', None) is not None: + version_path = '/%s' % filters['api_version'] path = re.sub(r'(^|/)+v\d+(?:\.\d+)?', - '/' + filters['api_version'], + version_path, parts.path, count=1) - _base_url = _base_url.replace(parts.path, path) + _base_url = urlparse.urlunparse((parts.scheme, + parts.netloc, + path or version_path, + parts.params, + parts.query, + parts.fragment)) if filters.get('skip_path', None) is not None and parts.path != '': - _base_url = _base_url.replace(parts.path, "/") + _base_url = urlparse.urlunparse((parts.scheme, + parts.netloc, + '/', + parts.params, + parts.query, + parts.fragment)) return _base_url @@ -447,13 +458,24 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider): parts = urlparse.urlparse(_base_url) if filters.get('api_version', None) is not None: + version_path = '/%s' % filters['api_version'] path = re.sub(r'(^|/)+v\d+(?:\.\d+)?', - '/' + filters['api_version'], + version_path, parts.path, count=1) - _base_url = _base_url.replace(parts.path, path) + _base_url = urlparse.urlunparse((parts.scheme, + parts.netloc, + path or version_path, + parts.params, + parts.query, + parts.fragment)) if filters.get('skip_path', None) is not None: - _base_url = _base_url.replace(parts.path, "/") + _base_url = urlparse.urlunparse((parts.scheme, + parts.netloc, + '/', + parts.params, + parts.query, + parts.fragment)) return _base_url