From 45361ea9b3dab917a455bc37bc96aabd0bf64fcf Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 23 Aug 2021 10:33:37 +0200 Subject: [PATCH] mgr/{prometheus,restful}: Fix url generation again Fixes ``` ====================================================================== ERROR: test_standby (tasks.mgr.test_prometheus.TestPrometheus) ---------------------------------------------------------------------- urllib3.exceptions.LocationParseError: Failed to parse: http://172.21.15.71:7789metrics ``` Signed-off-by: Sebastian Wagner --- src/pybind/mgr/mgr_util.py | 8 ++++++-- src/pybind/mgr/prometheus/module.py | 2 +- src/pybind/mgr/restful/module.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index 982d69a798481..d865d31092aa9 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -435,7 +435,7 @@ def get_default_addr(): return result -def build_url(host: str, scheme: Optional[str] = None, port: Optional[int] = None) -> str: +def build_url(host: str, scheme: Optional[str] = None, port: Optional[int] = None, path: str = '') -> str: """ Build a valid URL. IPv6 addresses specified in host will be enclosed in brackets automatically. @@ -449,6 +449,10 @@ def build_url(host: str, scheme: Optional[str] = None, port: Optional[int] = Non >>> build_url('fce:9af7:a667:7286:4917:b8d3:34df:8373', port=80, scheme='http') 'http://[fce:9af7:a667:7286:4917:b8d3:34df:8373]:80' + >>> build_url('example.com', 'https', 443, path='/metrics') + 'https://example.com:443/metrics' + + :param scheme: The scheme, e.g. http, https or ftp. :type scheme: str :param host: Consisting of either a registered name (including but not limited to @@ -463,7 +467,7 @@ def build_url(host: str, scheme: Optional[str] = None, port: Optional[int] = Non pr = urllib.parse.ParseResult( scheme=scheme if scheme else '', netloc=netloc, - path='', + path=path, params='', query='', fragment='') diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 8b6fe9d31e034..796eddfc8ace8 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -1382,7 +1382,7 @@ class Module(MgrModule): # about to start serving if server_addr in ['::', '0.0.0.0']: server_addr = self.get_mgr_ip() - self.set_uri(build_url(scheme='http', host=server_addr, port=server_port)) + self.set_uri(build_url(scheme='http', host=server_addr, port=server_port, path='/')) cherrypy.config.update({ 'server.socket_host': server_addr, diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index e671cb97ab9eb..b76464e76fa8e 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -313,7 +313,7 @@ class Module(MgrModule): # Publish the URI that others may use to access the service we're # about to start serving addr = self.get_mgr_ip() if server_addr == "::" else server_addr - self.set_uri(build_url(scheme='https', host=addr, port=server_port)) + self.set_uri(build_url(scheme='https', host=addr, port=server_port, path='/')) # Create the HTTPS werkzeug server serving pecan app self.server = make_server( -- 2.39.5