From 02f333e239eec4025eaed673488ebbe7a54821ef Mon Sep 17 00:00:00 2001 From: Alex Zgabur Date: Wed, 14 Aug 2024 13:25:26 +0200 Subject: [PATCH] Add Kuadrant version to pytest report Signed-off-by: Alex Zgabur --- testsuite/capabilities.py | 18 ++++++++++++++++++ testsuite/tests/conftest.py | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/testsuite/capabilities.py b/testsuite/capabilities.py index d0146ec7..6d5f477f 100644 --- a/testsuite/capabilities.py +++ b/testsuite/capabilities.py @@ -25,3 +25,21 @@ def has_kuadrant(): return False, f"Cluster {cluster.api_url} does not have Kuadrant resource in project {project}" return True, None + + +@functools.cache +def kuadrant_version(): + """Returns catalog image tag of deployed Kuadrant if possible.""" + clusters = weakget(settings)["control_plane"]["additional_clusters"] % [] + clusters.append(settings["cluster"]) + versions = "" + for cluster in clusters: + project = cluster.change_project("openshift-marketplace") + if not project.connected: + break + with project.context: + catalog_source = selector("CatalogSource/kuadrant-upstream").object(ignore_not_found=True) + if catalog_source is None: + break + versions += f"Kuadrant image: {catalog_source.as_dict()["spec"]["image"]} on cluster {cluster.api_url}\n" + return versions diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index 2ba424ac..61ca6180 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -7,7 +7,7 @@ from dynaconf import ValidationError from keycloak import KeycloakAuthenticationError -from testsuite.capabilities import has_kuadrant +from testsuite.capabilities import has_kuadrant, kuadrant_version from testsuite.certificates import CFSSLClient from testsuite.config import settings from testsuite.gateway import Exposer, CustomReference @@ -71,6 +71,11 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument report.extra = extra +def pytest_report_header(): + """Adds Kuadrant version string to pytest header output for every cluster.""" + return kuadrant_version() + + @pytest.fixture(scope="session") def skip_or_fail(request): """Skips or fails tests depending on --enforce option"""