← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~alexsander-souza/maas-ci/+git/system-tests:add_maas_gitrev_to_report into ~maas-committers/maas-ci/+git/system-tests:master

 

Alexsander de Souza has proposed merging ~alexsander-souza/maas-ci/+git/system-tests:add_maas_gitrev_to_report into ~maas-committers/maas-ci/+git/system-tests:master.

Commit message:
add MAAS git revision to test report

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~alexsander-souza/maas-ci/+git/system-tests/+merge/440799
-- 
Your team MAAS Committers is requested to review the proposed merge of ~alexsander-souza/maas-ci/+git/system-tests:add_maas_gitrev_to_report into ~maas-committers/maas-ci/+git/system-tests:master.
diff --git a/systemtests/conftest.py b/systemtests/conftest.py
index 58fc4aa..74238e5 100644
--- a/systemtests/conftest.py
+++ b/systemtests/conftest.py
@@ -5,6 +5,7 @@ from logging import getLogger
 from typing import TYPE_CHECKING, Any, Iterator
 
 import pytest
+from _pytest.terminal import TerminalReporter
 
 # Important that this comes before importing the modules so that
 # pytest can rewrite them early.
@@ -198,6 +199,18 @@ def pytest_runtest_makereport(item: Any, call: Any) -> Iterator[Any]:
         rep.sections.append(("Test logging", testlog.getvalue()))
 
 
+@pytest.hookimpl(hookwrapper=True)  # type: ignore
+def pytest_terminal_summary(
+    terminalreporter: TerminalReporter, exitstatus: int, config: pytest.Config
+):
+    yield
+    session = terminalreporter._session
+    if session is not None and hasattr(session, "maas_version"):
+        print("BEGIN_SYSTEMTESTS_META")
+        print(f"maasgit: {session.maas_version}")
+        print("END_SYSTEMTESTS_META")
+
+
 @pytest.fixture(scope="module")
 def machine_config(
     authenticated_admin: AuthenticatedAPIClient, request: Any
diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
index ce4c5cd..0cf6a82 100644
--- a/systemtests/fixtures.py
+++ b/systemtests/fixtures.py
@@ -431,7 +431,7 @@ def install_deb(
         ["apt-cache", "policy", "maas"],
         environment={"DEBIAN_FRONTEND": "noninteractive"},
     )  # just to record which version is running.
-    match = _DEB_GITREV_RE.match(policy.stdout)
+    match = _DEB_GITREV_RE.search(policy.stdout)
     if not match:
         return ""
     entry = match.groupdict()
@@ -440,7 +440,7 @@ def install_deb(
 
 def get_maas_snap_version(maas_container: Instance) -> str:
     snap_list = maas_container.execute(["snap", "list", "maas"])
-    match = _SNAP_GITREV_RE.match(snap_list.stdout)
+    match = _SNAP_GITREV_RE.search(snap_list.stdout)
     if not match:
         return ""
     entry = match.groupdict()
@@ -449,6 +449,7 @@ def get_maas_snap_version(maas_container: Instance) -> str:
 
 @pytest.fixture(scope="session")
 def maas_region(
+    request: pytest.FixtureRequest,
     maas_container: Instance,
     maas_deb_repo: Optional[str],
     vault: Optional[Vault],
@@ -497,10 +498,6 @@ def maas_region(
         assert maas_deb_repo is not None
         version = install_deb(maas_container, maas_deb_repo, config)
 
-    print("BEGIN_SYSTEMTESTS_META")
-    print(f"maasgit: {version}")
-    print("END_SYSTEMTESTS_META")
-
     # We never want to access the region via the system proxy
     if "no_proxy" not in os.environ:
         os.environ["no_proxy"] = region_ip
@@ -543,6 +540,8 @@ def maas_region(
         setup_o11y(config["o11y"], maas_container, installed_from_snap)
     yield region
 
+    setattr(request.session, "maas_version", version)
+
 
 @pytest.fixture(scope="session")
 def unauthenticated_maas_api_client(

Follow ups