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
@@ -159,6 +159,36 @@ def boot_space_low(report: dict[str, Any], cfg: Config) -> str | None:
|
||||
return f"/boot has {free_kb // 1024} MB free{used}; the next kernel may not fit"
|
||||
|
||||
|
||||
def _mb(kb: int) -> int:
|
||||
"""KiB to MB, rounded up so a small need never reads as 0 MB."""
|
||||
return -(-kb // 1024)
|
||||
|
||||
|
||||
def upgrade_space_low(report: dict[str, Any], cfg: Config) -> list[str]:
|
||||
"""Filesystems the pending upgrades would leave with under upgrade_min_free_mb
|
||||
free. Downloads land on the filesystem holding /var/cache/apt/archives, installed
|
||||
files on /usr's; when that's the same filesystem, both count against it. Nothing
|
||||
pending means nothing to check, however full the disk: general disk usage is out
|
||||
of scope. Agents before 0.11.0 don't report it; unknown counts as fine."""
|
||||
download, install = report.get("upgrade_download_kb"), report.get("upgrade_install_kb")
|
||||
if not cfg.upgrade_min_free_mb or download is None or install is None:
|
||||
return []
|
||||
needs: dict[str, list[int]] = {} # mount -> [download KiB, install KiB, free KiB]
|
||||
for prefix, slot, amount in (("apt_archives", 0, download), ("usr", 1, max(install, 0))):
|
||||
mount, free = report.get(f"{prefix}_mount"), report.get(f"{prefix}_free_kb")
|
||||
if mount and free is not None:
|
||||
needs.setdefault(mount, [0, 0, free])[slot] += amount
|
||||
reasons = []
|
||||
for mount, (dl, inst, free) in needs.items():
|
||||
if not dl + inst or free - dl - inst >= cfg.upgrade_min_free_mb * 1024:
|
||||
continue
|
||||
parts = [f"{_mb(dl)} MB download" if dl else "", f"{_mb(inst)} MB installed" if inst else ""]
|
||||
reasons.append(f"pending upgrades need {_mb(dl + inst)} MB on {mount} "
|
||||
f"({' + '.join(p for p in parts if p)}), {free // 1024} MB free; "
|
||||
f"they may fail part-way")
|
||||
return reasons
|
||||
|
||||
|
||||
UU_LOG = "/var/log/unattended-upgrades/"
|
||||
|
||||
|
||||
@@ -351,6 +381,8 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
|
||||
f"{', '.join(other[:5])}{more}")
|
||||
if low := boot_space_low(report, cfg):
|
||||
status.raise_to("update", low)
|
||||
for low in upgrade_space_low(report, cfg):
|
||||
status.raise_to("update", low)
|
||||
|
||||
if found := unattended_upgrades_problem(report, cfg):
|
||||
problem, why = found
|
||||
|
||||
Reference in new issue
Block a user