launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #31201
[Merge] ~lgp171188/lp-archive:add-root-and-healthcheck-urls-to-esm-layouts into lp-archive:main
Guruprasad has proposed merging ~lgp171188/lp-archive:add-root-and-healthcheck-urls-to-esm-layouts into lp-archive:main.
Commit message:
Add missing healthcheck routes to the ESM layouts
And also serve an appropriate message on the root URL of the ESM
snapshot domains.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lgp171188/lp-archive/+git/lp-archive/+merge/468793
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/lp-archive:add-root-and-healthcheck-urls-to-esm-layouts into lp-archive:main.
diff --git a/lp_archive/__init__.py b/lp_archive/__init__.py
index c1ecd4d..fff389f 100644
--- a/lp_archive/__init__.py
+++ b/lp_archive/__init__.py
@@ -43,7 +43,10 @@ def create_app(test_config: dict[str, Any] | None = None) -> Flask:
talisker.flask.register(app)
# Common Talisker service health check.
- for layout in app.config.get("LAYOUTS", []):
+ all_layouts = app.config.get("LAYOUTS", []) + app.config.get(
+ "ESM_LAYOUTS", []
+ )
+ for layout in all_layouts:
host = layout["host"]
app.add_url_rule(
"/_status/check",
diff --git a/lp_archive/root.py b/lp_archive/root.py
index e175759..5902cfe 100644
--- a/lp_archive/root.py
+++ b/lp_archive/root.py
@@ -10,6 +10,18 @@ def root() -> tuple[str, dict[str, str]]:
return render_template("index.html"), {"Content-Type": "text/html"}
+def esm_root() -> tuple[str, dict[str, str]]:
+ # Let us have this placeholder text till we have the
+ # proper documentation for ESM snapshots ready to be
+ # added here.
+ return "Launchpad ESM archive snapshot service.\n", {
+ "Content-Type": "text/plain"
+ }
+
+
def init_app(app: Flask) -> None:
for layout in app.config.get("LAYOUTS", []):
app.add_url_rule("/", host=layout["host"], view_func=root)
+
+ for layout in app.config.get("ESM_LAYOUTS", []):
+ app.add_url_rule("/", host=layout["host"], view_func=esm_root)
diff --git a/tests/test_root.py b/tests/test_root.py
index 13c6c32..cf9bc53 100644
--- a/tests/test_root.py
+++ b/tests/test_root.py
@@ -1,5 +1,6 @@
# Copyright 2022 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+import pytest
def test_root(client):
@@ -15,3 +16,17 @@ def test_health_check(client):
"/_status/check", headers=[("Host", "snapshot.ubuntu.test")]
)
assert response.get_json() == {"ok": True}
+
+
+@pytest.mark.parametrize(
+ "esm_hostname",
+ [
+ "snapshot.esm-infra-security.test",
+ "snapshot.esm-apps-security.test",
+ "snapshot.esm-infra-updates.test",
+ ],
+)
+def test_root_esm(esm_hostname, client):
+ response = client.get("/", headers=[("Host", esm_hostname)])
+ assert response.headers["Content-Type"] == "text/plain"
+ assert b"Launchpad ESM archive snapshot service." in response.data