Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kuadrant version to pytest report #511

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions testsuite/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why break when a catalog or project is not found? For consistency's sake I would expect that we have relevant information in all reports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the catalog source under exact name CatalogSource/kuadrant-upstream inside openshift-marketplace namespace is not found than no version is printed. This is intended. I plan in the future to make the search for version better to work in more circumstances - mainly on Kind.

This feature should be taken just as convince not as production ready and documented feature of the testsuite.

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
Loading