Skip to content

Commit

Permalink
Improve metrics tests skip
Browse files Browse the repository at this point in the history
- Now it should skip if the userWorkloadMonitoring is off
- Add ConfigMap class for ease of use
  • Loading branch information
pehala committed Oct 18, 2023
1 parent d97df08 commit b834f0a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
35 changes: 35 additions & 0 deletions testsuite/openshift/objects/config_map.py
Original file line number Diff line number Diff line change
@@ -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 Secret"""
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
14 changes: 13 additions & 1 deletion testsuite/tests/kuadrant/authorino/metrics/conftest.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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: # pylint: disable=bare-except
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
Expand Down

0 comments on commit b834f0a

Please sign in to comment.