From bb240f425f878e75ad0126c9b7201de9e9d26918 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 | 19 +++++++++++++++++++ testsuite/tests/conftest.py | 14 +++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/testsuite/capabilities.py b/testsuite/capabilities.py index 1e5332ac..7c4fd55e 100644 --- a/testsuite/capabilities.py +++ b/testsuite/capabilities.py @@ -24,3 +24,22 @@ 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 = [settings["control_plane"]["cluster"]] + if cluster2 := settings["control_plane"]["cluster2"]: + clusters.append(cluster2) + 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.append((catalog_source.as_dict()["spec"]["image"], cluster.api_url)) + return versions diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index 3f318f1a..db476143 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -4,10 +4,11 @@ from urllib.parse import urlparse import pytest +from pytest_metadata.plugin import metadata_key # type: ignore 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 +72,17 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument report.extra = extra +def pytest_report_header(config): + """Adds Kuadrant version string to pytest header output for every cluster.""" + header = "" + images = [] + for image, cluster in kuadrant_version(): + header += f"Kuadrant image: {image} on cluster {cluster}\n" + images.append(image) + config.stash[metadata_key]["Kuadrant"] = images + return header + + @pytest.fixture(scope="session") def skip_or_fail(request): """Skips or fails tests depending on --enforce option"""