Support <scheme>://<netloc>/<prefix> 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
This commit is contained in:
Cedric Brandily
2016-04-13 00:28:50 +02:00
parent de0828e780
commit 1430a8f247
2 changed files with 5 additions and 1 deletions

View File

@@ -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])

View File

@@ -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"))