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
+39
-8
@@ -6,7 +6,7 @@
|
||||
# rules can change without redeploying agents.
|
||||
set -euo pipefail
|
||||
|
||||
AGENT_VERSION=0.4.1
|
||||
AGENT_VERSION=0.5.0
|
||||
|
||||
# Prefix for every file the agent reads. Only the test suite sets this.
|
||||
ROOT=${KERNELWATCH_ROOT:-}
|
||||
@@ -193,13 +193,30 @@ json_str_or_null() {
|
||||
# with /proc/1/root. Unprivileged we can't read /proc/1/root, so ischroot
|
||||
# answers "chroot" and apt would offer every phased update. We're not in one:
|
||||
# say so, and apt applies phasing from /etc/machine-id like it does for root.
|
||||
#
|
||||
# apt's stderr goes to the file named by $1. A failed simulation prints nothing,
|
||||
# which would otherwise read as "no updates", so the caller reports the failure.
|
||||
apt_simulation() {
|
||||
LC_ALL=C apt-get -s -q \
|
||||
-o Dir::Bin::ischroot=/bin/false \
|
||||
-o Debug::NoLocking=true \
|
||||
-o Dir::Cache::pkgcache= \
|
||||
-o Dir::Cache::srcpkgcache= \
|
||||
dist-upgrade 2>/dev/null || true
|
||||
dist-upgrade 2>"$1"
|
||||
}
|
||||
|
||||
# Why apt failed, from its stderr on stdin: the first "E:" line, else the first
|
||||
# line, else the exit status in $1.
|
||||
apt_error() {
|
||||
local line first=
|
||||
while IFS= read -r line; do
|
||||
if [[ $line == 'E: '* ]]; then
|
||||
printf '%s' "${line#E: }"
|
||||
return 0
|
||||
fi
|
||||
[[ -z $first && -n $line ]] && first=$line
|
||||
done
|
||||
printf '%s' "${first:-apt-get exited with status $1}"
|
||||
}
|
||||
|
||||
# Packages Ubuntu is holding back from this host for now (phased updates). apt
|
||||
@@ -233,7 +250,7 @@ uptime_seconds() {
|
||||
}
|
||||
|
||||
build_report() {
|
||||
local running newest kernels sim inst reboot_file=0 reboot_pkgs=
|
||||
local running newest kernels sim inst sim_err rc apt_ok=1 apt_err= reboot_file=0 reboot_pkgs=
|
||||
|
||||
running=$(uname -r)
|
||||
kernels=$(installed_kernels)
|
||||
@@ -241,7 +258,15 @@ build_report() {
|
||||
read_needrestart
|
||||
read_livepatch
|
||||
|
||||
sim=$(apt_simulation)
|
||||
sim_err=$(mktemp)
|
||||
if sim=$(apt_simulation "$sim_err"); then
|
||||
:
|
||||
else
|
||||
rc=$?
|
||||
apt_ok=0 sim=
|
||||
apt_err=$(apt_error "$rc" <"$sim_err")
|
||||
fi
|
||||
rm -f "$sim_err"
|
||||
inst=$(grep '^Inst ' <<<"$sim" || true)
|
||||
|
||||
if [[ -e $ROOT/run/reboot-required ]]; then
|
||||
@@ -270,10 +295,16 @@ build_report() {
|
||||
fi
|
||||
printf '"reboot_required":%s,' "$(json_bool "$reboot_file")"
|
||||
printf '"reboot_required_pkgs":%s,' "$(json_str_array <<<"$reboot_pkgs")"
|
||||
printf '"upgradable_count":%s,' "$(json_int "$(grep -c . <<<"$inst" || true)")"
|
||||
printf '"security_count":%s,' "$(json_int "$(grep -ci 'security' <<<"$inst" || true)")"
|
||||
printf '"phased_packages":%s,' "$(phased_packages <<<"$sim" | json_str_array)"
|
||||
printf '"kernel_upgradable":%s,' "$(awk '$2 ~ /^linux-image-/ { print $2 }' <<<"$inst" | json_str_array)"
|
||||
if ((apt_ok)); then
|
||||
printf '"upgradable_count":%s,' "$(json_int "$(grep -c . <<<"$inst" || true)")"
|
||||
printf '"security_count":%s,' "$(json_int "$(grep -ci 'security' <<<"$inst" || true)")"
|
||||
printf '"phased_packages":%s,' "$(phased_packages <<<"$sim" | json_str_array)"
|
||||
printf '"kernel_upgradable":%s,' "$(awk '$2 ~ /^linux-image-/ { print $2 }' <<<"$inst" | json_str_array)"
|
||||
else
|
||||
printf '"upgradable_count":null,"security_count":null,"phased_packages":null,"kernel_upgradable":null,'
|
||||
fi
|
||||
printf '"apt_simulation_ok":%s,' "$(json_bool "$apt_ok")"
|
||||
printf '"apt_simulation_error":%s,' "$(json_str_or_null "$apt_err")"
|
||||
printf '"livepatch_state":%s,' "$(json_str_or_null "$LP_STATE")"
|
||||
printf '"livepatch_check_state":%s,' "$(json_str_or_null "$LP_CHECK")"
|
||||
printf '"livepatch_supported":%s,' "$(json_str_or_null "$LP_SUPPORTED")"
|
||||
|
||||
Reference in new issue
Block a user