From 1430a8f2479cc0cd1caf72cfaecfcd84925f1227 Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Wed, 13 Apr 2016 00:28:50 +0200 Subject: [PATCH] Support :/// endpoints Currently openstack.session.parse_url[1] doesn't handle correctly endpoint with a non-empty relative path not containing the version. Typically it transforms the neutron endpoint: http://example.com/network into: http://example.com/v2.0 when it should transform it into: http://example.com/network/v2.0 This change corrects parse_url in order to support such case. [1] openstack.session Closes-Bug: #1569578 Change-Id: Id5d80552e8f0c972288af984944fe5fe2ae951bf --- openstack/session.py | 3 ++- openstack/tests/unit/test_session.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openstack/session.py b/openstack/session.py index 5786748a1..9dc18389d 100644 --- a/openstack/session.py +++ b/openstack/session.py @@ -35,7 +35,8 @@ def parse_url(filt, url): path = result.path vstr = VERSION_PATTERN.search(path) if not vstr: - return result.scheme + "://" + result.netloc + "/" + filt.get_path() + return (result.scheme + "://" + result.netloc + path.rstrip('/') + + '/' + filt.get_path()) start, end = vstr.span() prefix = path[:start] version = '/' + filt.get_path(path[start + 1:end]) diff --git a/openstack/tests/unit/test_session.py b/openstack/tests/unit/test_session.py index 60ebad79c..31c57306b 100644 --- a/openstack/tests/unit/test_session.py +++ b/openstack/tests/unit/test_session.py @@ -27,6 +27,9 @@ class TestSession(testtools.TestCase): self.assertEqual( "http://127.0.0.1:9292/v1", session.parse_url(filt, "http://127.0.0.1:9292")) + self.assertEqual( + "http://127.0.0.1:9292/foo/v1", + session.parse_url(filt, "http://127.0.0.1:9292/foo")) self.assertEqual( "http://127.0.0.1:9292/v2", session.parse_url(filt, "http://127.0.0.1:9292/v2.0"))