Show Ubuntu phased updates separately from available updates

apt lists updates deferred by phasing in an indented block rather than
as Inst lines, so they were already excluded from the counts but
invisible. The agent now parses that block into phased_packages; the
dashboard shows "+N phased" in the Updates column (with a tooltip) and
the list on the host page. Phasing never affects status: Ubuntu doesn't
phase security updates, and there's nothing to act on until apt offers
the update.

Run the apt simulation with LC_ALL=C since we parse its messages (the
systemd unit already runs in the C locale; manual --print may not).
Agent and server 0.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 12:03:02 -04:00
1 parent ac17a98e91
commit 271af3b071
8 files changed
+76 -7

No files matched your search

+36
View File
@@ -98,6 +98,7 @@ class AgentReportTest(AgentCase):
self.assertEqual(r["upgradable_count"], 3)
self.assertEqual(r["security_count"], 2)
self.assertEqual(r["kernel_upgradable"], ["linux-image-6.12.60+deb13-amd64"])
self.assertEqual(r["phased_packages"], [], "Debian: no phasing")
self.assertAlmostEqual(r["apt_lists_age_seconds"], 7200, delta=60)
self.assertEqual(r["uptime_seconds"], 93784)
self.assertIsNone(r["services_need_restart"], "no needrestart results: unknown")
@@ -168,6 +169,41 @@ class AgentReportTest(AgentCase):
self.assertEqual(r["security_count"], 0)
self.assertEqual(r["kernel_upgradable"], [])
def test_ubuntu_phased_updates(self):
# Shape of real `apt-get -s dist-upgrade` output on 24.04 with phasing.
stub(self.bin, "apt-get", """cat <<'X'
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following upgrades have been deferred due to phasing:
libnss-systemd libpam-systemd libsystemd-shared libsystemd0 libudev1 systemd
systemd-resolved udev
The following packages will be upgraded:
curl libcurl4t64
2 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Inst libcurl4t64 [8.5.0-2ubuntu10.6] (8.5.0-2ubuntu10.7 Ubuntu:24.04/noble-security [amd64])
Inst curl [8.5.0-2ubuntu10.6] (8.5.0-2ubuntu10.7 Ubuntu:24.04/noble-security [amd64])
Conf libcurl4t64 (8.5.0-2ubuntu10.7 Ubuntu:24.04/noble-security [amd64])
X
""")
r = self.report()
self.assertEqual(r["upgradable_count"], 2)
self.assertEqual(r["security_count"], 2)
self.assertEqual(r["phased_packages"], sorted(
["libnss-systemd", "libpam-systemd", "libsystemd-shared", "libsystemd0", "libudev1",
"systemd", "systemd-resolved", "udev"]))
def test_apt_runs_in_c_locale(self):
stub(self.bin, "apt-get", 'echo "Inst locale-$LC_ALL [1] (2 x [amd64])"\n')
self.assertEqual(self.report()["upgradable_count"], 1)
stub(self.bin, "apt-get", '[ "$LC_ALL" = C ] || exit 1; echo "Inst ok [1] (2 x [amd64])"\n')
self.assertEqual(self.report()["upgradable_count"], 1)
def test_hostile_strings_stay_valid_json(self):
stub(self.bin, "hostname", "printf 'a\"b\\\\c\\tq'\n")
self.assertEqual(self.report()["reported_hostname"], 'a"b\\cq')