Rename Aetos's service type to metric-storage
Also it's no longer required for the service name to be 'aetos', which better aligns to how other services work and a default 443 port is used for https. Depends-On: https://review.opendev.org/c/openstack/service-types-authority/+/955782 Change-Id: I0f53830cf7ace12d44812a0b2c52aaa7e2ac6d07 Signed-off-by: Jaromir Wysoglad <jwysogla@redhat.com>
This commit is contained in:
@@ -16,7 +16,6 @@ import os
|
||||
from unittest import mock
|
||||
|
||||
from keystoneauth1 import adapter
|
||||
from keystoneauth1 import discover
|
||||
from keystoneauth1 import session
|
||||
import testtools
|
||||
|
||||
@@ -51,11 +50,6 @@ class GetPrometheusClientTest(testtools.TestCase):
|
||||
super(GetPrometheusClientTest, self).setUp()
|
||||
config_data = 'host: "somehost"\nport: "1234"'
|
||||
self.config_file = mock.mock_open(read_data=config_data)("name", 'r')
|
||||
self.prom_endpoint_data = discover.EndpointData(
|
||||
catalog_url="http://localhost:1234/prometheus",
|
||||
service_type="prometheus",
|
||||
service_name="aetos"
|
||||
)
|
||||
|
||||
def test_get_prometheus_client_from_file(self):
|
||||
with mock.patch.object(metric_utils, 'get_config_file',
|
||||
@@ -108,12 +102,13 @@ class GetPrometheusClientTest(testtools.TestCase):
|
||||
metric_utils.get_prometheus_client)
|
||||
|
||||
def test_get_prometheus_client_from_keystone_http(self):
|
||||
prom_endpoint = "http://localhost:1234/prometheus"
|
||||
keystone_session = session.Session()
|
||||
with mock.patch.dict(os.environ, {}), \
|
||||
mock.patch.object(metric_utils, 'get_config_file',
|
||||
return_value=None), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint_data',
|
||||
return_value=self.prom_endpoint_data), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
||||
return_value=prom_endpoint), \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
"__init__", return_value=None) as init_m, \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
@@ -125,14 +120,13 @@ class GetPrometheusClientTest(testtools.TestCase):
|
||||
ca_m.assert_not_called()
|
||||
|
||||
def test_get_prometheus_client_from_keystone_https(self):
|
||||
self.prom_endpoint_data.catalog_url = \
|
||||
"https://localhost:1234/prometheus"
|
||||
prom_endpoint = "https://localhost:1234/prometheus"
|
||||
keystone_session = session.Session()
|
||||
with mock.patch.dict(os.environ, {}), \
|
||||
mock.patch.object(metric_utils, 'get_config_file',
|
||||
return_value=None), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint_data',
|
||||
return_value=self.prom_endpoint_data), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
||||
return_value=prom_endpoint), \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
"__init__", return_value=None) as init_m, \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
@@ -144,16 +138,15 @@ class GetPrometheusClientTest(testtools.TestCase):
|
||||
ca_m.assert_called_with(True)
|
||||
|
||||
def test_get_prometheus_client_from_keystone_custom_ca(self):
|
||||
self.prom_endpoint_data.catalog_url = \
|
||||
"https://localhost:1234/prometheus"
|
||||
prom_endpoint = "https://localhost:1234/prometheus"
|
||||
keystone_session = session.Session()
|
||||
config_data = 'ca_cert: "ca/path"'
|
||||
config_file = mock.mock_open(read_data=config_data)("name", 'r')
|
||||
with mock.patch.dict(os.environ, {}), \
|
||||
mock.patch.object(metric_utils, 'get_config_file',
|
||||
return_value=config_file), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint_data',
|
||||
return_value=self.prom_endpoint_data), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
||||
return_value=prom_endpoint), \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
"__init__", return_value=None) as init_m, \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
@@ -192,14 +185,13 @@ class GetPrometheusClientTest(testtools.TestCase):
|
||||
)
|
||||
|
||||
def test_get_prometheus_client_from_keystone_ipv6(self):
|
||||
self.prom_endpoint_data.catalog_url = \
|
||||
"http://[2607:5300:201:2000::654]:80/prometheus"
|
||||
prom_endpoint = "http://[2607:5300:201:2000::654]:80/prometheus"
|
||||
keystone_session = session.Session()
|
||||
with mock.patch.dict(os.environ, {}), \
|
||||
mock.patch.object(metric_utils, 'get_config_file',
|
||||
return_value=None), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint_data',
|
||||
return_value=self.prom_endpoint_data), \
|
||||
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
||||
return_value=prom_endpoint), \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
"__init__", return_value=None) as init_m, \
|
||||
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
||||
|
@@ -73,10 +73,9 @@ def get_prometheus_client(session=None, adapter_options={}):
|
||||
try:
|
||||
endpoint = adapter.Adapter(
|
||||
session=session, **adapter_options
|
||||
).get_endpoint_data()
|
||||
parsed_url = parse.urlparse(endpoint.catalog_url)
|
||||
).get_endpoint()
|
||||
parsed_url = parse.urlparse(endpoint)
|
||||
host = parsed_url.hostname
|
||||
port = parsed_url.port if parsed_url.port is not None else 80
|
||||
root_path = parsed_url.path.strip('/')
|
||||
if parsed_url.scheme == "https" and ca_cert is None:
|
||||
# NOTE(jwysogla): Use the default CA certs if the scheme
|
||||
@@ -84,11 +83,13 @@ def get_prometheus_client(session=None, adapter_options={}):
|
||||
# so that a custom certificate can be set in the config
|
||||
# file, while the endpoint is retrieved from keystone.
|
||||
ca_cert = True
|
||||
if (endpoint.service_type == "prometheus" and
|
||||
endpoint.service_name == "aetos"):
|
||||
# We know this is Aetos and we can include keystone tokens
|
||||
# when sending requests to it.
|
||||
is_aetos = True
|
||||
if parsed_url.port is not None:
|
||||
port = parsed_url.port
|
||||
elif parsed_url.scheme == "https":
|
||||
port = 443
|
||||
else:
|
||||
port = 80
|
||||
is_aetos = True
|
||||
except keystone_exception.EndpointNotFound:
|
||||
# NOTE(jwysogla): Don't do anything here. It's still possible
|
||||
# to get the correct endpoint configuration from the env vars.
|
||||
@@ -108,8 +109,8 @@ def get_prometheus_client(session=None, adapter_options={}):
|
||||
root_path = os.environ['PROMETHEUS_ROOT_PATH']
|
||||
if host is None or port is None:
|
||||
raise ConfigurationError("Can't find prometheus host and "
|
||||
"port configuration and endpoint for service"
|
||||
"prometheus not found.")
|
||||
"port configuration and endpoint for "
|
||||
"metric-storage not found.")
|
||||
escaped_host = netutils.escape_ipv6(host)
|
||||
if is_aetos:
|
||||
client = PrometheusAPIClient(
|
||||
|
@@ -28,7 +28,7 @@ class Client(object):
|
||||
session_options = session_options or {}
|
||||
adapter_options = adapter_options or {}
|
||||
|
||||
adapter_options.setdefault('service_type', "prometheus")
|
||||
adapter_options.setdefault('service_type', "metric-storage")
|
||||
|
||||
if session is None:
|
||||
session = keystoneauth1.session.Session(**session_options)
|
||||
|
@@ -0,0 +1,6 @@
|
||||
---
|
||||
other:
|
||||
- |
|
||||
Service type used to automatically discover Aetos endpoint from
|
||||
keystone was changed from 'prometheus' to 'metric-storage'. The
|
||||
service name is no longer required to be 'aetos'.
|
Reference in New Issue
Block a user