← Back to team overview

canonical-ubuntu-qa team mailing list archive

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

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:service-message 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/464028
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:service-message into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/config.yaml b/charms/focal/autopkgtest-web/config.yaml
index a60637a..ede3e9a 100644
--- a/charms/focal/autopkgtest-web/config.yaml
+++ b/charms/focal/autopkgtest-web/config.yaml
@@ -57,3 +57,8 @@ options:
     type: string
     default: ~
     description: "List of teams that are allowed to request autopkgtest tests."
+  important-service-message:
+    type: string
+    default: ""
+    description: "Short, one-sentence message regarding autopkgtest.ubuntu.com's \
+                  most important service update."
diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
index a228a0f..4680ed0 100644
--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
@@ -31,6 +31,7 @@ CONFIG_DIR = pathlib.Path("/home/ubuntu/.config/autopkgtest-web/")
 for parent in reversed(CONFIG_DIR.parents):
     parent.mkdir(mode=0o770, exist_ok=True)
 ALLOWED_REQUESTOR_TEAMS_PATH = CONFIG_DIR / "allowed-requestor-teams"
+SERVICE_MESSAGE_PATH = CONFIG_DIR / "important-service-message"
 
 PUBLIC_SWIFT_CREDS_PATH = os.path.expanduser("~ubuntu/public-swift-creds")
 
@@ -149,6 +150,15 @@ def initially_configure_website(website):
 
 
 @when_any(
+    "config.changed.important-service-message",
+    "config.set.important-service-message",
+)
+def write_service_message():
+    service_message = config().get("important-service-message")
+    SERVICE_MESSAGE_PATH.write_text(service_message)
+
+
+@when_any(
     "config.changed.hostname",
     "config.changed.https-proxy",
     "config.changed.no-proxy",
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index 309fb82..418fae3 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -6,6 +6,7 @@ import json
 import os
 import re
 import sqlite3
+import pathlib
 from collections import OrderedDict
 from wsgiref.handlers import CGIHandler
 
@@ -31,6 +32,10 @@ app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 60
 
 app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
 
+SERVICE_MESSAGE_PATH = pathlib.Path("/home/ubuntu/.config/autopkgtest-web/important-service-message")
+if SERVICE_MESSAGE_PATH.is_file():
+    flask.session["important-service-message"] = SERVICE_MESSAGE_PATH.read_text()
+
 secret_path = os.path.join(PATH, "secret_key")
 setup_key(app, secret_path)
 
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
index e4cfce6..da23417 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
@@ -41,6 +41,10 @@
           </div><!--/.nav-collapse -->
         </div>
       </div>
+   
+    {% if session.get("important-service-message") %}
+      <p>{{ session.get("important-service-message") }}</p>
+    {% endif %}
 
 
 <div class="container">

References