Fix _make_connection_url

After support uWSGI[1], Watcher endpoint changed from http://ip:port
to http://ip/infra-optim. method _make_connection_url in HTTPClient
class can't return the correct url. This patch fixed it.
[1]: https://review.opendev.org/#/c/666779/

Change-Id: I77e610cd6781b252327a49aa5cd5bc63d395bf91
Closes-Bug: #1837186
This commit is contained in:
licanwei 2019-07-19 17:17:19 +08:00
parent 3caa385548
commit ea74a22b49
2 changed files with 9 additions and 1 deletions

View File

@ -276,7 +276,7 @@ class HTTPClient(VersionNegotiationMixin):
LOG.debug('\n'.join(dump))
def _make_connection_url(self, url):
return urlparse.urljoin(self.endpoint_trimmed, url)
return '%s/%s' % (self.endpoint_trimmed.rstrip('/'), url.lstrip('/'))
def _parse_version_headers(self, resp):
return self._generic_parse_version_headers(resp.headers.get)

View File

@ -350,3 +350,11 @@ class ClientTest(utils.BaseTestCase):
client = httpclient.HTTPClient('http://localhost/')
header_redact = client._process_header(name, value)
self.assertEqual(header, header_redact)
def test_make_connection_url(self):
endpoint = 'http://localhost/infra-optim'
url = '/v1/goals'
expected_url = 'http://localhost/infra-optim/v1/goals'
client = httpclient.HTTPClient(endpoint)
conn_url = client._make_connection_url(url)
self.assertEqual(expected_url, conn_url)