diff mbox series

[yocto-autobuilder-helper,4/4] scripts: send_qa_email: protect get_regression_base_and_target from exceptions

Message ID 20231217133032.27231-5-alexis.lothore@bootlin.com
State New
Headers show
Series Fix send_qa_email for releases with new major number | expand

Commit Message

Alexis Lothoré Dec. 17, 2023, 1:30 p.m. UTC
From: Alexis Lothoré <alexis.lothore@bootlin.com>

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.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 scripts/send_qa_email.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/scripts/send_qa_email.py b/scripts/send_qa_email.py
index 8422e4937102..fe612c7e114a 100755
--- a/scripts/send_qa_email.py
+++ b/scripts/send_qa_email.py
@@ -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}")