← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:user-specific-page into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:user-specific-page into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)
Related bugs:
  Bug #2057947 in Auto Package Testing: "Feature: user-specific history page"
  https://bugs.launchpad.net/auto-package-testing/+bug/2057947

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/462713
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:user-specific-page into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index 810163d..1f09ca7 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -51,6 +51,18 @@ def init_config():
     swift_container_url = os.path.join(url, "autopkgtest-%s")
 
 
+def get_package_release_arch(test_id):
+    c = db_con.cursor()
+    c.execute(
+        "SELECT package, release, arch FROM test WHERE id=?",
+        (test_id,),
+    )
+    try:
+        return c.fetchone()
+    except TypeError:
+        return None
+
+
 def get_test_id(release, arch, src):
     c = db_con.cursor()
     c.execute(
@@ -315,6 +327,116 @@ def package_overview(package, _=None):
     )
 
 
+@app.route("/user/<user>")
+def user_overview(user):
+    results = []
+    # get previous results!
+    for row in db_con.execute(
+        "SELECT test_id, run_id, version, triggers, duration, exitcode, requester, env, uuid FROM result "
+        "WHERE requester=? "
+        "ORDER BY run_id DESC",
+        (user,),
+    ):
+        test_id = row[0]
+        version = row[2]
+        triggers = row[3]
+        additional_params = row[
+            7
+        ]  # string of comma separated env variables e.g. all-proposed=1,test-name=mytest
+        code = human_exitcode(row[5])
+        release, arch, package = get_package_release_arch(test_id)
+        url = os.path.join(
+            swift_container_url % release,
+            release,
+            arch,
+            srchash(package),
+            package,
+            row[1],
+        )
+        identifier = (
+            version,
+            triggers,
+        )  # Version + triggers uniquely identifies this result
+        show_retry = code != "pass" and identifier not in seen
+        all_proposed = (
+            additional_params is not None
+            and "all-proposed=1" in additional_params
+        )
+        results.append(
+            (
+                version,
+                triggers,
+                additional_params,
+                human_date(row[0]),
+                human_sec(int(row[3])),
+                user,
+                code,
+                url,
+                show_retry,
+                all_proposed,
+                row[7],
+            )
+        )
+    # get queued jobs
+    # Add running jobs if any
+    for package, running_hash in get_running_jobs().items():
+        for release, running in running_hash.items():
+            for arch, vals in running.items():
+                info_dict = vals[0]
+                if info_dict.get("requester", "") == user:
+                    results.insert(
+                        0,
+                        (
+                            "N/A",
+                            info_dict.get("triggers"),
+                            "N/A",
+                            human_date(info_dict.get("submit-time")),
+                            human_sec(int(vals[1])),
+                            user,
+                            "running",
+                            "",
+                            False,
+                            "",
+                            info_dict.get("uuid", "-"),
+                        )
+                    )
+
+    # Add queued jobs if any
+    (_, _, queues_info) = get_queues_info()
+    for _, queue in queues_info.items():
+        for release, queue_by_arch in queue.items():
+            for arch, queue_items in queue_by_arch.items():
+                requests = queue_items.get("requests", [])
+                for req in requests:
+                    req_info = json.loads(req.split("\n")[1])
+                    if req_info.get("requester", "") == user:
+                        results.insert(
+                            0,
+                            (
+                                "N/A",
+                                req_info.get("triggers"),
+                                "N/A",
+                                human_date(req_info.get("submit-time")),
+                                "N/A",
+                                user,
+                                "queued",
+                                "",
+                                False,
+                                "",
+                                req_info.get("uuid", ""),
+                            )
+                        )
+    # amend the below to use browse-user.html
+    # return render(
+    #     "browse-results.html",
+    #     package=package,
+    #     release=release,
+    #     arch=arch,
+    #     package_results=results,
+    #     title_suffix="- %s/%s/%s" % (package, release, arch),
+    # )
+                    
+
 # backwards-compatible path with debci that specifies the source hash
 @app.route("/packages/<_>/<package>/<release>/<arch>")
 @app.route("/packages/<package>/<release>/<arch>")

References