diff --git a/CHANGELOG.md b/CHANGELOG.md index 17c83dfad..a4832aff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ per the process in [`docs/dev/releasing.md`](docs/dev/releasing.md). - The **Stack Topology & Egress** panel shows the host's own traffic: a scope pill, host-OS nodes for time sync, OS and release fetches and image pulls, a warning when the host audit counted flows outside the allowlist, and a not-observed notice when the audit table is not loaded. `GET /api/system/egress-audit` and `egress_audit` in `/api/state` expose the counters (#4415, #4416, #4417). - With `tor.auto_heal`, a Tor stuck at 95% bootstrap with no circuit and an up guard (a relay refusing circuit creation) is cured by a guard rotation (`DROPGUARDS`) on the NEWNYM budget instead of a refresh that keeps the guards, and the heal never restarts Tor after one (#4121). +- Rigs take OS updates themselves: `pithead rig-update check` reads the release channel through the + image's on-demand Tor client, and `pithead rig-update install` downloads the signed bundle over Tor, + verifies it against the baked keyring with every shared refusal, writes the spare slot and reboots; + the intent lands in `rig-update.json` on `/data` and the boot settles the verdict — self-commit and + `updated`, or fallback with the failed slot marked bad and a `rolled_back` record (#4013). ### Fixed diff --git a/docs/dev/rig-os-update.md b/docs/dev/rig-os-update.md index 30a8dcd22..46cc482a5 100644 --- a/docs/dev/rig-os-update.md +++ b/docs/dev/rig-os-update.md @@ -46,7 +46,14 @@ On request only, never on a schedule. A request names no URL: the rig fetches th ### Status file -The rig keeps its last request time, verdict and reason in a status file on `/data`; its path and fields are fixed by #4013, which adds them to this page before it merges. The journal carries the same lines. +The rig keeps its last request outcome in `/data/pithead/rig-update.json` (`$PWD/rig-update.json` on the rig checkout), written by `pithead rig-update` before the reboot and settled by the rig branch of `pithead-boot` on the next boot through `pithead rig-update boot-record`. Fields: + +- `state` — `pending` (written after the bundle verified and before the spare slot is written, so a status file that cannot be written aborts the install before anything changes; settled by the next boot, or replaced by `refused` if the slot write fails), `refused` (a refusal — the running slot was untouched and the rig kept mining), `updated` (the pending slot booted with the miner up and committed), or `rolled_back` (the miner never came up there; the bootloader fell back and the failed slot was marked bad). +- `from`, `to` — the running version at the time and the target version, bare `X.Y.Z`; `to` is the version a pending install is waiting on, and a pending record blocks a new install until the reboot settles it. A refusal, including a failure of the Tor helper (clock, bootstrap or lock), never overwrites a `pending` record or a `rolled_back` verdict. +- `ts` — Unix seconds of the last state change. +- `reason` — present on refusals and on `rolled_back`: the one-line why, the same text printed to the console. The journal carries the same lines. + +A status read is what the feed (#4014) surfaces; the file is plain JSON, world-readable, and lives on `/data`, so it survives the slot swap. ### Trust model diff --git a/docs/dev/testing-strategy.md b/docs/dev/testing-strategy.md index 3f64a42a2..52ad0e3f8 100644 --- a/docs/dev/testing-strategy.md +++ b/docs/dev/testing-strategy.md @@ -358,6 +358,7 @@ the situations above; `missing` means nothing does yet, with the issue that owns | `firstboot-wizard` | covered | KVM (`pithead-firstboot.service`) | | `local-miner` | covered | KVM rig phase, via `pithead-boot` | | `os-update` | covered | KVM (appliance-only verb) | +| `rig-update` | covered | KVM rig phase, its own leg (#4013) | | `factory-reset` | covered | KVM (appliance-only verb) | | `control-run-pending` | covered | DIY bench | | `egress-run-pending` | covered | firewall-on clearnet sync on the DIY bench | diff --git a/lib/pithead/18-help-version.sh b/lib/pithead/18-help-version.sh index afadbc67a..fee46d91d 100644 --- a/lib/pithead/18-help-version.sh +++ b/lib/pithead/18-help-version.sh @@ -159,6 +159,24 @@ Maintenance: --reboot reboot to finish the update once it is installed (asks first unless -y is given). + rig-update check Rig-side OS updater (rigs only). Starts Tor through the image's + on-demand client, reads the hardened release channel, prints the + running and available OS versions, stops Tor, installs nothing. + + rig-update install [--tag T] [--max-version V] + Downloads the signed bundle over Tor into /data (resumable, + refused up front when /data lacks the room), verifies it against + the baked release keyring with the same refusals as every other + door (signature, compatible, variant, no downgrade, equal + refused, /data migration floor), refuses while the other slot is + uncommitted or an update is pending, then writes the spare slot + and reboots. The intent and the post-boot verdict live in + rig-update.json on /data. --tag names an exact vX.Y.Z release; + --max-version is a semantic ceiling the target must not exceed. + Every refusal keeps the rig mining and names its reason in that + status file; the bundle and its partial are deleted on every + outcome. + onion-client-key Print the Tor client-auth line for the dashboard onion — the client PRIVATE key, kept out of 'status'. Add it to your Tor client's ClientOnionAuthDir to reach a client-auth'd onion. diff --git a/lib/pithead/41-subcommand-chaining.sh b/lib/pithead/41-subcommand-chaining.sh index cd2daee0f..b22a0608f 100644 --- a/lib/pithead/41-subcommand-chaining.sh +++ b/lib/pithead/41-subcommand-chaining.sh @@ -3,7 +3,7 @@ # Every dispatchable subcommand, in help order. main's dispatch, the chain validator, and the # tab-completion script (pithead-completion.bash) key off this one list; tests/stack/run.sh fails # if any of the three drift apart. -readonly PITHEAD_COMMANDS="setup apply render up down restart tor-recover upgrade logs status test-alert doctor support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" +readonly PITHEAD_COMMANDS="setup apply render up down restart tor-recover upgrade logs status test-alert doctor support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update rig-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" # The subset allowed in a chain: commands that take no positional argument and terminate on their # own. Excluded: setup (interactive first-run), logs (follows until Ctrl+C), restore (needs an # archive path), reset-dashboard (destructive — run it deliberately, alone), test-alert (outbound diff --git a/lib/pithead/47a-os-update-channel.sh b/lib/pithead/47a-os-update-channel.sh index 45f51875f..8417859a5 100644 --- a/lib/pithead/47a-os-update-channel.sh +++ b/lib/pithead/47a-os-update-channel.sh @@ -1,4 +1,4 @@ -os_release_tag_valid() { printf '%s' "${1:-}" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; } +os_release_tag_valid() { [[ "${1:-}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; } os_release_host_ok() { case "$1" in diff --git a/lib/pithead/47b-rig-update.sh b/lib/pithead/47b-rig-update.sh new file mode 100644 index 000000000..91acf98a9 --- /dev/null +++ b/lib/pithead/47b-rig-update.sh @@ -0,0 +1,390 @@ +rig_update_state_file() { printf '%s' "${PITHEAD_RIG_UPDATE_STATE:-$PWD/rig-update.json}"; } + +rig_update_pending() { + local f + f=$(rig_update_state_file) + [ -f "$f" ] || return 0 + jq -r 'select(.state == "pending") | .to // empty' "$f" 2>/dev/null || true +} + +rig_update_state_write() { + local f tmp + f=$(rig_update_state_file) + tmp="$f.tmp" + if jq -n --arg st "$1" --arg fr "$2" --arg t "$3" --arg r "$4" --argjson ts "$(date +%s)" \ + '{state:$st,from:$fr,to:$t,ts:$ts} + (if $r == "" then {} else {reason:$r} end)' \ + >"$tmp" 2>/dev/null; then + mv -f "$tmp" "$f" && return 0 + fi + rm -f "$tmp" + return 1 +} + +rig_update_keeps_verdict() { + local f + f=$(rig_update_state_file) + [ -f "$f" ] || return 1 + jq -e '.state == "pending" or .state == "rolled_back"' "$f" >/dev/null 2>&1 +} + +rig_update_refuse() { + if ! rig_update_keeps_verdict; then + rig_update_state_write refused "$(os_running_version)" "${2:-}" "$1" || true + fi + error "$1" +} + +rig_update_wrap_fail() { + local ts msg="the Tor helper ended with status $1 — nothing was changed." + ts=$(jq -r '.ts // 0' "$(rig_update_state_file)" 2>/dev/null) || ts=0 + if [ "${ts:-0}" -lt "$2" ] && ! rig_update_keeps_verdict; then + rig_update_state_write refused "$(os_running_version)" "" "$msg" || true + fi + printf 'rig-update: %s\n' "$msg" >&2 +} + +rig_update_gate() { + command -v rauc >/dev/null 2>&1 || + error "rauc is not available here — rig-update applies to the appliance rig image, not a checkout install." + local role + role=$(machine_role) + [ "$role" = "rig" ] || + error "rig-update runs on a rig — this machine is '$role'. A coordinator updates its OS with 'pithead os-update' or the dashboard." +} + +rig_update_tor_wrap() { + if os_update_test_base >/dev/null 2>&1; then return 127; fi + if [ "${PITHEAD_RIG_UPDATE_IN_TOR:-}" = 1 ]; then return 127; fi + command -v pithead-tor >/dev/null 2>&1 || return 126 + local rc=0 + PITHEAD_RIG_UPDATE_IN_TOR=1 pithead-tor "$0" rig-update "$@" || rc=$? + return "$rc" +} + +rig_update_channel_url() { + local base + if base=$(os_update_test_base); then + printf '%s' "$base/releases-latest.json" + return 0 + fi + if [ -n "${1:-}" ]; then + printf '%s' "https://api.github.com/repos/p2pool-starter-stack/pithead/releases/tags/$1" + else + printf '%s' "https://api.github.com/repos/p2pool-starter-stack/pithead/releases/latest" + fi +} + +rig_update_release() { + local url tmp rc=0 size note_json + RIG_TAG="" RIG_SIZE=0 RIG_NOTE="" RIG_REFUSE="" + url=$(rig_update_channel_url "${1:-}") + tmp=$(mktemp "${TMPDIR:-/tmp}/pithead-rigrel.XXXXXX") || { + RIG_REFUSE="the release channel response could not be staged — nothing was changed." + return 1 + } + os_channel_fetch get "$url" "$tmp" "$CURL_CAP_SMALL" "127.0.0.1:${PITHEAD_TOR_SOCKS_PORT:-9253}" || rc=$? + if [ "$rc" -ne 0 ]; then + RIG_REFUSE="${OS_CHANNEL_HINT:-the release channel could not be read — nothing was changed.}" + rm -f "$tmp" + return 1 + fi + RIG_TAG=$(jq -r '.tag_name // ""' "$tmp" 2>/dev/null) || RIG_TAG="" + if ! os_release_tag_valid "$RIG_TAG"; then + RIG_REFUSE="the release channel published no usable release tag — nothing was changed." + rm -f "$tmp" + return 1 + fi + size=$(jq -r --arg n "pithead-os-$RIG_TAG.raucb" '[.assets[]? | select(.name == $n)][0].size // 0' "$tmp" 2>/dev/null) || size=0 + case "$size" in '' | *[!0-9]*) size=0 ;; esac + if [ "$size" -le 0 ]; then + RIG_REFUSE="release $RIG_TAG publishes no appliance OS bundle — nothing was changed." + rm -f "$tmp" + return 1 + fi + rm -f "$tmp" + RIG_SIZE="$size" + note_json=$(os_channel_record "$RIG_TAG" 2>/dev/null) || note_json="" + RIG_NOTE=$(printf '%s' "$note_json" | jq -r '.note // ""' 2>/dev/null) || RIG_NOTE="" + return 0 +} + +rig_update_slot_guard() { + local status bs + status=$(rauc status --output-format=json 2>/dev/null) || { + RIG_REFUSE="this machine's slot state could not be read — nothing was changed." + return 1 + } + bs=$(printf '%s' "$status" | + jq -r '(.booted // "") as $b | [.slots[]? | to_entries[]? | + select(.value.bootname != null and .value.bootname != $b) | .value.boot_status // ""] | .[0] // ""' 2>/dev/null) || bs="" + case "$bs" in + good | bad | "") return 0 ;; + unknown) + if [ -f .boot-gate-failures ]; then + RIG_REFUSE="the other slot is uncommitted and a boot here failed its gate — read 'journalctl -u pithead-boot' before installing over it; nothing was changed." + return 1 + fi + return 0 + ;; + esac + RIG_REFUSE="the other slot is uncommitted (rauc reports boot status '$bs') — a slot mid-flight is never overwritten; nothing was changed." + return 1 +} + +rig_update_cleanup() { find "$(os_update_staging_dir)" -maxdepth 1 -name 'pithead-os-*.raucb*' -delete 2>/dev/null || true; } + +rig_update_download() { + local final="$1" part="$2" size="$3" url="$4" socks="$5" + local attempt="${PITHEAD_OS_DL_ATTEMPT:-600}" tries=0 pid rc=0 bytes have http_code fail dl_url resf + while :; do + tries=$((tries + 1)) + if [ "$tries" -gt "${PITHEAD_RIG_UPDATE_ATTEMPTS:-12}" ]; then + RIG_REFUSE="the download did not finish in $((tries - 1)) attempts — the partial file was discarded and nothing was installed." + return 1 + fi + have=0 + if [ -f "$part" ]; then have=$(wc -c <"$part" | tr -d ' '); fi + dl_url="$url" + if [ -n "$socks" ]; then + resf=$(mktemp "${TMPDIR:-/tmp}/pithead-rigurl.XXXXXX") || resf="" + if [ -z "$resf" ] || ! os_channel_fetch head "$url" /dev/null "$CURL_CAP_OS_BUNDLE" "$socks" >"$resf"; then + RIG_REFUSE="the update bundle URL could not be resolved over Tor — ${OS_CHANNEL_HINT:-nothing was changed.}" + rm -f "$resf" + return 1 + fi + dl_url=$(cat "$resf") + rm -f "$resf" + fi + if [ -n "$socks" ]; then + curl -fS -C - --max-time "$attempt" --max-filesize "$CURL_CAP_OS_BUNDLE" \ + --proto "=https" --socks5-hostname "$socks" -o "$part" -w '%{http_code}\n' \ + "$dl_url" >"$part.code" 2>/dev/null & + else + curl -fS -C - --max-time "$attempt" --max-filesize "$CURL_CAP_OS_BUNDLE" \ + -o "$part" -w '%{http_code}\n' "$dl_url" >"$part.code" 2>/dev/null & + fi + pid=$! + wait "$pid" && rc=0 || rc=$? + http_code=$(tr -d '[:space:]' <"$part.code" 2>/dev/null) || http_code="" + rm -f "$part.code" + bytes=0 + if [ -f "$part" ]; then bytes=$(wc -c <"$part" | tr -d ' '); fi + fail="" + if [ "$bytes" -gt "$size" ]; then fail="the bundle stream exceeded its announced $size-byte size"; fi + if [ -z "$fail" ] && [ "$rc" -eq 0 ] && [ "${http_code#2}" = "$http_code" ]; then + fail="the bundle URL answered HTTP ${http_code:-none}" + fi + if [ -n "$fail" ]; then + RIG_REFUSE="$fail — the partial file was discarded and nothing was installed." + return 1 + fi + if [ "$rc" -eq 0 ]; then + if [ "$bytes" -eq "$size" ]; then + mv -f "$part" "$final" + return 0 + fi + RIG_REFUSE="the download completed at $bytes bytes but the release publishes $size — a truncated bundle is never verified as complete; the partial file was discarded." + return 1 + fi + if [ "$rc" -ne 28 ]; then + RIG_REFUSE="the download failed over Tor at $bytes of $size bytes — the partial file was discarded and nothing was installed." + return 1 + fi + rc=0 + done +} + +rig_update_check() { + rig_update_gate + local rc=0 running start + start=$(date +%s) + rig_update_tor_wrap check || rc=$? + if [ "$rc" -ne 127 ]; then + if [ "$rc" -eq 126 ]; then + rig_update_refuse "this image carries no on-demand Tor client (pithead-tor) — rig-update needs it to reach the release channel." + fi + if [ "$rc" -ne 0 ]; then rig_update_wrap_fail "$rc" "$start"; fi + return "$rc" + fi + rig_update_release "" || rig_update_refuse "$RIG_REFUSE" + running=$(os_running_version) + printf 'rig-update: running v%s, release channel offers %s (%s bytes) — nothing installed.\n' \ + "$running" "$RIG_TAG" "$RIG_SIZE" + if [ "$RIG_TAG" = "v$running" ]; then + printf 'rig-update: this rig already runs %s.\n' "$RIG_TAG" + fi + if [ -n "$RIG_NOTE" ]; then + printf 'rig-update: %s\n' "$RIG_NOTE" + fi + return 0 +} + +rig_update_install() { + rig_update_gate + local tag_wanted="" max_version="" arg rc=0 reason pending start + while [ "$#" -gt 0 ]; do + arg="$1" + case "$arg" in + --tag) + [ "$#" -ge 2 ] || error "rig-update install --tag needs a tag. Run '$0 help'." + tag_wanted="$2" + shift 2 + ;; + --max-version) + [ "$#" -ge 2 ] || error "rig-update install --max-version needs a version. Run '$0 help'." + max_version="$2" + shift 2 + ;; + *) error "Unknown option for rig-update install: $arg. Run '$0 help'." ;; + esac + done + if [ -n "$tag_wanted" ] && ! os_release_tag_valid "$tag_wanted"; then + rig_update_refuse "--tag wants the exact vX.Y.Z form (got '$tag_wanted') — nothing was changed." + fi + max_version="${max_version#v}" + if [ -n "$max_version" ] && ! os_semver_ok "$max_version"; then + rig_update_refuse "--max-version wants an X.Y.Z version (got '$max_version') — nothing was changed." + fi + pending=$(rig_update_pending) + if [ -n "$pending" ]; then + rig_update_refuse "an update to v$pending is already pending a reboot — reboot this rig before starting another; nothing was changed." + fi + rig_update_slot_guard || rig_update_refuse "$RIG_REFUSE" + local -a wrap=(install) + if [ -n "$tag_wanted" ]; then wrap+=(--tag "$tag_wanted"); fi + if [ -n "$max_version" ]; then wrap+=(--max-version "$max_version"); fi + start=$(date +%s) + rig_update_tor_wrap "${wrap[@]}" || rc=$? + if [ "$rc" -ne 127 ]; then + if [ "$rc" -eq 126 ]; then + rig_update_refuse "this image carries no on-demand Tor client (pithead-tor) — rig-update needs it to reach the release channel." + fi + if [ "$rc" -ne 0 ]; then rig_update_wrap_fail "$rc" "$start"; fi + return "$rc" + fi + rig_update_release "$tag_wanted" || rig_update_refuse "$RIG_REFUSE" + local target="${RIG_TAG#v}" + if [ -n "$max_version" ] && semver_newer "$target" "$max_version"; then + rig_update_refuse "$RIG_TAG is above --max-version v$max_version — nothing was installed." "$target" + fi + if [ "$RIG_TAG" = "v$(os_running_version)" ]; then + rig_update_refuse "this rig already runs $RIG_TAG — nothing to install." "$target" + fi + reason=$(os_update_version_guard "$target" 0) + if [ -n "$reason" ]; then + rig_update_refuse "$reason" "$target" + fi + local osdir final part socks base url have avail_kb need errf last_err="" + osdir=$(os_update_staging_dir) + mkdir -p "$osdir" + final="$osdir/pithead-os-$RIG_TAG.raucb" + part="$final.partial" + find "$osdir" -maxdepth 1 -name 'pithead-os-*.raucb*' \ + ! -name "pithead-os-$RIG_TAG.raucb" ! -name "pithead-os-$RIG_TAG.raucb.partial" -delete 2>/dev/null || true + have=0 + if [ -f "$part" ]; then have=$(wc -c <"$part" | tr -d ' '); fi + avail_kb=$(df -Pk "$osdir" 2>/dev/null | awk 'NR==2{print $4}') || avail_kb="" + case "$avail_kb" in '' | *[!0-9]*) avail_kb=0 ;; esac + need=$(((RIG_SIZE - have) / 1024 + 1048576)) + if [ "$avail_kb" -lt "$need" ]; then + rig_update_refuse "not enough free space on /data for the update bundle (need about $((need / 1024)) MiB free, have $((avail_kb / 1024)) MiB) — free space and retry; nothing was installed." "$target" + fi + if base=$(os_update_test_base); then + url="$base/pithead-os-$RIG_TAG.raucb" + socks="" + else + socks="127.0.0.1:${PITHEAD_TOR_SOCKS_PORT:-9253}" + url="https://github.com/p2pool-starter-stack/pithead/releases/download/$RIG_TAG/pithead-os-$RIG_TAG.raucb" + fi + if ! rig_update_download "$final" "$part" "$RIG_SIZE" "$url" "$socks"; then + rig_update_cleanup + rig_update_refuse "$RIG_REFUSE" "$target" + fi + rc=0 + reason=$(os_verify_bundle_reason "$final" "$RIG_TAG") || rc=$? + reason="${reason% The downloaded update was kept.}" + if [ "$rc" -ne 0 ] || [ -n "$reason" ]; then + rig_update_cleanup + rig_update_refuse "${reason:-the bundle could not be verified — nothing was installed.}" "$target" + fi + printf 'rig-update: %s verified against this machine release keyring — writing it to the spare slot\n' "$RIG_TAG" + if ! rig_update_state_write pending "$(os_running_version)" "$target" ""; then + rig_update_cleanup + error "the update status file could not be written — nothing was installed and the rig was not rebooted." + fi + errf=$(mktemp "${TMPDIR:-/tmp}/pithead-riginstall.XXXXXX") || errf="" + rc=0 + if [ -n "$errf" ]; then + (os_update "$final" -y "$errf" || rc=$? + last_err=$(tail -1 "$errf" 2>/dev/null | tr -d '[:cntrl:]' | head -c 300) + rm -f "$errf" + else + (os_update "$final" -y /dev/null 2>&1 || return 0 + to=$(jq -r 'select(.state == "pending") | .to // empty' "$f" 2>/dev/null) || to="" + [ -n "$to" ] || return 0 + from=$(jq -r '.from // ""' "$f" 2>/dev/null) || from="" + now=$(date +%s) + tmp="$f.tmp" + if [ "$to" = "$(os_running_version)" ]; then + if jq -n --arg fr "$from" --arg t "$to" --argjson ts "$now" \ + '{state:"updated",from:$fr,to:$t,ts:$ts}' >"$tmp" 2>/dev/null; then + mv -f "$tmp" "$f" + echo "pithead-boot: the rig's update to v$to booted with the miner up — verdict updated" + else + rm -f "$tmp" + fi + return 0 + fi + rauc status mark-bad other >/dev/null 2>&1 || true + sync + if jq -n --arg fr "$from" --arg t "$to" --argjson ts "$now" \ + '{state:"rolled_back",from:$fr,to:$t,ts:$ts,reason:"the miner never came up on the updated slot — the bootloader fell back"}' \ + >"$tmp" 2>/dev/null; then + mv -f "$tmp" "$f" + echo "pithead-boot: the rig's v$to update never committed — this boot runs the previous version, the failed slot is marked bad and the verdict recorded" + else + rm -f "$tmp" + fi + return 0 +} + +rig_update() { + local sub="${1:-}" + case "$sub" in + boot-record) + shift + rig_update_boot_record "$@" + ;; + check) + shift + rig_update_check "$@" + ;; + install) + shift + rig_update_install "$@" + ;; + *) + error "rig-update needs a subcommand: check, or install [--tag T] [--max-version V]. Run '$0 help'." + ;; + esac +} diff --git a/lib/pithead/51-main-dispatch.sh b/lib/pithead/51-main-dispatch.sh index 66c5c3372..b4cf365d9 100644 --- a/lib/pithead/51-main-dispatch.sh +++ b/lib/pithead/51-main-dispatch.sh @@ -148,6 +148,7 @@ main() { provision_local_miner ;; os-update) os_update "$@" ;; + rig-update) rig_update "$@" ;; control-run-pending) _reject_options control-run-pending "$@" require_deployed diff --git a/os/overlay/pithead-boot b/os/overlay/pithead-boot index 8a128bb44..f937bfef6 100755 --- a/os/overlay/pithead-boot +++ b/os/overlay/pithead-boot @@ -289,7 +289,7 @@ if [ -f machine-role ] && [ "$(tr -d '[:space:]' &2 if [ "$hold_chain" = 1 ]; then clear_migration_hold "$migration_fingerprint"; else restore_data_floor_after_fallback "$migration_fingerprint"; fi || echo "pithead-boot: FAULT — migration protection could not be reconciled after commitment" >&2 echo "pithead-boot: the rig's miner is running — booted slot committed" diff --git a/pithead-completion.bash b/pithead-completion.bash index f861fa8cb..0efbb7434 100644 --- a/pithead-completion.bash +++ b/pithead-completion.bash @@ -13,7 +13,7 @@ # Keep in sync with PITHEAD_COMMANDS in the pithead script — tests/stack/run.sh fails if the # two lists drift. -_pithead_commands="setup apply render up down restart tor-recover upgrade logs status test-alert doctor support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" +_pithead_commands="setup apply render up down restart tor-recover upgrade logs status test-alert doctor support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update rig-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" # Service names = the top-level keys under `services:` in the docker-compose.yml next to the # pithead being completed. $1 = path to that compose file. diff --git a/tests/os/phases/rig.sh b/tests/os/phases/rig.sh index d87be0df8..44f7ebbdc 100644 --- a/tests/os/phases/rig.sh +++ b/tests/os/phases/rig.sh @@ -428,8 +428,8 @@ phase_rig() { return } marker=$(_ssh cat /etc/pithead-test-marker | tr -d '\r\n') - [ "$marker" = "v2" ] && ok "COMMIT: the update persists on the rig across reboot" || - bad "expected v2 on the rig after commit, got '$marker'" + [ "$marker" = "v2" ] && ok "COMMIT: the update persists on the rig across reboot" || bad "expected v2 on the rig after commit, got '$marker'" + rig_update_leg # #2063: no accepted share has ever been proven on the appliance channel — this rig's own pool # is its own sshd (#796), by design. A coordinator this battery itself boots in remote-node mode diff --git a/tests/os/rig-update-leg.sh b/tests/os/rig-update-leg.sh new file mode 100644 index 000000000..f832d6397 --- /dev/null +++ b/tests/os/rig-update-leg.sh @@ -0,0 +1,131 @@ +# shellcheck shell=bash +rig_update_leg() { + info "rig-update leg — channel check, refusals, install and verdict through pithead rig-update" + local tag srv host_addr port=8933 size srv_pid bundle out aged before marker n + tag="v$(tr -d ' \t\r\n' "$srv/releases-latest.json" + host_addr=$(ip -4 -o addr show virbr0 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -1) + [ -n "$host_addr" ] || host_addr="192.168.122.1" + if ! srv_pid=$(_serve_update_dir "$srv" "$port"); then + bad "rig-update leg: the bench release server never answered on :$port — this is the harness, not the product" + rm -rf "$srv" + return + fi + _ssh "printf 'http://$host_addr:$port' > /data/pithead/os-update-test-base" || { + bad "rig-update leg: could not plant the update-server seam on the rig" + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" + return + } + if ! aged=$(aged_version "${tag#v}"); then + bad "rig-update leg: cannot age the running version ${tag#v} (tests/os/aged-version.sh)" + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" + return + fi + _ssh "printf '%s\n' '$aged' > /data/pithead/VERSION" || { + bad "rig-update leg: could not age the rig's running version to $aged" + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" + return + } + + out=$(_ssh "cd /data/pithead && ./pithead rig-update check 2>&1") + case "$out" in + *"running v$aged, release channel offers $tag"*) + ok "rig-update check reports the running and published versions without installing" + ;; + *) bad "rig-update check did not report the seam release (got: $(printf '%s' "$out" | tr '\n' ' ' | cut -c1-200))" ;; + esac + [ -z "$(_ssh 'pgrep -x tor 2>/dev/null' | tr -d '\r')" ] && + ok "the seam check started no Tor" || bad "the seam check started Tor" + + out=$(_ssh "cd /data/pithead && ./pithead rig-update install --max-version 2.0.0 2>&1") + case "$out" in + *"above --max-version"*) + ok "rig-update refuses the published tag above --max-version, semantically" + ;; + *) bad "the --max-version ceiling did not refuse (got: $(printf '%s' "$out" | tr '\n' ' ' | cut -c1-200))" ;; + esac + if _rig_mining_up 6; then + ok "the refusal left the rig mining" + else + bad "the rig stopped mining after a refusal" + fi + [ "$(_ssh "jq -r '.state' /data/pithead/rig-update.json" 2>/dev/null | tr -d '\r')" = "refused" ] && + ok "the refusal is recorded with its reason in rig-update.json" || + bad "the refusal did not reach the status file" + + _ssh "printf '{\"state\":\"pending\",\"from\":\"0.0.0\",\"to\":\"9.9.9\",\"ts\":1}' > /data/pithead/rig-update.json" + out=$(_ssh "cd /data/pithead && ./pithead rig-update install 2>&1") + case "$out" in + *"pending a reboot"*) ok "a pending update blocks a new install until the reboot settles it" ;; + *) bad "the pending record did not refuse a second install (got: $(printf '%s' "$out" | tr '\n' ' ' | cut -c1-200))" ;; + esac + [ "$(_ssh "jq -r '.to' /data/pithead/rig-update.json" 2>/dev/null | tr -d '\r')" = "9.9.9" ] && + ok "the refusal kept the pending record intact" || bad "the refusal clobbered the pending record" + _ssh "rm -f /data/pithead/rig-update.json" + + if ! before=$(_boot_id); then + bad "rig-update leg: could not read the boot id before the install reboot — a reconnect and a reboot would look alike" + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" + return + fi + out=$(_ssh "cd /data/pithead && ./pithead rig-update install 2>&1") || true + if ! _wait_new_boot "$before" 420; then + bad "rig-update leg: the rig never returned after rig-update installed the spare slot" + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" + return + fi + marker=$(_ssh cat /etc/pithead-test-marker | tr -d '\r\n') + [ "$marker" = "v1" ] && ok "rig-update installed its bundle and the rig booted it" || + bad "expected v1 after rig-update's reboot, got '$marker'" + _rig_mining_up 24 && ok "the rig mines again after the rig-update reboot" || + bad "the rig stopped mining after the rig-update reboot" + n=0 + while [ "$n" -lt 30 ]; do + [ "$(_ssh "jq -r '.state' /data/pithead/rig-update.json" 2>/dev/null | tr -d '\r')" = "updated" ] && break + sleep 5 + n=$((n + 1)) + done + [ "$n" -lt 30 ] && ok "the boot settled the verdict as updated in rig-update.json" || + bad "the post-boot verdict never landed in rig-update.json" + _ssh "journalctl -b -u pithead-boot 2>/dev/null | grep -q 'verdict updated'" && + ok "pithead-boot's journal carries the updated verdict" || + bad "pithead-boot's journal has no verdict line" + ! _ssh 'ls /data/pithead/data/os-update/pithead-os-* >/dev/null 2>&1' && + ok "the bundle and any partial were deleted after the install" || + bad "a staged bundle survived the rig-update outcome" + + out=$(_ssh "rm -f /data/pithead/os-update-test-base && cd /data/pithead && PITHEAD_TOR_TIMEOUT=300 ./pithead rig-update check 2>&1") + case "$out" in + *"release channel offers v"*) ok "rig-update check reads the real release channel over Tor" ;; + *) bad "the Tor check did not report the channel (got: $(printf '%s' "$out" | tr '\n' ' ' | cut -c1-200))" ;; + esac + [ -z "$(_ssh 'pgrep -x tor 2>/dev/null' | tr -d '\r')" ] && + ok "Tor stopped after the check" || bad "Tor kept running after the check" + + _ssh 'grub-editenv /boot/efi/grub/grubenv set "ORDER=B A"' || + bad "rig-update leg: could not put slot B back as the boot default — the legs below will follow the wrong slot" + _reboot_wait reboot 300 || bad "rig-update leg: the rig never returned after the boot-default was restored to slot B" + case "$(_ssh cat /proc/cmdline 2>/dev/null | tr -d '\r')" in + *rauc.slot=B*) ok "the rig runs slot B again for the legs below" ;; + *) bad "the rig did not come back on slot B — cmdline: $(printf '%s' "$(_ssh cat /proc/cmdline 2>/dev/null)" | cut -c1-160)" ;; + esac + _rig_mining_up 24 && ok "the rig mines again after the hand-back reboot" || + bad "the rig stopped mining after the hand-back reboot" + + kill "$srv_pid" 2>/dev/null || true + rm -rf "$srv" +} diff --git a/tests/os/run.sh b/tests/os/run.sh index f97ee58cd..3912f7c59 100755 --- a/tests/os/run.sh +++ b/tests/os/run.sh @@ -158,6 +158,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" . "$SCRIPT_DIR/rig-config-meta-wait.sh" # shellcheck source=tests/os/rig-control-off-leg.sh . "$SCRIPT_DIR/rig-control-off-leg.sh" +# shellcheck source=tests/os/rig-update-leg.sh +. "$SCRIPT_DIR/rig-update-leg.sh" # shellcheck source=tests/os/appliance-miner-recovery.sh . "$SCRIPT_DIR/appliance-miner-recovery.sh" # shellcheck source=tests/os/rig-share-leg.sh diff --git a/tests/os/selftest-rig-update.sh b/tests/os/selftest-rig-update.sh new file mode 100644 index 000000000..8fe83794b --- /dev/null +++ b/tests/os/selftest-rig-update.sh @@ -0,0 +1,324 @@ +#!/usr/bin/env bash +set -uo pipefail +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO="$HERE/../.." +CLI="$REPO/pithead" + +if [ ! -x "$CLI" ]; then + echo "selftest-rig-update: $CLI is not built — run make first" >&2 + exit 1 +fi + +FAILURES=0 +PASSES=0 +check() { + if [ "$2" = "$3" ]; then PASSES=$((PASSES + 1)); else + FAILURES=$((FAILURES + 1)) + echo "selftest-rig-update: FAIL: $1 — expected [$3], got [$2]" >&2 + fi +} +check_has() { + case "$2" in + *"$3"*) PASSES=$((PASSES + 1)) ;; + *) + FAILURES=$((FAILURES + 1)) + echo "selftest-rig-update: FAIL: $1 — [$2] missing [$3]" >&2 + ;; + esac +} + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +SB="$tmp/os" +STAGE="$SB/data/os-update" +mkdir -p "$SB/bin" "$STAGE" +printf '1.3.1\n' >"$SB/VERSION" +printf 'rig\n' >"$SB/machine-role" +printf 'release\n' >"$SB/variant-release" +printf 'compatible=pithead-os\n' >"$SB/system.conf" +yes x | head -c 1000 >"$SB/fixture.raucb" +listing() { + printf '{"tag_name":"%s","html_url":"https://example.invalid/rel","assets":[{"name":"pithead-os-%s.raucb","size":%s}]}' \ + "$1" "$1" "${2:-1000}" >"$SB/api.json" +} +listing v9.9.9 +printf '{"tag_name":"v9.9.9/../../x","assets":[{"name":"pithead-os-x.raucb","size":1000}]}' >"$SB/api-evil-tag.json" +printf '{"tag_name":"v9.9.9","assets":[]}' >"$SB/api-no-bundle.json" +printf 'http://seam.invalid/os' >"$SB/os-update-test-base" +: >"$SB/test-marker" + +cat >"$SB/bin/curl" <<'EOF' +#!/usr/bin/env bash +echo "[curl] $*" >>"${CURL_LOG:-/dev/null}" +url="${*: -1}" +out="" +prev="" +head=0 +for a in "$@"; do + [ "$prev" = "-o" ] && out="$a" + [ "$a" = "-I" ] && head=1 + prev="$a" +done +if [ "$head" = 1 ]; then + [ -n "${CH_HEAD_RC:-}" ] && exit "$CH_HEAD_RC" + printf '200' + exit 0 +fi +case "$url" in +*api.github.com* | *seam.invalid*releases-latest.json) + if [ "${CH_STUB_RC:-0}" != "0" ]; then exit "$CH_STUB_RC"; fi + cat "${CH_API_RESPONSE:?}" >"$out" + printf '200' + ;; +*pithead-os-*) + have=0 + [ -f "$out" ] && have=$(wc -c <"$out" | tr -d ' ') + n=$(cat "${CH_RC28_FILE:-/dev/null}" 2>/dev/null || echo 0) + if [ "$n" -lt "${CH_RC28_N:-0}" ]; then + echo $((n + 1)) >"$CH_RC28_FILE" + head -c 100 "${CH_BUNDLE:?}" >>"$out" + exit 28 + fi + if [ "${CH_TRUNCATE:-0}" = 1 ]; then + head -c 600 "${CH_BUNDLE:?}" >>"$out" + else + tail -c "+$((have + 1))" "${CH_BUNDLE:?}" >>"$out" + fi + printf '200' + ;; +*) exit 22 ;; +esac +exit 0 +EOF +cat >"$SB/bin/rauc" <<'EOF' +#!/usr/bin/env bash +echo "rauc $*" >>"${RAUC_LOG:-/dev/null}" +case "$1" in +info) + if [ "$#" -ge 2 ] && [ "$2" = "--output-format=shell" ]; then + [ "${RAUC_INFO_FAIL:-0}" = 1 ] && exit 1 + printf "RAUC_MF_COMPATIBLE='pithead-os'\nRAUC_META_PITHEAD_VERSION='%s'\nRAUC_META_PITHEAD_VARIANT='release'\nRAUC_META_PITHEAD_DATA_MIGRATION='false'\n" \ + "${RAUC_BUNDLE_VERSION:-9.9.9}" + exit 0 + fi + [ "${RAUC_INFO_FAIL:-0}" = 1 ] && exit 1 + exit 0 + ;; +status) + case "${2:-}" in + --output-format=json) + printf '{"booted":"A","slots":[{"rootfs.0":{"bootname":"A","state":"booted","boot_status":"good"}},{"rootfs.1":{"bootname":"B","state":"inactive","boot_status":"%s"}}]}\n' \ + "${RAUC_OTHER_STATUS:-good}" + ;; + esac + exit 0 + ;; +install) + [ "${RAUC_INSTALL_FAIL:-0}" = 1 ] && exit 1 + exit 0 + ;; +*) exit 0 ;; +esac +EOF +cat >"$SB/bin/df" <<'EOF' +#!/usr/bin/env bash +echo "Filesystem 1024-blocks Used Available Capacity Mounted on" +echo "fake 1000000 0 ${DF_AVAIL_KB:-999999999} 0% /data" +EOF +cat >"$SB/bin/systemctl" <<'EOF' +#!/usr/bin/env bash +exit 0 +EOF +cat >"$SB/bin/pithead-tor" <<'EOF' +#!/usr/bin/env bash +echo "tor $*" >>"${TOR_LOG:-/dev/null}" +[ -n "${TOR_RC:-}" ] && exit "$TOR_RC" +exec "$@" +EOF +cat >"$SB/reboot-stub" <<'EOF' +#!/usr/bin/env bash +echo reboot >>"${REBOOT_LOG:-/dev/null}" +EOF +chmod +x "$SB/bin/curl" "$SB/bin/rauc" "$SB/bin/df" "$SB/bin/systemctl" "$SB/bin/pithead-tor" "$SB/reboot-stub" +cp "$CLI" "$SB/pithead" +: >"$SB/rauc.log" +: >"$SB/curl.log" +: >"$SB/tor.log" +: >"$tmp/reboot.log" + +rig() { + local -a e=() + while [ "$#" -gt 0 ]; do + case "$1" in + *=*) + e+=("$1") + shift + ;; + *) break ;; + esac + done + (cd "$SB" && PATH="$SB/bin:$PATH" CURL_LOG="$SB/curl.log" CH_API_RESPONSE="$SB/api.json" \ + CH_BUNDLE="$SB/fixture.raucb" RAUC_LOG="$SB/rauc.log" TOR_LOG="$SB/tor.log" \ + REBOOT_LOG="$tmp/reboot.log" CH_RC28_FILE="$SB/rc28.n" PITHEAD_TEST_MARKER_FILE="$SB/test-marker" PITHEAD_APPLIANCE=1 PITHEAD_OS_UPDATE_DIR="$STAGE" \ + PITHEAD_RIG_UPDATE_STATE="$SB/rig-update.json" PITHEAD_RIG_UPDATE_ATTEMPTS=3 \ + PITHEAD_VARIANT_FILE="$SB/variant-release" PITHEAD_RAUC_SYSTEM_CONF="$SB/system.conf" \ + PITHEAD_DATA_FLOOR_FILE="$SB/floor" PITHEAD_REBOOT_CMD="$SB/reboot-stub" \ + env ${e[@]+"${e[@]}"} ./pithead rig-update "$@" 2>&1) +} +state() { jq -r "$1" "$SB/rig-update.json" 2>/dev/null; } +staged() { find "$STAGE" -name 'pithead-os-*' | wc -l | tr -d ' '; } + +out=$(rig check) +check_has "check reports both versions over the seam" "$out" "running v1.3.1, release channel offers v9.9.9 (1000 bytes)" +check "the seam check starts no Tor" "$(grep -c 'rig-update' "$SB/tor.log")" "0" + +listing v9.9.9 +rm -f "$SB/os-update-test-base" +out=$(rig check) +check_has "check passes with no seam" "$out" "release channel offers v9.9.9" +check_has "check starts Tor through the helper" "$(cat "$SB/tor.log")" "rig-update check" +check "the channel fetch dials the Tor SOCKS port" "$(grep -c -- '--socks5-hostname 127.0.0.1:9253' "$SB/curl.log")" "1" +printf 'http://seam.invalid/os' >"$SB/os-update-test-base" + +out=$(rig check) +check_has "a frozen channel is reported" "$out" "stale or frozen" + +out=$(rig CH_API_RESPONSE="$SB/api-evil-tag.json" check) +check_has "a tainted tag is refused" "$out" "no usable release tag" +check "the refusal is in the status file" "$(state .state)" "refused" +check_has "the status file names the reason" "$(state .reason)" "no usable release tag" + +out=$(rig CH_API_RESPONSE="$SB/api-no-bundle.json" check) +check_has "a release without the OS bundle is refused" "$out" "publishes no appliance OS bundle" + +out=$(rig install --max-version) +check "a missing --max-version value is refused" "$(printf '%s' "$out" | grep -c 'needs a version')" "1" + +listing v1.3.1 +out=$(rig install) +check_has "the equal version is refused" "$out" "already runs v1.3.1" +listing v1.0.0 +out=$(rig install) +check_has "a downgrade is refused" "$out" "downgrade" +listing v9.9.9 + +out=$(rig install --max-version 2.0.0) +check_has "a tag above --max-version is refused semantically" "$out" "above --max-version v2.0.0" + +out=$(rig install --tag v9-9-9) +check_has "an unparseable --tag is refused" "$out" "vX.Y.Z form" + +jq -n '{state:"pending",from:"1.3.1",to:"9.9.9",ts:1}' >"$SB/rig-update.json" +out=$(rig install) +check_has "a pending update is refused" "$out" "pending a reboot" +check "the pending record survives the refusal" "$(state .state)" "pending" +check "the refusal names the pending target" "$(state .to)" "9.9.9" + +rm -f "$SB/rig-update.json" +touch "$SB/.boot-gate-failures" +out=$(rig RAUC_OTHER_STATUS=unknown install) +check_has "an uncommitted other slot with a failed gate boot is refused" "$out" "uncommitted" +check "the uncommitted refusal keeps /data clean" "$(staged)" "0" +rm -f "$SB/.boot-gate-failures" + +out=$(rig DF_AVAIL_KB=100 install) +check_has "a bundle larger than free /data is refused with a reason" "$out" "not enough free space on /data" + +out=$(rig CH_TRUNCATE=1 install) +check_has "a truncated file is never verified as complete" "$out" "never verified as complete" +check "the truncated download staged no bundle" "$(staged)" "0" + +out=$(rig RAUC_INFO_FAIL=1 install) +check_has "a mis-signed bundle is refused" "$out" "failed signature verification" +check "the mis-signed bundle is deleted" "$(staged)" "0" + +out=$(rig RAUC_BUNDLE_VERSION=9.9.8 install) +check_has "a stamp mismatch against the tag is refused" "$out" "refusing a version-mismatched file" +check "the mismatched bundle is deleted" "$(staged)" "0" + +out=$(rig RAUC_INSTALL_FAIL=1 install) +check_has "an install failure is refused with a reason" "$out" "could not be installed" +check "the failed install recorded no pending update" "$(state .state)" "refused" +check "the failed install kept nothing staged" "$(staged)" "0" + +rm -f "$SB/os-update-test-base" "$SB/rig-update.json" + +out=$(rig TOR_RC=69 check) +check_has "a failing Tor helper is reported" "$out" "Tor helper ended with status 69" +check "a Tor helper failure is recorded as a refusal" "$(state .state)" "refused" +check_has "the status file names the Tor helper status" "$(state .reason)" "status 69" + +out=$(rig CH_API_RESPONSE="$SB/api-evil-tag.json" check) +check_has "the inner refusal is kept over the wrapper's" "$(state .reason)" "no usable release tag" + +jq -n '{state:"pending",from:"1.3.1",to:"9.9.9",ts:1}' >"$SB/rig-update.json" +out=$(rig TOR_RC=69 check) +check "a Tor helper failure keeps a pending record" "$(state .state)" "pending" +jq -n '{state:"rolled_back",from:"2.0.0",to:"9.9.9",ts:1,reason:"x"}' >"$SB/rig-update.json" +out=$(rig CH_API_RESPONSE="$SB/api-evil-tag.json" check) +check "a refusal keeps a rolled_back verdict" "$(state .state)" "rolled_back" +rm -f "$SB/rig-update.json" + +: >"$SB/curl.log" +out=$(rig CH_HEAD_RC=7 install) +check_has "a failed bundle URL resolve keeps its cause" "$out" "curl exit 7" +check "the failed resolve staged nothing" "$(staged)" "0" + +: >"$SB/curl.log" +rm -f "$SB/rc28.n" +out=$(rig CH_RC28_N=1 install) +dl=$(grep -c 'releases/download' "$SB/curl.log") +check "an rc 28 download resumes and re-resolves the URL every attempt" "$dl" "4" +check "every bundle request is https-only through the Tor SOCKS port" "$(grep 'releases/download' "$SB/curl.log" | grep -c -- '--proto =https --socks5-hostname 127.0.0.1:9253')" "4" +check "the resumed download asked curl to continue" "$(grep 'releases/download' "$SB/curl.log" | grep -c -- ' -C - ')" "2" +check "the resumed install writes the pending record" "$(state .state)" "pending" +check "the resumed install reboots" "$(wc -l <"$tmp/reboot.log" | tr -d ' ')" "1" +rm -f "$SB/rig-update.json" + +printf 'http://seam.invalid/os' >"$SB/os-update-test-base" +rm -f "$SB/rc28.n" +out=$(rig CH_RC28_N=99 install) +check_has "an exhausted resume loop is refused" "$out" "did not finish in 3 attempts" +check "the exhausted download staged nothing" "$(staged)" "0" +check "no reboot after the exhausted download" "$(wc -l <"$tmp/reboot.log" | tr -d ' ')" "1" + +reboots=$(wc -l <"$tmp/reboot.log" | tr -d ' ') +rauc_before=$(grep -c 'rauc install' "$SB/rauc.log") +out=$(rig PITHEAD_RIG_UPDATE_STATE="$SB/nodir/rig-update.json" install) +check_has "an unwritable status file aborts the install" "$out" "status file could not be written" +check "no reboot without a pending record" "$(wc -l <"$tmp/reboot.log" | tr -d ' ')" "$reboots" +check "no slot write without a pending record" "$(grep -c 'rauc install' "$SB/rauc.log")" "$rauc_before" + +for tag in $'v9.9.9\n../../x' 'v9.9.9 ' 'v9.9'; do + out=$(rig install --tag "$tag") + check_has "the tag $(printf '%q' "$tag") is refused" "$out" "vX.Y.Z form" +done + +rauc_n=$(grep -c "rauc install $STAGE/pithead-os-v9.9.9.raucb" "$SB/rauc.log") +out=$(rig install) +check_has "the good install reboots to the spare slot" "$(cat "$tmp/reboot.log")" "reboot" +check "the install ran rauc install once" "$(($(grep -c "rauc install $STAGE/pithead-os-v9.9.9.raucb" "$SB/rauc.log") - rauc_n))" "1" +check "the pending record names the intent" "$(state .state)" "pending" +check "the pending record carries the target version" "$(state .to)" "9.9.9" +check "the bundle is deleted after the install" "$(staged)" "0" + +printf '9.9.9\n' >"$SB/VERSION" +out=$(rig boot-record) +check_has "the boot settles the verdict as updated" "$out" "verdict updated" +check "the status file reads updated" "$(state .state)" "updated" + +printf '2.0.0\n' >"$SB/VERSION" +jq -n '{state:"pending",from:"2.0.0",to:"9.9.9",ts:1}' >"$SB/rig-update.json" +yes x | head -c 10 >"$STAGE/pithead-os-v9.9.9.raucb" +out=$(rig boot-record) +check_has "the fallback boot records the rollback" "$out" "never committed" +check "the fallback verdict is in the status file" "$(state .state)" "rolled_back" +check_has "the fallback names the reason" "$(state .reason)" "miner never came up" +check "the failed slot was marked bad" "$(grep -c 'rauc status mark-bad other' "$SB/rauc.log")" "1" +check "the fallback boot swept the staged bundle" "$(staged)" "0" + +if [ "$FAILURES" -ne 0 ]; then + echo "selftest-rig-update: $FAILURES failed, $PASSES passed" >&2 + exit 1 +fi +echo "selftest-rig-update OK ($PASSES checks)" diff --git a/tests/stack/control/test-control-upgrade.sh b/tests/stack/control/test-control-upgrade.sh index 62966f802..8e093d72e 100644 --- a/tests/stack/control/test-control-upgrade.sh +++ b/tests/stack/control/test-control-upgrade.sh @@ -157,7 +157,7 @@ assert_contains "and says which status came back" "$gh_500" "HTTP 500" assert_eq "every release lookup uses the shared fetch" \ "$(grep -c 'gh_release_fetch p2pool-starter-stack/' "$STACK")" "3" assert_eq "no release lookup dials the API directly any more" \ - "$(grep -c 'api.github.com/repos/.*/releases/latest' "$STACK")" "1" + "$(grep -c 'api.github.com/repos/.*/releases/latest' "$STACK")" "2" # The hint has to reach the CALLER. `rel=$(gh_release_fetch ...)` reads naturally and is a subshell, # so the hint would be set and discarded and every rejection would carry an empty message — the # defect this whole change exists to remove, reintroduced by the refactor that removes it. Neither diff --git a/tests/stack/test-cli-verb-ledger-lock.sh b/tests/stack/test-cli-verb-ledger-lock.sh index a033ed059..439e15a51 100644 --- a/tests/stack/test-cli-verb-ledger-lock.sh +++ b/tests/stack/test-cli-verb-ledger-lock.sh @@ -19,7 +19,7 @@ echo "== domain: the CLI verb ledger accounts for every dispatched verb (#2348) ==" -CVL_COVERED="setup apply render up down restart tor-recover upgrade status doctor backup restore load-images firstboot-wizard local-miner os-update factory-reset control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key uninstall rotate-secrets rotate-dashboard-onion reset-dashboard config-reset recovery-bundle" +CVL_COVERED="setup apply render up down restart tor-recover upgrade status doctor backup restore load-images firstboot-wizard local-miner os-update rig-update factory-reset control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key uninstall rotate-secrets rotate-dashboard-onion reset-dashboard config-reset recovery-bundle" CVL_MISSING="support-bundle render-quadlet" CVL_BYDESIGN="test-alert logs version help" diff --git a/tests/stack/test-readonly-verbs-lock.sh b/tests/stack/test-readonly-verbs-lock.sh index 0bae70e19..b85727585 100644 --- a/tests/stack/test-readonly-verbs-lock.sh +++ b/tests/stack/test-readonly-verbs-lock.sh @@ -157,7 +157,7 @@ kill "$ROVHOLDER" 2>/dev/null # ROV_UNCLAIMED is a floor, not a finding: it is what this domain makes NO claim about, not a set # shown to mutate. Some of it is very likely read-only too; nothing here says so either way. ROV_PROVEN="logs status doctor" -ROV_UNCLAIMED="setup apply render up down restart tor-recover upgrade test-alert support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" +ROV_UNCLAIMED="setup apply render up down restart tor-recover upgrade test-alert support-bundle recovery-bundle reset-dashboard config-reset factory-reset backup restore uninstall firstboot-wizard load-images local-miner os-update rig-update control-run-pending egress-run-pending egress-status lan-guard-check onion-client-key rotate-dashboard-onion rotate-secrets render-quadlet version help" rov_cmds="$( cd "$SANDBOX" || exit