diff --git a/testsuite/capabilities.py b/testsuite/capabilities.py index d0146ec7f..ce00378db 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.insert(0, 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.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 2ba424ac9..db573aa42 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 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"""