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

Proposed by Tim Andersson
Status: Work in progress
Proposed branch: ~andersson123/autopkgtest-cloud:service-message
Merge into: autopkgtest-cloud:master
Diff against target: 97 lines (+34/-0)
5 files modified
charms/focal/autopkgtest-web/config.yaml (+5/-0)
charms/focal/autopkgtest-web/reactive/autopkgtest_web.py (+10/-0)
charms/focal/autopkgtest-web/webcontrol/browse.cgi (+7/-0)
charms/focal/autopkgtest-web/webcontrol/static/style.css (+7/-0)
charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html (+5/-0)
Reviewer Review Type Date Requested Status
Canonical's Ubuntu QA Pending
Review via email: mp+464028@code.launchpad.net
To post a comment you must log in.

Unmerged commits

b0c139c... by Tim Andersson

feat: web: add the possibility of displaying a service message with juju config

This commit adds the possibility of displaying a short service message
at the top of all pages.

This is useful in situations where there's an issue/recent bug that'll
affect all users.

To add a service message, use:

juju config autopkgtest-web important-service-message "my message".

The message is displayed with black text on a yellow background.

Displaying the service message requires a restart to apache2.

Failed
[FAILED] pre_commit:0 (build)
[WAITING] unit_tests:0 (build)
[WAITING] build_charms:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/charms/focal/autopkgtest-web/config.yaml b/charms/focal/autopkgtest-web/config.yaml
index a60637a..09f71ae 100644
--- a/charms/focal/autopkgtest-web/config.yaml
+++ b/charms/focal/autopkgtest-web/config.yaml
@@ -57,3 +57,8 @@ options:
57 type: string57 type: string
58 default: ~58 default: ~
59 description: "List of teams that are allowed to request autopkgtest tests."59 description: "List of teams that are allowed to request autopkgtest tests."
60 important-service-message:
61 type: string
62 default: ""
63 description: "Short, one-sentence message regarding \
64 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 4386e50..37e22df 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/")
31for parent in reversed(CONFIG_DIR.parents):31for parent in reversed(CONFIG_DIR.parents):
32 parent.mkdir(mode=0o770, exist_ok=True)32 parent.mkdir(mode=0o770, exist_ok=True)
33ALLOWED_REQUESTOR_TEAMS_PATH = CONFIG_DIR / "allowed-requestor-teams"33ALLOWED_REQUESTOR_TEAMS_PATH = CONFIG_DIR / "allowed-requestor-teams"
34SERVICE_MESSAGE_PATH = CONFIG_DIR / "important-service-message"
3435
35PUBLIC_SWIFT_CREDS_PATH = os.path.expanduser("~ubuntu/public-swift-creds")36PUBLIC_SWIFT_CREDS_PATH = os.path.expanduser("~ubuntu/public-swift-creds")
3637
@@ -166,6 +167,15 @@ def initially_configure_website(website):
166167
167168
168@when_any(169@when_any(
170 "config.changed.important-service-message",
171 "config.set.important-service-message",
172)
173def write_service_message():
174 service_message = config().get("important-service-message")
175 SERVICE_MESSAGE_PATH.write_text(service_message)
176
177
178@when_any(
169 "config.changed.hostname",179 "config.changed.hostname",
170 "config.changed.https-proxy",180 "config.changed.https-proxy",
171 "config.changed.no-proxy",181 "config.changed.no-proxy",
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index 309fb82..a6e8c0a 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -4,6 +4,7 @@
44
5import json5import json
6import os6import os
7import pathlib
7import re8import re
8import sqlite39import sqlite3
9from collections import OrderedDict10from collections import OrderedDict
@@ -31,6 +32,12 @@ app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 60
3132
32app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)33app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
3334
35SERVICE_MESSAGE_PATH = pathlib.Path(
36 "/home/ubuntu/.config/autopkgtest-web/important-service-message"
37)
38if SERVICE_MESSAGE_PATH.is_file():
39 app.config["important-service-message"] = SERVICE_MESSAGE_PATH.read_text()
40
34secret_path = os.path.join(PATH, "secret_key")41secret_path = os.path.join(PATH, "secret_key")
35setup_key(app, secret_path)42setup_key(app, secret_path)
3643
diff --git a/charms/focal/autopkgtest-web/webcontrol/static/style.css b/charms/focal/autopkgtest-web/webcontrol/static/style.css
index eb8fc11..1ee18a2 100644
--- a/charms/focal/autopkgtest-web/webcontrol/static/style.css
+++ b/charms/focal/autopkgtest-web/webcontrol/static/style.css
@@ -129,3 +129,10 @@ th.sticky-table-headers {
129.unfinished {129.unfinished {
130 color: grey;130 color: grey;
131}131}
132
133.service {
134 margin-left: 350px;
135 width: 54%;
136 background: yellow;
137 text-align: center;
138}
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
index e4cfce6..82f9be5 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
@@ -42,6 +42,11 @@
42 </div>42 </div>
43 </div>43 </div>
4444
45 {% if config.get("important-service-message") %}
46 <div class="service">
47 <p>PSA: {{ config.get("important-service-message") }}</p>
48 </div>
49 {% endif %}
4550
46<div class="container">51<div class="container">
47{% block content %}{% endblock %}52{% block content %}{% endblock %}

Subscribers

People subscribed via source and target branches