← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:ugj-check-running into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:ugj-check-running into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/461823
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:ugj-check-running into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
index c0f10fb..b9d2bf6 100755
--- a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
+++ b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
@@ -4,6 +4,7 @@ import configparser
 import datetime
 import io
 import json
+import pathlib
 import logging
 import os
 import sys
@@ -14,6 +15,7 @@ import swiftclient
 from request.submit import Submit
 
 PENDING_DIR = "/run/autopkgtest_webcontrol/github-pending"
+RUNNING_CACHE = "/run/amqp-status-collector/running.json"
 SWIFT_CREDS_FILE = "/home/ubuntu/public-swift-creds"
 MAX_DAY_DIFF = 30
 
@@ -102,6 +104,37 @@ def finish_job(jobfile, params, code, log_url):
     logging.debug("job %s finished!" % jobfile)
 
 
+def is_job_running(params):
+    job_match_me = (
+        params["arch"],
+        params["release"],
+        params["build-git"],
+        params["ppas"],
+        params["env"],
+    )
+
+    running_file = pathlib.Path(RUNNING_CACHE)
+    running_json = json.loads(running_file.read_text())
+    packages = running_json.keys()
+    if params["package"] not in packages:
+        return False
+    running_jobs = running_json[params["package"]]
+    for _, vals in running_jobs.items():
+        for release, vars in vals.items():
+            for arch, tests in vars.items():
+                for test in tests:
+                    this_test = (
+                        arch,
+                        release,
+                        test["build-git"],
+                        test["ppas"],
+                        test["env"],
+                    )
+                    if this_test == job_match_me:
+                        return True
+    return False
+
+
 def process_job(jobfile, swift_conn, ext_url):
     try:
         with open(jobfile) as f:
@@ -110,6 +143,9 @@ def process_job(jobfile, swift_conn, ext_url):
     except json.decoder.JSONDecodeError as e:
         logging.error("couldn't read %s, skipping: %s", jobfile, e)
         return
+    if is_job_running(params):
+        logging.debug("job %s is currently running, skipping.")
+        return
 
     logging.debug(
         "\n\n--------------------\nprocessing job %s:\n   %s",
@@ -128,6 +164,7 @@ def process_job(jobfile, swift_conn, ext_url):
 
     _, object_list = swift_conn.get_container(container, full_listing=True)
 
+    test_list = []
     for obj in object_list:
         if "result.tar" in obj["name"]:
             last_modified = obj["last_modified"].split(".")[0]
@@ -145,6 +182,14 @@ def process_job(jobfile, swift_conn, ext_url):
                 log_url = "/".join([ext_url, container, obj["name"]]).replace(
                     "result.tar", "log.gz"
                 )
+                store_me_maybe = {
+                    "jobfile": jobfile,
+                    "params": params,
+                    "code": code,
+                    "log_url": log_url,
+                }
+                test_list.append(store_me_maybe)
+                # do we really want to return here? There could be multiple jobs that match, no?
                 finish_job(jobfile, params, code, log_url)
                 return
 

References