Skip to content

Commit

Permalink
Merge pull request #244 from pehala/metrics_skip
Browse files Browse the repository at this point in the history
Enhance metrics tests skip
  • Loading branch information
pehala authored Nov 1, 2023
2 parents 6a5c705 + b4ce717 commit 37a26c4
Show file tree
Hide file tree
Showing 2 changed files with 49 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 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
15 changes: 14 additions & 1 deletion testsuite/tests/kuadrant/authorino/metrics/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Conftest for the Authorino metrics tests"""
import yaml

import pytest
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 +20,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
Expand Down

0 comments on commit 37a26c4

Please sign in to comment.