← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~alexsander-souza/maas-ci/+git/system-tests:add_maas_gitrev_to_systemtests_meta 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_systemtests_meta into ~maas-committers/maas-ci/+git/system-tests:master.

Commit message:
add MAAS gitrev to systemtest metadata

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~alexsander-souza/maas-ci/+git/system-tests/+merge/439100
-- 
Your team MAAS Committers is requested to review the proposed merge of ~alexsander-souza/maas-ci/+git/system-tests:add_maas_gitrev_to_systemtests_meta into ~maas-committers/maas-ci/+git/system-tests:master.
diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
index decff3b..f035b4e 100644
--- a/systemtests/fixtures.py
+++ b/systemtests/fixtures.py
@@ -2,6 +2,7 @@ from __future__ import annotations
 
 import io
 import os
+import re
 from logging import Logger, StreamHandler, getLogger
 from textwrap import dedent
 from typing import Any, Iterator, Optional, TextIO
@@ -24,6 +25,9 @@ LOG_NAME = "systemtests.fixtures"
 
 LXD_PROFILE = os.environ.get("MAAS_SYSTEMTESTS_LXD_PROFILE", "prof-maas-lab")
 
+_DEB_GITREV_RE = re.compile(r"^\s+Installed:\s+\S+-g\.(?P<gitrev>\S+)-\S+$", re.M)
+_SNAP_GITREV_RE = re.compile(r"^maas\s+.+-g\.(?P<gitrev>\S+)\s+.+$", re.M)
+
 
 def _add_maas_ppa(
     instance: Instance,
@@ -426,11 +430,20 @@ def install_deb(
         ["apt-cache", "policy", "maas"],
         environment={"DEBIAN_FRONTEND": "noninteractive"},
     )  # just to record which version is running.
-    try:
-        version = policy.stdout.split("\n")[1].strip().split(" ")[1][2:]
-    except IndexError:
-        version = ""
-    return version
+    match = _DEB_GITREV_RE.match(policy.stdout)
+    if not match:
+        return ""
+    entry = match.groupdict()
+    return entry["gitrev"]
+
+
+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)
+    if not match:
+        return ""
+    entry = match.groupdict()
+    return entry["gitrev"]
 
 
 @pytest.fixture(scope="session")
@@ -463,15 +476,10 @@ def maas_region(
         maas_container.execute(["update-ca-certificates"])
 
     if installed_from_snap:
+        version = get_maas_snap_version(maas_container)
         maas_already_initialized = maas_container.files[
             "/var/snap/maas/common/snap_mode"
         ].exists()
-        # just to record which version is running.
-        snap_list = maas_container.execute(["snap", "list", "maas"])
-        try:
-            version = snap_list.stdout.split("\n")[1].split()[1]
-        except IndexError:
-            version = ""
         if not maas_already_initialized:
             maas_container.execute(
                 [
@@ -487,8 +495,10 @@ def maas_region(
     else:
         assert maas_deb_repo is not None
         version = install_deb(maas_container, maas_deb_repo, config)
-    with open("version_under_test", "w") as fh:
-        fh.write(f"{version}\n")
+
+    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:

Follow ups