Flag hosts whose OS release no longer gets security updates
CI / tests (Python 3.10) (pull_request) Successful in 30s
CI / tests (Python 3.11) (pull_request) Successful in 30s
CI / tests (Python 3.12) (pull_request) Successful in 28s
CI / tests (Python 3.13) (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3s

Past its end of support a release gets no more security updates, so apt
offers nothing and the host showed ok indefinitely. The server now has a
table of when free security support ends for each release the agent
installs on (support.py): Debian's LTS end, and Ubuntu's end of standard
support plus end of ESM. Dates from Debian LTS and Ubuntu's release cycle
via endoflife.date; a test checks the table covers every release
agent/install.sh accepts.

The agent reports whether Ubuntu Pro is attached and esm-infra's status,
read from the pro client's world-readable status.json. A host past its
date goes to update; within os_eol_warn_days (default 90) of it, the row
gets a note. An Ubuntu host with ESM enabled isn't warned when standard
support ends, only before ESM does. The host page shows the dates.
Agent 0.7.0; older agents don't report ESM and count as having none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-31 19:50:44 -04:00
1 parent 5a11d31e66
commit bc46c55298
15 files changed
+348 -7

No files matched your search

+40
View File
@@ -173,9 +173,49 @@ class AgentReportTest(AgentCase):
f.write("ii \tcurl\nrc \told-pkg\n")
self.assertEqual(self.report()["dpkg_unfinished_packages"], [])
def write_pro_status(self, text):
d = os.path.join(self.root, "var/lib/ubuntu-advantage")
os.makedirs(d, exist_ok=True)
with open(os.path.join(d, "status.json"), "w") as f:
f.write(text)
def test_ubuntu_pro_attached_with_esm(self):
self.write_pro_status(json.dumps({"attached": True, "services": [
{"name": "esm-apps", "status": "enabled"}, {"name": "esm-infra", "status": "enabled"},
{"name": "livepatch", "status": "enabled"}]}))
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (True, "enabled"))
def test_ubuntu_pro_attached_esm_disabled(self):
self.write_pro_status(json.dumps({"attached": True, "services": [
{"name": "esm-infra", "status": "disabled"}]}))
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (True, "disabled"))
def test_ubuntu_pro_not_attached(self):
# Unattached, the cache lists services as available, which isn't the same as on.
self.write_pro_status(json.dumps({"attached": False, "services": [
{"name": "esm-infra", "available": "yes", "status": "enabled"}]}))
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (False, None))
def test_no_pro_client_or_unreadable_status(self):
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (None, None))
self.write_pro_status("{not json")
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (None, None))
def test_odd_esm_status_is_dropped(self):
self.write_pro_status(json.dumps({"attached": True, "services": [
{"name": "esm-infra", "status": "en abled\" x"}]}))
r = self.report()
self.assertEqual((r["ubuntu_pro_attached"], r["ubuntu_esm_infra"]), (True, None))
def test_every_reported_field_is_accepted_by_the_server(self):
from kernelwatch.report import FIELDS
self.write_livepatch("LIVEPATCH-STATE: applied\nLIVEPATCH-FIXES: 2\n")
self.write_pro_status('{"attached": true, "services": [{"name": "esm-infra", "status": "enabled"}]}')
self.assertEqual(sorted(set(self.report()) - set(FIELDS)), [])
def write_conf(self, text):
+8
View File
@@ -100,6 +100,14 @@ class ConfigTest(unittest.TestCase):
with self.subTest(bad=bad), self.assertRaises(SystemExit):
config.load(self.write(tmp, f"boot_min_free_mb = {bad}\n"))
def test_os_eol_warn_days_validated(self):
with tempdir() as tmp:
self.assertEqual(config.Config().os_eol_warn_days, 90)
self.assertEqual(config.load(self.write(tmp, "os_eol_warn_days = 0\n")).os_eol_warn_days, 0)
for bad in ("-1", "1.5"):
with self.subTest(bad=bad), self.assertRaises(SystemExit):
config.load(self.write(tmp, f"os_eol_warn_days = {bad}\n"))
def test_fallback_parser_matches_tomllib(self):
"""Python 3.10 has no tomllib; the fallback must read the same configs."""
if config.tomllib is None:
+13
View File
@@ -339,6 +339,19 @@ class EvaluateTest(unittest.TestCase):
self.assertEqual(self.level(report(dpkg_unfinished_packages=[])).level, "ok")
self.assertEqual(self.level(report(dpkg_unfinished_packages=None)).level, "ok")
def test_os_past_end_of_support(self):
s = self.level(report(os_id="debian", os_version_id="11"))
self.assertEqual(s.level, "update")
self.assertIn("Debian 11 security support ended 2026-08-31", s.reasons[0])
def test_os_end_of_support_warning_is_a_note(self):
# NOW is 2027-01-15; Ubuntu 22.04 standard support ends 2027-06-01.
rep = report(os_id="ubuntu", os_version_id="22.04")
self.assertEqual(evaluate(NOW, rep, NOW, Config(os_eol_warn_days=200)).level, "ok")
self.assertIn("standard support ends 2027-06-01",
evaluate(NOW, rep, NOW, Config(os_eol_warn_days=200)).reasons[0])
self.assertEqual(self.level(rep).reasons, [], "outside the default 90 days")
def test_reboot_outranks_update(self):
s = self.level(report(needrestart_ksta=3, security_count=2))
self.assertEqual(s.level, "reboot")
+108
View File
@@ -0,0 +1,108 @@
"""OS end-of-support: the release table and what it says about a host."""
import os
import re
import unittest
from datetime import date
from helpers import REPO
from kernelwatch import support
def host(os_id, version, **kw):
return {"os_id": os_id, "os_version_id": version, **kw}
def check(rep, today, warn_days=90):
return support.check(rep, date.fromisoformat(today), warn_days)
class ReleaseTableTest(unittest.TestCase):
def test_every_release_the_agent_installs_on_is_listed(self):
with open(os.path.join(REPO, "agent", "install.sh")) as f:
accepted = re.search(r'^case "\$ID:\$VERSION_ID" in\n(.*?)\)', f.read(), re.M | re.S).group(1)
releases = [tuple(r.strip().split(":")) for r in accepted.split("|")]
self.assertGreaterEqual(len(releases), 5)
for key in releases:
self.assertIn(key, support.RELEASES)
def test_dates_are_consistent(self):
for key, rel in support.RELEASES.items():
with self.subTest(key=key):
if key[0] == "ubuntu":
self.assertIsNotNone(rel.esm_end)
self.assertLess(rel.end, rel.esm_end)
else:
self.assertIsNone(rel.esm_end)
class DebianTest(unittest.TestCase):
def test_supported(self):
self.assertIsNone(check(host("debian", "12"), "2026-10-31"))
def test_warning_before_the_end(self):
self.assertEqual(check(host("debian", "12"), "2028-05-01"),
(False, "Debian 12 security support ends 2028-06-30 (in 60 days); plan the upgrade"))
self.assertEqual(check(host("debian", "12"), "2028-06-30"),
(False, "Debian 12 security support ends 2028-06-30 (in 0 days); plan the upgrade"))
def test_warning_disabled(self):
self.assertIsNone(check(host("debian", "12"), "2028-05-01", warn_days=0))
def test_ended(self):
self.assertEqual(check(host("debian", "11"), "2026-10-31"),
(True, "Debian 11 security support ended 2026-08-31; upgrade the release"))
self.assertEqual(check(host("debian", "11"), "2026-10-31", warn_days=0)[0], True,
"the warning setting never hides an ended release")
class UbuntuTest(unittest.TestCase):
def test_supported(self):
self.assertIsNone(check(host("ubuntu", "24.04"), "2026-10-31"))
self.assertIsNone(check(host("ubuntu", "22.04"), "2026-10-31"))
def test_standard_support_ending_without_esm(self):
why = ("Ubuntu 22.04 standard support ends 2027-06-01 (in 31 days); "
"enable ESM with Ubuntu Pro or plan the upgrade")
self.assertEqual(check(host("ubuntu", "22.04"), "2027-05-01"), (False, why))
self.assertEqual(check(host("ubuntu", "22.04", ubuntu_esm_infra="disabled"), "2027-05-01"), (False, why))
def test_standard_support_ending_with_esm_is_fine(self):
self.assertIsNone(check(host("ubuntu", "22.04", ubuntu_esm_infra="enabled"), "2027-05-01"))
def test_standard_support_ended_without_esm(self):
self.assertEqual(check(host("ubuntu", "20.04", ubuntu_pro_attached=False), "2026-10-31"),
(True, "Ubuntu 20.04 standard support ended 2025-05-31 and ESM isn't enabled; "
"enable it with Ubuntu Pro or upgrade the release"))
def test_standard_support_ended_with_esm(self):
self.assertIsNone(check(host("ubuntu", "20.04", ubuntu_esm_infra="enabled"), "2026-10-31"))
self.assertEqual(check(host("ubuntu", "20.04", ubuntu_esm_infra="enabled"), "2030-03-01"),
(False, "Ubuntu 20.04 ESM ends 2030-04-23 (in 53 days); plan the upgrade"))
def test_esm_ended(self):
self.assertEqual(check(host("ubuntu", "20.04", ubuntu_esm_infra="enabled"), "2030-04-24"),
(True, "Ubuntu 20.04 ESM ended 2030-04-23; upgrade the release"))
class OtherHostsTest(unittest.TestCase):
def test_unknown_release_is_noted(self):
self.assertEqual(check(host("ubuntu", "25.10"), "2026-10-31"),
(False, "no end-of-support date known for ubuntu 25.10"))
def test_nothing_said_without_a_release(self):
self.assertIsNone(check({}, "2026-10-31"), "agent reported no os fields")
self.assertIsNone(check(host("debian", ""), "2026-10-31"), "Debian testing/sid")
self.assertIsNone(check(host("fedora", "41"), "2026-10-31"))
def test_summary(self):
self.assertEqual(support.summary(host("debian", "13")), "until 2030-06-30")
self.assertEqual(support.summary(host("ubuntu", "24.04", ubuntu_esm_infra="enabled")),
"standard until 2029-05-31, ESM until 2034-04-25 (esm-infra: enabled)")
self.assertEqual(support.summary(host("ubuntu", "24.04")),
"standard until 2029-05-31, ESM until 2034-04-25 (esm-infra: unknown)")
self.assertIsNone(support.summary(host("ubuntu", "25.10")))
if __name__ == "__main__":
unittest.main()
+10
View File
@@ -197,6 +197,16 @@ class DashboardTest(ServerCase):
self.assertIn("<code>linux-image-6.8.0-138-generic</code>", body)
self.assertIn("/boot has 95 MB free, 81% used; the next kernel may not fit", body)
def test_host_page_shows_os_support(self):
self.add_user("admin", "a-long-password")
token = self.add_host("web01")
self.post_report(token, {"kernel_running": "6.8.0-136-generic", "apt_lists_age_seconds": 60,
"os_id": "ubuntu", "os_version_id": "24.04", "ubuntu_pro_attached": True,
"ubuntu_esm_infra": "enabled"})
_, headers, _ = self.login("admin", "a-long-password")
body = self.request("GET", "/host/web01", headers={"Cookie": headers["Set-Cookie"].split(";")[0]})[2]
self.assertIn("standard until 2029-05-31, ESM until 2034-04-25 (esm-infra: enabled)", body)
def test_login_dashboard_logout(self):
self.add_user("admin", "a-long-password")
token = self.add_host("web01")