← Back to team overview

canonical-ubuntu-qa team mailing list archive

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

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:admin-page 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/456759
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:admin-page into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index f2dc00f..e97093d 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -370,6 +370,67 @@ def running():
     )
 
 
+@app.route("/admin")
+def admin():
+    try:
+        with open("/run/amqp-status-collector/running.json") as f:
+            # package -> runhash -> release -> arch -> (params, duration, logtail)
+            running_info = json.load(f)
+    except FileNotFoundError:
+        running_info = {}
+        return None
+    pruned_running_info = {}
+    for running_pkg, running_dict in running_info.items():
+        for skey, sval in running_dict.items():
+            for release, values in sval.items():
+                for arch, vals in values.items():
+                    duration = vals[1]
+                    test_id = get_test_id(release, arch, running_pkg)
+                    if test_id is None:
+                        continue
+                    counter = 0
+                    duration_sum = 0
+                    for row in db_con.execute(
+                        "SELECT run_id, version, triggers, "
+                        "duration, exitcode, requester FROM result "
+                        "WHERE test_id=? "
+                        "ORDER BY run_id DESC",
+                        (test_id,),
+                    ):
+                        duration_sum += int(row[3])
+                        counter += 1
+                    duration_avg = duration_sum / counter
+                    if (duration) > duration_avg * 5:
+                        if running_pkg not in pruned_running_info:
+                            pruned_running_info[running_pkg] = {}
+                        if skey not in pruned_running_info[running_pkg]:
+                            pruned_running_info[running_pkg][skey] = {}
+                        if (
+                            release
+                            not in pruned_running_info[running_pkg][skey]
+                        ):
+                            pruned_running_info[running_pkg][skey][
+                                release
+                            ] = {}
+                        if (
+                            arch
+                            not in pruned_running_info[running_pkg][skey][
+                                release
+                            ]
+                        ):
+                            pruned_running_info[running_pkg][skey][release][
+                                arch
+                            ] = []
+                        # Add the weird result!
+                        pruned_running_info[running_pkg][skey][release][
+                            arch
+                        ] = vals
+    return render(
+        "browse-admin.html",
+        running=pruned_running_info,
+    )
+
+
 @app.route("/queue_size.json")
 def queuesize_json():
     queue_info = get_queue_info()[2]
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-admin.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-admin.html
new file mode 100644
index 0000000..c3c0972
--- /dev/null
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-admin.html
@@ -0,0 +1,28 @@
+{% extends "browse-layout.html" %}
+{% block content %}
+  <h1 class="page-header">Admin</h1>
+  <p>Click on the package name to jump to the currently running tests of that package.</p>
+
+  <!-- Running tests -->
+  {% for p in running|sort %}
+  <h2 id="pkg-{{p}}"><a href="/packages/{{p}}">{{p}}</a></h2>
+    {% for runhash, relinfo in running[p].items() %}
+      {% for release, archinfo in relinfo.items() %}
+        {% for arch, (params, duration, logtail) in archinfo.items() %}
+          <table class="table-condensed">
+            <tr><th>Release:</th><td>{{release}}</td></tr>
+            <tr><th>Architecture:</th><td>{{arch}}</td></tr>
+            {% for param, v in params.items() %}
+            <tr><th>{{param|capitalize}}:</th><td>{{v}}</td></tr>
+            {% endfor %}
+            <tr><th>Running for:</th><td>{{duration//3600 }}h {{duration % 3600//60}}m {{duration % 60}}s</td></tr>
+         </table>
+        <pre>
+{{logtail}}
+        </pre>
+        {% endfor %}
+      {% endfor %}
+    {% endfor %}
+  {% endfor %}
+
+{% endblock %}
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
index 9188c81..0f90de3 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
@@ -33,6 +33,7 @@
               <li><a href="https://wiki.ubuntu.com/ProposedMigration#autopkgtests";>Documentation</a></li>
               <li><a href="https://discourse.ubuntu.com/t/autopkgtest-service/34490";>Service Status</a></li>
               <li><a href="https://autopkgtest-cloud.readthedocs.io/";>Docs for admins</a></li>
+              <li><a href="{{base_url}}admin">Admin</a></li>
             </ul>
           </div><!--/.nav-collapse -->
         </div>

Follow ups