Collect Ubuntu Livepatch status in the agent
CI / tests (Python 3.10) (pull_request) Successful in 22s
CI / tests (Python 3.11) (pull_request) Successful in 22s
CI / tests (Python 3.12) (pull_request) Successful in 21s
CI / tests (Python 3.13) (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 2s
CI / tests (Python 3.10) (pull_request) Successful in 22s
CI / tests (Python 3.11) (pull_request) Successful in 22s
CI / tests (Python 3.12) (pull_request) Successful in 21s
CI / tests (Python 3.13) (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 2s
kernelwatch-livepatch.service runs canonical-livepatch as root with no network and a read-only filesystem, and a small python3 helper keeps the running kernel's state, check state, support, end-of-support date and fix count in /run/kernelwatch/livepatch. The agent (0.4.0) reads that file the way it reads needrestart's and never runs the snap itself. NoNewPrivileges=yes can't be used: snap-confine fails under it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fa86de11f
commit
b59336d7e2
11 files changed
+273
-8
No files matched your search
@@ -125,6 +125,46 @@ class AgentReportTest(AgentCase):
|
||||
self.assertEqual(r["services_need_restart"], ["nginx.service", "ssh.service"])
|
||||
self.assertEqual(r["sessions_need_restart"], 1)
|
||||
|
||||
def write_livepatch(self, text, age=60):
|
||||
d = os.path.join(self.root, "run/kernelwatch")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
path = os.path.join(d, "livepatch")
|
||||
with open(path, "w") as f:
|
||||
f.write(text)
|
||||
t = time.time() - age
|
||||
os.utime(path, (t, t))
|
||||
|
||||
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.assertEqual(sorted(set(self.report()) - set(FIELDS)), [])
|
||||
|
||||
def test_no_livepatch_file_reports_nulls(self):
|
||||
r = self.report()
|
||||
for key in ("state", "check_state", "supported", "upgrade_required", "fix_count"):
|
||||
self.assertIsNone(r["livepatch_" + key])
|
||||
|
||||
def test_livepatch_results(self):
|
||||
self.write_livepatch("LIVEPATCH-STATE: applied\nLIVEPATCH-CHECK: checked\n"
|
||||
"LIVEPATCH-SUPPORTED: supported\nLIVEPATCH-UPGRADE-REQUIRED: 2027-09-07\n"
|
||||
"LIVEPATCH-FIXES: 2\n")
|
||||
r = self.report()
|
||||
self.assertEqual((r["livepatch_state"], r["livepatch_check_state"], r["livepatch_supported"]),
|
||||
("applied", "checked", "supported"))
|
||||
self.assertEqual((r["livepatch_upgrade_required"], r["livepatch_fix_count"]), ("2027-09-07", 2))
|
||||
|
||||
def test_stale_livepatch_results_ignored(self):
|
||||
self.write_livepatch("LIVEPATCH-STATE: applied\nLIVEPATCH-FIXES: 2\n", age=3 * 3600)
|
||||
r = self.report()
|
||||
self.assertIsNone(r["livepatch_state"])
|
||||
self.assertIsNone(r["livepatch_fix_count"])
|
||||
|
||||
def test_agent_never_runs_livepatch_itself(self):
|
||||
marker = os.path.join(self.tmp, "livepatch-ran")
|
||||
stub(self.bin, "canonical-livepatch", f"touch {marker}\n")
|
||||
self.report()
|
||||
self.assertFalse(os.path.exists(marker))
|
||||
|
||||
def test_needrestart_nothing_to_restart(self):
|
||||
self.write_needrestart("NEEDRESTART-VER: 3.6\nNEEDRESTART-KSTA: 1\n")
|
||||
r = self.report()
|
||||
|
||||
Reference in new issue
Block a user