Put hosts with unloaded CPU microcode updates in reboot
CI / tests (Python 3.10) (pull_request) Successful in 40s
CI / tests (Python 3.11) (pull_request) Successful in 39s
CI / tests (Python 3.12) (pull_request) Successful in 38s
CI / tests (Python 3.13) (pull_request) Successful in 38s
CI / lint (pull_request) Failing after 3s

On bare metal, needrestart -b reports NEEDRESTART-UCSTA: 2 when the
installed intel-microcode/amd64-microcode is newer than what the CPU
loaded at boot, which only a reboot fixes. The agent dropped those
lines. It now reports needrestart_ucsta, _uccur and _ucexp, and the
server puts the host in reboot with both revisions. Livepatch doesn't
cover it. needrestart skips the check in VMs, so only physical hosts
(debian-homelab today) report it; the host page gets a "CPU microcode"
row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-11-01 15:25:57 -05:00
1 parent 4676942108
commit 8174f1df81
8 files changed
+79 -1

No files matched your search

+14
View File
@@ -136,6 +136,20 @@ class AgentReportTest(AgentCase):
self.assertEqual(r["services_need_restart"], ["nginx.service", "ssh.service"])
self.assertEqual(r["sessions_need_restart"], 1)
def test_needrestart_microcode(self):
self.write_needrestart("NEEDRESTART-KSTA: 1\nNEEDRESTART-UCSTA: 2\n"
"NEEDRESTART-UCCUR: 0x001e\nNEEDRESTART-UCEXP: 0x0020\n")
r = self.report()
self.assertEqual((r["needrestart_ucsta"], r["needrestart_uccur"], r["needrestart_ucexp"]),
(2, "0x001e", "0x0020"))
def test_needrestart_without_microcode_lines(self):
# Virtual machines: needrestart leaves the UC* lines out.
self.write_needrestart("NEEDRESTART-KSTA: 1\n")
r = self.report()
self.assertIsNone(r["needrestart_ucsta"])
self.assertIsNone(r["needrestart_uccur"])
def write_livepatch(self, text, age=60):
d = os.path.join(self.root, "run/kernelwatch")
os.makedirs(d, exist_ok=True)
+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_microcode_update_needs_a_reboot(self):
s = self.level(report(needrestart_ucsta=2, needrestart_uccur="0x001e", needrestart_ucexp="0x0020"))
self.assertEqual(s.level, "reboot")
self.assertEqual(s.reasons, ["CPU microcode update installed but not loaded (0x001e → 0x0020)"])
for ucsta in (0, 1, None):
with self.subTest(ucsta=ucsta):
self.assertEqual(self.level(report(needrestart_ucsta=ucsta)).level, "ok")
def test_livepatch_doesnt_cover_microcode(self):
s = evaluate(NOW - 60, livepatched(needrestart_ucsta=2), NOW, CFG)
self.assertEqual(s.level, "reboot")
self.assertIn("CPU microcode update installed but not loaded", s.reasons)
def test_held_kernel_package_is_a_problem(self):
s = self.level(report(held_packages=["linux-image-amd64"]))
self.assertEqual(s.level, "update")
+10
View File
@@ -239,6 +239,16 @@ class DashboardTest(ServerCase):
self.assertIn("noble-security: not in apt&#x27;s sources", body)
self.assertIn("apt has no noble-security repository", body)
def test_host_page_shows_microcode(self):
self.add_user("admin", "a-long-password")
token = self.add_host("web01")
self.post_report(token, {"kernel_running": "6.12.57+deb13-amd64", "apt_lists_age_seconds": 60,
"needrestart_ucsta": 2, "needrestart_uccur": "0x001e",
"needrestart_ucexp": "0x0020"})
_, headers, _ = self.login("admin", "a-long-password")
body = self.request("GET", "/host/web01", headers={"Cookie": headers["Set-Cookie"].split(";")[0]})[2]
self.assertIn("update needs a reboot (loaded 0x001e, installed 0x0020)", body)
def test_host_page_shows_helper_units(self):
self.add_user("admin", "a-long-password")
token = self.add_host("web01")