← Back to team overview

canonical-ubuntu-qa team mailing list archive

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

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:add_info_to_webpage 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/449089
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:add_info_to_webpage into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/publish-version-info b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/publish-version-info
new file mode 100644
index 0000000..814c1cf
--- /dev/null
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/publish-version-info
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+
+import re
+import requests
+
+
+chlog = ""
+with open("/home/ubuntu/autopkgtest/debian/changelog", "r") as f:
+    chlog = f.read()
+
+version = re.sub('[^0-9.]','',chlog.splitlines()[0])
+
+data = {
+    "autopkgtest-version": str(version)
+}
+
+url="https://autopkgtest.staging.ubuntu.com/cloud-worker-versioning";
+req = requests.post(url, json=data)
diff --git a/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.service b/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.service
new file mode 100644
index 0000000..1a5b488
--- /dev/null
+++ b/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=publish autopkgtest version info to webui
+Wants=network-online.target
+After=network-online.target
+
+[Service]
+Type=oneshot
+User=ubuntu
+WorkingDirectory=~
+TimeoutStartSec=1h
+ExecStart=/home/ubuntu/autopkgtest-cloud/tools/publish-version-info
diff --git a/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.timer b/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.timer
new file mode 100644
index 0000000..313a758
--- /dev/null
+++ b/charms/focal/autopkgtest-cloud-worker/units/publish-version-info.timer
@@ -0,0 +1,8 @@
+[Unit]
+Description=Timer to publish autopkgtest version to webui
+
+[Timer]
+OnBootSec=1h
+
+[Install]
+WantedBy=autopkgtest.target
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index d7bc343..da25a14 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -24,6 +24,7 @@ ALL_UBUNTU_RELEASES = UDI.all
 SUPPORTED_UBUNTU_RELEASES = sorted(
     set(UDI.supported() + UDI.supported_esm()), key=ALL_UBUNTU_RELEASES.index
 )
+CLOUD_WORKER_VERSION = {}
 
 
 def init_config():
@@ -398,6 +399,29 @@ def queues_json():
     )
 
 
+@app.route("/versions.json")
+def get_version_info():
+    version_info = {}
+    files = [
+        ("/home/ubuntu/webcontrol/breadcrumb.json", "charm-git-info"),
+        #     "/run/autopkgtest_webcontrol/cloud-worker-versions",
+        #     "cloud-worker-info",
+        # ),
+        # (
+    ]
+    # Charm revision I've got no idea how to do lol
+    for file, key in files:
+        if os.path.isfile(file):
+            with open(file, "r") as f:
+                version_info[key] = json.load(f)
+        else:
+            version_info[key] = {}
+    version_info["cloud-worker-info"] = CLOUD_WORKER_VERSION
+    return flask.Response(
+        json.dumps(version_info, indent=2), mimetype="application.json"
+    )
+
+
 @app.route("/testlist")
 def testlist():
     # geneate index → [(package, version)] map
@@ -469,6 +493,12 @@ def statistics():
     )
 
 
+@app.route("/cloud-worker-versioning", methods=["POST"])
+def write_cloud_worker_versioning():
+    global CLOUD_WORKER_VERSION
+    CLOUD_WORKER_VERSION = flask.request.json
+
+
 if __name__ == "__main__":
     app.config["DEBUG"] = True
     init_config()
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
index fe51858..3ceacd5 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
@@ -40,6 +40,7 @@
             <li><a href="{{base_url}}static/autopkgtest.db">SQLite database with results</a></li>
             <li><a href="{{base_url}}static/running.json">Currently running tests in JSON format</a></li>
             <li><a href="{{base_url}}queues.json">Queued tests in JSON format</a></li>
+            <li><a href="{{base_url}}versions.json">Version info for the infrastructure</a></li>
           </ul>
         </div>
       </div>