Skip to content

Commit

Permalink
Merge pull request Kuadrant#511 from azgabur/kuadrant_version_print
Browse files Browse the repository at this point in the history
Add Kuadrant version to pytest report
  • Loading branch information
jsmolar authored Sep 26, 2024
2 parents 0196a63 + bb240f4 commit 8ee50f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
19 changes: 19 additions & 0 deletions testsuite/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 8ee50f1

Please sign in to comment.