From ea74a22b4998a4214cf98828c4ff93676c8d46c8 Mon Sep 17 00:00:00 2001 From: licanwei Date: Fri, 19 Jul 2019 17:17:19 +0800 Subject: [PATCH] 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 --- watcherclient/common/httpclient.py | 2 +- watcherclient/tests/unit/test_client.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/watcherclient/common/httpclient.py b/watcherclient/common/httpclient.py index 6c70be9..f0cd592 100644 --- a/watcherclient/common/httpclient.py +++ b/watcherclient/common/httpclient.py @@ -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) diff --git a/watcherclient/tests/unit/test_client.py b/watcherclient/tests/unit/test_client.py index e49f7e1..f1ce98c 100644 --- a/watcherclient/tests/unit/test_client.py +++ b/watcherclient/tests/unit/test_client.py @@ -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)