Flag hosts without room on disk for their pending upgrades
CI / tests (Python 3.10) (pull_request) Successful in 43s
CI / tests (Python 3.11) (pull_request) Successful in 44s
CI / tests (Python 3.12) (pull_request) Successful in 43s
CI / tests (Python 3.13) (pull_request) Successful in 42s
CI / lint (pull_request) Successful in 3s
CI / tests (Python 3.10) (pull_request) Successful in 43s
CI / tests (Python 3.11) (pull_request) Successful in 44s
CI / tests (Python 3.12) (pull_request) Successful in 43s
CI / tests (Python 3.13) (pull_request) Successful in 42s
CI / lint (pull_request) Successful in 3s
A filesystem that fills up while apt downloads or dpkg unpacks leaves the upgrade half-done and apt broken, the same failure as a full /boot but on / or /var. Nothing caught it until the host's updates stopped. The agent (0.11.0) now works out what the pending upgrades need. A simulation doesn't print apt's "Need to get" or "additional disk space" lines, so it sums the package records from apt-cache show for each version the simulation would install: Size for each .deb not already in /var/cache/apt/archives, and the growth in Installed-Size over the installed versions (from dpkg-query). Removals aren't subtracted, so it errs high. It also reports free space and the mount point of the filesystems holding /var/cache/apt/archives and /usr. The server puts a host in update when the upgrades would leave less than upgrade_min_free_mb (default 100, 0 disables) on either filesystem. The download and the install both count when they're on the same one. With nothing pending there is nothing to check, so this doesn't turn into general disk monitoring. The host page gets a "Pending upgrades size" row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5be19f85d
commit
15b1f5be4f
13 files changed
+363
-7
No files matched your search
+52
-1
@@ -264,7 +264,8 @@ class EvaluateTest(unittest.TestCase):
|
||||
self.assertEqual(s.level, "ok")
|
||||
self.assertIn("agent 0.1.0 is older", s.reasons[0])
|
||||
self.assertEqual(self.level(report(agent_version=AGENT_VERSION)).reasons, [])
|
||||
self.assertEqual(self.level(report(agent_version="0.10.0")).reasons, [], "numeric compare")
|
||||
self.assertEqual(self.level(report(agent_version="0.100.0")).reasons, [],
|
||||
"numeric compare: lexically older than 0.11.0")
|
||||
|
||||
def test_server_knows_shipped_agent_version(self):
|
||||
with open(os.path.join(REPO, "agent", "kernelwatch-agent")) as f:
|
||||
@@ -326,6 +327,56 @@ class EvaluateTest(unittest.TestCase):
|
||||
self.assertEqual(evaluate(NOW, report(boot_free_kb=0), NOW, Config(boot_min_free_mb=0)).level,
|
||||
"ok", "0 disables")
|
||||
|
||||
@staticmethod
|
||||
def upgrade(download_mb, install_mb, archives=("/", 1000), usr=("/", 1000), **kw):
|
||||
fields = dict(upgrade_download_kb=download_mb * 1024, upgrade_install_kb=install_mb * 1024,
|
||||
apt_archives_mount=archives[0], apt_archives_free_kb=archives[1] * 1024,
|
||||
usr_mount=usr[0], usr_free_kb=usr[1] * 1024)
|
||||
return report(**{**fields, **kw})
|
||||
|
||||
def test_upgrade_space_shared_filesystem(self):
|
||||
# 300 + 650 needed on /, 1000 free: 50 MB left, under the 100 MB default.
|
||||
s = self.level(self.upgrade(300, 650))
|
||||
self.assertEqual(s.level, "update")
|
||||
self.assertEqual(s.reasons, ["pending upgrades need 950 MB on / (300 MB download + 650 MB installed), "
|
||||
"1000 MB free; they may fail part-way"])
|
||||
self.assertEqual(self.level(self.upgrade(300, 600)).level, "ok", "exactly 100 MB left")
|
||||
|
||||
def test_upgrade_space_separate_filesystems(self):
|
||||
s = self.level(self.upgrade(300, 650, archives=("/var", 350), usr=("/", 2000)))
|
||||
self.assertEqual(s.reasons, ["pending upgrades need 300 MB on /var (300 MB download), "
|
||||
"350 MB free; they may fail part-way"])
|
||||
s = self.level(self.upgrade(300, 1950, archives=("/var", 5000), usr=("/", 2000)))
|
||||
self.assertEqual(s.reasons, ["pending upgrades need 1950 MB on / (1950 MB installed), "
|
||||
"2000 MB free; they may fail part-way"])
|
||||
self.assertEqual(len(self.level(self.upgrade(300, 1950, archives=("/var", 350))).reasons), 2)
|
||||
|
||||
def test_upgrade_space_shrinking_install_counts_as_zero(self):
|
||||
self.assertEqual(self.level(self.upgrade(850, -500)).level, "ok")
|
||||
self.assertEqual(self.level(self.upgrade(950, -500)).level, "update",
|
||||
"the download still has to fit before the old files go")
|
||||
|
||||
def test_upgrade_space_ignores_full_disk_with_nothing_pending(self):
|
||||
self.assertEqual(self.level(self.upgrade(0, 0, archives=("/", 5), usr=("/", 5))).level, "ok")
|
||||
|
||||
def test_upgrade_space_rounds_need_up(self):
|
||||
rep = report(upgrade_download_kb=10, upgrade_install_kb=0, apt_archives_mount="/",
|
||||
apt_archives_free_kb=50 * 1024, usr_mount="/", usr_free_kb=50 * 1024)
|
||||
self.assertEqual(self.level(rep).reasons, ["pending upgrades need 1 MB on / (1 MB download), "
|
||||
"50 MB free; they may fail part-way"])
|
||||
|
||||
def test_upgrade_space_unknown_or_unreported(self):
|
||||
self.assertEqual(self.level(report()).level, "ok", "agents before 0.11.0 don't send it")
|
||||
self.assertEqual(self.level(self.upgrade(300, 650, upgrade_download_kb=None)).level, "ok")
|
||||
self.assertEqual(self.level(self.upgrade(300, 650, apt_archives_free_kb=None, usr_mount=None)).level,
|
||||
"ok", "df failed")
|
||||
|
||||
def test_upgrade_space_threshold_is_configurable(self):
|
||||
self.assertEqual(evaluate(NOW, self.upgrade(300, 650), NOW, Config(upgrade_min_free_mb=0)).level,
|
||||
"ok", "0 disables")
|
||||
self.assertEqual(evaluate(NOW, self.upgrade(300, 300), NOW, Config(upgrade_min_free_mb=500)).level,
|
||||
"update")
|
||||
|
||||
def test_unfinished_dpkg_packages(self):
|
||||
s = self.level(report(dpkg_unfinished_packages=["linux-image-6.12.60+deb13-amd64"]))
|
||||
self.assertEqual(s.level, "update")
|
||||
|
||||
Reference in new issue
Block a user