Report a failed apt simulation instead of reading it as "no updates"
CI / tests (Python 3.10) (pull_request) Successful in 26s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 25s
CI / tests (Python 3.13) (pull_request) Successful in 25s
CI / lint (pull_request) Failing after 3s
CI / tests (Python 3.10) (pull_request) Successful in 26s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 25s
CI / tests (Python 3.13) (pull_request) Successful in 25s
CI / lint (pull_request) Failing after 3s
The agent ran `apt-get -s dist-upgrade 2>/dev/null || true`, so when apt failed (unmet dependencies, a broken sources entry, a damaged package cache) the empty output counted as zero updates and the host could show ok while nothing could be installed. The agent now keeps apt's exit status and stderr, reports apt_simulation_ok and the first "E:" line as apt_simulation_error, and sends the update counts as null. The server puts such a host in update with "apt can't work out pending updates: ...", and the host page shows the result. Agents before 0.5.0 don't send the field and are judged as before. Also show "–" rather than "None" for an unknown count in a host's history, and stop hard-coding the agent version in the status CLI tests. Agent 0.5.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1350c78676
commit
6d29197cfc
10 files changed
+100
-15
No files matched your search
@@ -271,6 +271,35 @@ X
|
||||
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_apt_simulation_ok(self):
|
||||
r = self.report()
|
||||
self.assertIs(r["apt_simulation_ok"], True)
|
||||
self.assertIsNone(r["apt_simulation_error"])
|
||||
|
||||
def test_apt_failure_reports_unknown_counts_not_zero(self):
|
||||
# A failed simulation prints no Inst lines; that must not read as "no updates".
|
||||
stub(self.bin, "apt-get", "echo 'Reading package lists...'\n"
|
||||
"echo 'W: Some warning' >&2\n"
|
||||
"echo \"E: Unmet dependencies. Try 'apt --fix-broken install'.\" >&2\n"
|
||||
"exit 100\n")
|
||||
r = self.report()
|
||||
self.assertIs(r["apt_simulation_ok"], False)
|
||||
self.assertEqual(r["apt_simulation_error"], "Unmet dependencies. Try 'apt --fix-broken install'.")
|
||||
for key in ("upgradable_count", "security_count", "kernel_upgradable", "phased_packages"):
|
||||
self.assertIsNone(r[key], key)
|
||||
|
||||
def test_apt_failure_without_an_error_line(self):
|
||||
stub(self.bin, "apt-get", "echo 'something broke' >&2\nexit 1\n")
|
||||
self.assertEqual(self.report()["apt_simulation_error"], "something broke")
|
||||
stub(self.bin, "apt-get", "exit 100\n")
|
||||
self.assertEqual(self.report()["apt_simulation_error"], "apt-get exited with status 100")
|
||||
|
||||
def test_apt_warnings_dont_mix_into_the_simulation(self):
|
||||
stub(self.bin, "apt-get", f"echo 'W: Inst fake [1] (2 x [amd64])' >&2\ncat <<'X'\n{APT_SIM_DEBIAN}X\n")
|
||||
r = self.report()
|
||||
self.assertIs(r["apt_simulation_ok"], True)
|
||||
self.assertEqual(r["upgradable_count"], 3)
|
||||
|
||||
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')
|
||||
|
||||
Reference in new issue
Block a user