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

Proposed by Tim Andersson
Status: Needs review
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
1diff --git a/charms/focal/autopkgtest-web/config.yaml b/charms/focal/autopkgtest-web/config.yaml
2index a60637a..09f71ae 100644
3--- a/charms/focal/autopkgtest-web/config.yaml
4+++ b/charms/focal/autopkgtest-web/config.yaml
5@@ -57,3 +57,8 @@ options:
6 type: string
7 default: ~
8 description: "List of teams that are allowed to request autopkgtest tests."
9+ important-service-message:
10+ type: string
11+ default: ""
12+ description: "Short, one-sentence message regarding \
13+ autopkgtest.ubuntu.com's most important service update."
14diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
15index 4386e50..37e22df 100644
16--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
17+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
18@@ -31,6 +31,7 @@ CONFIG_DIR = pathlib.Path("/home/ubuntu/.config/autopkgtest-web/")
19 for parent in reversed(CONFIG_DIR.parents):
20 parent.mkdir(mode=0o770, exist_ok=True)
21 ALLOWED_REQUESTOR_TEAMS_PATH = CONFIG_DIR / "allowed-requestor-teams"
22+SERVICE_MESSAGE_PATH = CONFIG_DIR / "important-service-message"
23
24 PUBLIC_SWIFT_CREDS_PATH = os.path.expanduser("~ubuntu/public-swift-creds")
25
26@@ -166,6 +167,15 @@ def initially_configure_website(website):
27
28
29 @when_any(
30+ "config.changed.important-service-message",
31+ "config.set.important-service-message",
32+)
33+def write_service_message():
34+ service_message = config().get("important-service-message")
35+ SERVICE_MESSAGE_PATH.write_text(service_message)
36+
37+
38+@when_any(
39 "config.changed.hostname",
40 "config.changed.https-proxy",
41 "config.changed.no-proxy",
42diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
43index 309fb82..a6e8c0a 100755
44--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
45+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
46@@ -4,6 +4,7 @@
47
48 import json
49 import os
50+import pathlib
51 import re
52 import sqlite3
53 from collections import OrderedDict
54@@ -31,6 +32,12 @@ app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 60
55
56 app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
57
58+SERVICE_MESSAGE_PATH = pathlib.Path(
59+ "/home/ubuntu/.config/autopkgtest-web/important-service-message"
60+)
61+if SERVICE_MESSAGE_PATH.is_file():
62+ app.config["important-service-message"] = SERVICE_MESSAGE_PATH.read_text()
63+
64 secret_path = os.path.join(PATH, "secret_key")
65 setup_key(app, secret_path)
66
67diff --git a/charms/focal/autopkgtest-web/webcontrol/static/style.css b/charms/focal/autopkgtest-web/webcontrol/static/style.css
68index eb8fc11..1ee18a2 100644
69--- a/charms/focal/autopkgtest-web/webcontrol/static/style.css
70+++ b/charms/focal/autopkgtest-web/webcontrol/static/style.css
71@@ -129,3 +129,10 @@ th.sticky-table-headers {
72 .unfinished {
73 color: grey;
74 }
75+
76+.service {
77+ margin-left: 350px;
78+ width: 54%;
79+ background: yellow;
80+ text-align: center;
81+}
82diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
83index e4cfce6..82f9be5 100644
84--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
85+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-layout.html
86@@ -42,6 +42,11 @@
87 </div>
88 </div>
89
90+ {% if config.get("important-service-message") %}
91+ <div class="service">
92+ <p>PSA: {{ config.get("important-service-message") }}</p>
93+ </div>
94+ {% endif %}
95
96 <div class="container">
97 {% block content %}{% endblock %}

Subscribers

People subscribed via source and target branches