Skip to contentSkip to conversation

Fix send_qa_email for releases with new major number

PATCH New Alexis Lothoré 1 participant 5 messages Dec 17, 2023

lore
Share & tools
lore
#0 lore raw

cover Fix send_qa_email for releases with new major number

Hello,
the autobuilder encountered a failure while trying to generate 5.0_M1.rc1 (see [1]) on send_qa_email part, which resulted in missing QA email.

This issue is mostly due to the fact that this is the first release on new major 5.0. While this case is in theory handled in send_qa_email, practice came in and made things blew up: this version makes the tag computation method fall through the last branch, which currently expects the tag to exist. This assumption is a mistake: it may be valid when trying to generate regression reports a posteriori, but not for autobuilder run (tag is then applied only when corresponding release has been validated)

The two first commits slightly rework tests to prepare for the fix, which comes in the third commit.
Last commit makes sure that get_regression_base_and_target will not prevent QA email generation in case of an exception, as it is currently done with generate_regression_report

[1] https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/6338/steps/29/logs/stdio

Alexis Lothoré (4):
scripts: send_qa_email: slightly rework previous tag test
scripts: send_qa_email: allow testing against non fixed tags
scripts: send_qa_email: properly compute previous tag for new major
release tag
scripts: send_qa_email: protect get_regression_base_and_target from
exceptions

 scripts/send_qa_email.py      | 33 +++++++++++++++++++--------------
 scripts/test_send_qa_email.py | 15 ++++++++++-----
 2 files changed, 29 insertions(+), 19 deletions(-)
Signature · 1 line
2.42.1
#1 lore raw

PATCH 1/4 scripts: send_qa_email: slightly rework previous tag test

From: Alexis Lothoré <[email protected]>

Use intermediate variables for test input/output, and print expected output in subtest to get more info when a test fails

---
 scripts/test_send_qa_email.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/test_send_qa_email.py +4 -4
index 5509b3c2510e..8ab91538748a 100755
@@ -57,10 +57,10 @@ class TestVersion(unittest.TestCase):
 
     def test_versions(self):
         for data in self.test_data_get_version:
-            test_name = data["input"]["version"]
-            with self.subTest(f"Test {test_name} previous tag"):
-                self.assertEqual(send_qa_email.get_previous_tag(os.environ.get(
-                    "POKY_PATH"), data["input"]["version"]), data["expected"])
+            input_version = data["input"]["version"]
+            expected = data["expected"]
+            with self.subTest(f"Test {input_version} previous tag (expecting {expected})"):
+                self.assertEqual(send_qa_email.get_previous_tag(os.environ.get("POKY_PATH"), input_version), expected)
 
     def test_is_release_version(self):
         for data in self.test_data_is_release_version:
Signature · 1 line
2.42.1
#2 lore raw

PATCH 2/4 scripts: send_qa_email: allow testing against non fixed tags

In reply to Alexis Lothoré

From: Alexis Lothoré <[email protected]>

send_qa_email currently deals with tags in a "reproducible" way: despite new versions being released on different branches, the computation of the "reference" version for a specific input version always remain the same.

This behavior does not match perfectly real expectations: if at the some point we get version 4.3.1 as a comparison reference for a regression report, and 4.3.2 is released some time later, we want the next comparision to be done against 4.3.2.

Start introducing this new behavior by allowing the tests to check returned version against regex patterns instead of static strings, so we can for example use wildcards on the "micro" version

---
 scripts/test_send_qa_email.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/test_send_qa_email.py +3 -1
index 8ab91538748a..2dd946f32bf1 100755
@@ -12,6 +12,7 @@ import sys
 import unittest
 import send_qa_email
 import logging
+import re
 
 logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
 log = logging.getLogger('send-qa-email')
@@ -60,7 +61,8 @@ class TestVersion(unittest.TestCase):
             input_version = data["input"]["version"]
             expected = data["expected"]
             with self.subTest(f"Test {input_version} previous tag (expecting {expected})"):
-                self.assertEqual(send_qa_email.get_previous_tag(os.environ.get("POKY_PATH"), input_version), expected)
+               result = send_qa_email.get_previous_tag(os.environ.get("POKY_PATH"), input_version)
+               self.assertIsNotNone(re.match(data["expected"], result), msg=f"get_previous_tag returned {result}")
 
     def test_is_release_version(self):
         for data in self.test_data_is_release_version:
Signature · 1 line
2.42.1
#3 lore raw

PATCH 3/4 scripts: send_qa_email: properly compute previous tag for new major release tag

In reply to Alexis Lothoré

From: Alexis Lothoré <[email protected]>

send_qa_email currently fails when dealing with release version starting a new major, for example 5.0. This has been observed for example when trying to generate 5.0_M1.rc1

This specific versioning makes previous tag computation method fall through last branch which currently expects that the current release tag indeed exists (5.0_M1), which is true when checking regression reports a posteriori, but not in an autobuilder run (tag is added only when the release has been "validated")

Fix tag computation for this case by getting previous release tag with git ls-remote, instead of relying on git describe with a possibly non-existing tag. While doing so, add a few tests about this specific case.

---
 scripts/send_qa_email.py      | 9 +++++++--
 scripts/test_send_qa_email.py | 5 ++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
scripts/send_qa_email.py +7 -2
index 232f360621fe..8422e4937102 100755
@@ -42,10 +42,15 @@ def get_previous_tag(targetrepodir, version):
         # Process first milestone or release if not first in major release
         elif compareversionminor > 0:
             previousversion = compareversion[:-1] + [compareversion[-1] - 1]
-        # Otherwise : format it as tag (which must exist) and search previous tag
+        # Otherwise : compare against last release on previous major. This can
+        # not be computed: we need to retrieve the exact tag from remote
         else:
             comparetagstring = utils.get_tag_from_version(compareversion, comparemilestone)
-            return subprocess.check_output(["git", "describe", "--abbrev=0", comparetagstring + "^"], cwd=targetrepodir).decode('utf-8').strip()
+            previous_major = compareversion[0] - 1
+            tags_list = subprocess.check_output(["git", "ls-remote", "--refs", "-t", "origin", f"refs/tags/yocto-{previous_major}*"], cwd=targetrepodir).decode('utf-8').strip()
+            # Get last tag from list, pick only the tag part, and remove the
+            # "refs/tags/" part
+            return tags_list.splitlines()[-1].split()[1].split('/')[-1]
 
         return utils.get_tag_from_version(previousversion, previousmilestone)
 
scripts/test_send_qa_email.py +4 -1
index 2dd946f32bf1..415d8cbbbccd 100755
@@ -30,7 +30,10 @@ class TestVersion(unittest.TestCase):
         {"input": {"version": "4.1_M3.rc4"}, "expected": "4.1_M2"},
         {"input": {"version": "4.1_M1.rc1"}, "expected": "yocto-4.0"},
         {"input": {"version": "4.1_M1.rc4"}, "expected": "yocto-4.0"},
-        {"input": {"version": "4.1.rc4"}, "expected": "yocto-4.0"}
+        {"input": {"version": "4.1.rc4"}, "expected": "yocto-4.0"},
+        {"input": {"version": "yocto-5.0_M1.rc1"}, "expected": "yocto-4.3(\.\d)?"},
+        {"input": {"version": "yocto-5.0_M1.rc2"}, "expected": "yocto-4.3(\.\d)?"},
+        {"input": {"version": "yocto-5.0_M2.rc1"}, "expected": "5.0_M1"},
     ]
 
     test_data_is_release_version = [
Signature · 1 line
2.42.1
#4 lore raw

PATCH 4/4 scripts: send_qa_email: protect get_regression_base_and_target from exceptions

In reply to Alexis Lothoré

From: Alexis Lothoré <[email protected]>

generate_regression_reports is currently protect in a try/catch block to prevent it from canceling QA email generation when encountering an issue, but get_regression_base_and_target is not.

Make sure that get_regression_base_and_target can not prevent QA email from being generated by adding it to the try/catch block protecting send_qa_email. While doing so, make sure to preserve the exitcode variable to make sure that the step is still marked as fail in autobuilder to make sure the error does not go silent. However the variable is not needed as global anymore since it is now used in a single function.

---
 scripts/send_qa_email.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
scripts/send_qa_email.py +12 -12
index 8422e4937102..fe612c7e114a 100755
@@ -16,7 +16,6 @@ import logging
 import utils
 
 TEST_RESULTS_REPOSITORY_URL="git://git.yoctoproject.org/yocto-testresults"
-exitcode = 0
 
 def is_release_version(version):
     p = re.compile('\d{8}-\d+')
@@ -89,21 +88,16 @@ def get_regression_base_and_target(targetbranch, basebranch, release, targetrepo
 
 def generate_regression_report(querytool, targetrepodir, base, target, resultdir, outputdir, log):
     log.info(f"Comparing {target} to {base}")
-    global exitcode
 
-    try:
-        regreport = subprocess.check_output([querytool, "regression-report", base, target, '-t', resultdir])
-        with open(outputdir + "/testresult-regressions-report.txt", "wb") as f:
-           f.write(regreport)
-    except subprocess.CalledProcessError as e:
-        error = str(e)
-        exitcode = 1
-        log.error(f"Error while generating report between {target} and {base} : {error}")
+    regreport = subprocess.check_output([querytool, "regression-report", base, target, '-t', resultdir])
+    with open(outputdir + "/testresult-regressions-report.txt", "wb") as f:
+       f.write(regreport)
 
 def send_qa_email():
     # Setup logging
     logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
     log = logging.getLogger('send-qa-email')
+    exitcode = 0
 
     parser = utils.ArgParser(description='Process test results and optionally send an email about the build to prompt QA to begin testing.')
 
@@ -195,9 +189,15 @@ def send_qa_email():
             #     log.warning("Test results not published on release version. Faulty AB configuration ?")
 
             utils.printheader("Processing regression report")
-            regression_base, regression_target = get_regression_base_and_target(targetbranch, basebranch, args.release, targetrepodir, log)
-            if regression_base and regression_target:
+            try:
+                regression_base, regression_target = get_regression_base_and_target(targetbranch, basebranch, args.release, targetrepodir, log)
+                log.info(f"Generating regression report between {regression_base} and {regression_target}")
                 generate_regression_report(querytool, targetrepodir, regression_base, regression_target, tempdir, args.results_dir, log)
+            except subprocess.CalledProcessError as e:
+                error = str(e)
+                exitcode = 1
+                log.error(f"Error while generating regression report: {error}")
+
 
         finally:
             log.info(f"[SKIP] delete {tempdir}")
Signature · 1 line
2.42.1