From ca7d22384bca6133c0e177d1c6f06c3b87f5b71a Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Wed, 23 Sep 2026 18:46:16 -0400 Subject: [PATCH] deploy: apply helper reboots only when the rollback itself failed Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01KqhjP7nud5gdBg25zCiRk9 --- deploy.sh | 5 ++++- tests/check-templates.sh | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index c0ff8c7..a05bb93 100755 --- a/deploy.sh +++ b/deploy.sh @@ -345,10 +345,13 @@ restore() { # restore : put the pre-run netplan back, re-check connecti if [ "\$rb" = ok ] && [ "\$c" = ok ]; then echo "apply-network ROLLED BACK (restored, connectivity ok)" status rolled-back "\$1" + elif [ "\$rb" = ok ]; then + echo "apply-network ROLLED BACK (restored, but no connectivity - check the uplink/cable)" + status rolled-back restored-no-connectivity else echo "apply-network ROLLBACK FAILED: \$rb / connectivity \$c" status rollback-failed "\$1; \$rb / connectivity \$c" - [ "\$c" = ok ] || { echo "no connectivity after rollback - rebooting"; systemctl reboot; } + [ "\$c" = ok ] || { echo "rollback failed and no connectivity - rebooting (boot uses the files on disk)"; systemctl reboot; } fi exit 1 } diff --git a/tests/check-templates.sh b/tests/check-templates.sh index abc3fb6..87b8db1 100755 --- a/tests/check-templates.sh +++ b/tests/check-templates.sh @@ -354,10 +354,18 @@ STUB a_is "stage2: exit 1" "$rc" 1; a_is "stage2: status" "$(st_word)" rolled-back [ ! -e "$sb/netplan/50-van-wan.yaml" ] && [ -e "$sb/netplan/10-dhcp-all-interfaces.yaml" ] && ok "apply helper stage2: restored" || bad "apply helper stage2: not restored" rm -rf "$sb" - # (6) no connectivity even after rollback: last-resort reboot + # (6) clean rollback but no connectivity (uplink unplugged): must NOT reboot an_run STUB_ROUTE=none - a_is "no connectivity: status" "$(st_word)" rollback-failed - grep -q '^systemctl reboot' "$sb/calls" && ok "apply helper: reboots when connectivity is not back after rollback" || bad "apply helper: no reboot" + a_is "no connectivity after clean rollback: exit" "$rc" 1 + a_is "no connectivity after clean rollback: status" "$(cat "$sb/status" 2>/dev/null | cut -d' ' -f1,3)" "rolled-back restored-no-connectivity" + grep -q 'restored, but no connectivity' "$sb/log" && ok "apply helper: no-connectivity log" || bad "apply helper: no-connectivity log" + grep -q '^systemctl reboot' "$sb/calls" && bad "apply helper: must not reboot after a clean rollback" || ok "apply helper: no reboot after a clean rollback" + [ -e "$sb/netplan/10-dhcp-all-interfaces.yaml" ] && [ ! -e "$sb/netplan/50-van-wan.yaml" ] && ok "apply helper: clean rollback restored files" || bad "apply helper: clean rollback files" + rm -rf "$sb" + # (7) rollback cp fails AND no connectivity: last-resort reboot + AN_NOBAK=1 an_run STUB_ROUTE=none + a_is "failed rollback, no connectivity: status" "$(st_word)" rollback-failed + grep -q '^systemctl reboot' "$sb/calls" && ok "apply helper: reboots when the rollback failed and connectivity is absent" || bad "apply helper: no reboot after failed rollback" rm -rf "$sb" rm -rf "$stubs" fi