Flag a /boot too full for the next kernel and packages dpkg left unfinished
CI / tests (Python 3.10) (pull_request) Successful in 29s
CI / tests (Python 3.11) (pull_request) Successful in 30s
CI / tests (Python 3.12) (pull_request) Successful in 29s
CI / tests (Python 3.13) (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 4s

A full /boot makes the next kernel's postinst fail: apt is left half-done
and the host quietly stays on its old kernel, which kernelwatch only
noticed indirectly, if at all. The agent now reports the size and free
space of the filesystem holding /boot (df) and the packages dpkg didn't
finish installing (half-installed, unpacked, half-configured, trigger
states or reinst-required, as dpkg --audit counts them).

The server puts a host in update when /boot has less than
boot_min_free_mb (default 200, 0 disables) free, or any package is
unfinished, with the fix in the reason ("run dpkg --configure -a"). The
host page shows both. Agents before 0.6.0 send neither field and are
judged as before. Agent 0.6.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-31 18:54:47 -04:00
1 parent 3e2f550414
commit 70272efed5
13 files changed
+173 -5

No files matched your search

+40 -1
View File
@@ -59,13 +59,20 @@ class AgentCase(unittest.TestCase):
stub(self.bin, "uname", 'case "$1" in -r) echo 6.12.48+deb13-amd64;; '
'-v) echo "#1 SMP PREEMPT_DYNAMIC Debian 6.12.48-1";; esac\n')
stub(self.bin, "hostname", "echo web01.example\n")
stub(self.bin, "dpkg-query", 'case "$*" in *Version*) echo "ii 6.12.48-2";; *) cat <<\'X\'\n'
# The full-database query (unfinished packages) prints $KERNELWATCH_ROOT/dpkg-all.
stub(self.bin, "dpkg-query", 'case "$*" in *binary:Package*) cat "$KERNELWATCH_ROOT/dpkg-all" 2>/dev/null;; '
'*Version*) echo "ii 6.12.48-2";; *) cat <<\'X\'\n'
f"{DPKG_DEBIAN}X\n;; esac\n")
self.stub_df("/dev/sda1 999320 187364 743144 21% /boot\n")
stub(self.bin, "apt-get", f"cat <<'X'\n{APT_SIM_DEBIAN}X\n")
def tearDown(self):
self._tmp.cleanup()
def stub_df(self, line, rc=0):
stub(self.bin, "df", "echo 'Filesystem 1024-blocks Used Available Capacity Mounted on'\n"
f"cat <<'X'\n{line}X\nexit {rc}\n")
def run_agent(self, *args, env=None):
full_env = {
"PATH": f"{self.bin}:{os.environ['PATH']}",
@@ -134,6 +141,38 @@ class AgentReportTest(AgentCase):
t = time.time() - age
os.utime(path, (t, t))
def test_boot_space(self):
r = self.report()
self.assertEqual((r["boot_size_kb"], r["boot_free_kb"]), (999320, 743144))
def test_boot_space_unknown_when_df_fails(self):
self.stub_df("", rc=1)
r = self.report()
self.assertIsNone(r["boot_size_kb"])
self.assertIsNone(r["boot_free_kb"])
def test_boot_space_unknown_when_df_prints_garbage(self):
self.stub_df("/dev/sda1 - - - - /boot\n")
self.assertIsNone(self.report()["boot_free_kb"])
def test_unfinished_packages(self):
with open(os.path.join(self.root, "dpkg-all"), "w") as f:
f.write("ii \tcurl\n"
"iF \tlinux-image-6.12.60+deb13-amd64\n"
"iU \tlinux-headers-6.12.60+deb13-amd64\n"
"iHR\tlibfoo1:amd64\n"
"iiR\tlibbar2\n"
"it \tman-db\n"
"rc \told-pkg\n")
self.assertEqual(self.report()["dpkg_unfinished_packages"], [
"libbar2", "libfoo1:amd64", "linux-headers-6.12.60+deb13-amd64",
"linux-image-6.12.60+deb13-amd64", "man-db"])
def test_no_unfinished_packages(self):
with open(os.path.join(self.root, "dpkg-all"), "w") as f:
f.write("ii \tcurl\nrc \told-pkg\n")
self.assertEqual(self.report()["dpkg_unfinished_packages"], [])
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")