diff --git a/testsuite/openshift/objects/config_map.py b/testsuite/openshift/objects/config_map.py new file mode 100644 index 00000000..01ef5528 --- /dev/null +++ b/testsuite/openshift/objects/config_map.py @@ -0,0 +1,35 @@ +"""Config map""" +from testsuite.openshift.objects import OpenShiftObject + + +class ConfigMap(OpenShiftObject): + """Kubernetes ConfigMap object""" + + @classmethod + def create_instance( + cls, + openshift, + name, + data: dict[str, str], + labels: dict[str, str] = None, + ): + """Creates new Config Map""" + model: dict = { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": name, + "labels": labels, + }, + "data": data, + } + return cls(model, context=openshift.context) + + def __getitem__(self, name): + return self.model.data[name] + + def __contains__(self, name): + return name in self.model.data + + def __setitem__(self, name, value): + self.model.data[name] = value diff --git a/testsuite/tests/kuadrant/authorino/metrics/conftest.py b/testsuite/tests/kuadrant/authorino/metrics/conftest.py index ab2faddb..6f17fbc7 100644 --- a/testsuite/tests/kuadrant/authorino/metrics/conftest.py +++ b/testsuite/tests/kuadrant/authorino/metrics/conftest.py @@ -1,6 +1,9 @@ """Conftest for the Authorino metrics tests""" import pytest +import yaml +from openshift import selector +from testsuite.openshift.objects.config_map import ConfigMap from testsuite.openshift.objects.metrics import ServiceMonitor, MetricsEndpoint, Prometheus @@ -16,9 +19,18 @@ def prometheus(request, openshift): Return an instance of OpenShift metrics client Skip tests if query route is not properly configured """ + openshift_monitoring = openshift.change_project("openshift-monitoring") + # Check if metrics are enabled + try: + with openshift_monitoring.context: + cm = selector("cm/cluster-monitoring-config").object(cls=ConfigMap) + assert yaml.safe_load(cm["config.yaml"])["enableUserWorkload"] + except Exception: # pylint: disable=broad-exception-caught + pytest.skip("User workload monitoring is disabled") + # find thanos-querier route in the openshift-monitoring project # this route allows to query metrics - openshift_monitoring = openshift.change_project("openshift-monitoring") + routes = openshift_monitoring.get_routes_for_service("thanos-querier") if len(routes) > 0: url = ("https://" if "tls" in routes[0].model.spec else "http://") + routes[0].model.spec.host