Skip to content

fix: stop preparation when installs fail - #1048

Draft
xtrusia wants to merge 1 commit into
canonical:mainfrom
xtrusia:fix/prepare-node-install-failures
Draft

xtrusia wants to merge 1 commit into
canonical:mainfrom
xtrusia:fix/prepare-node-install-failures

Conversation

@xtrusia

@xtrusia xtrusia commented Nov 26, 2026

Copy link
Copy Markdown

The generated preparation script kept going when a package, Juju or LXD install failed, and it could still exit 0. The failure only showed up later in sunbeam cluster join, as in the bug report. I made each of those three installs exit with its own status.

I didn't add set -e to the whole script as the bug suggests. Several lines rely on a failing command on purpose (the grep ... || {...} checks, juju show-controller followed by $?), so that would change a lot more behaviour.

Partial-bug: #2068935

QA steps

From sunbeam-python/:

  • tox -e unit,pep8,mypy: 4,745 unit tests passed, pep8 and mypy passed.
  • tests/unit/sunbeam/commands/test_prepare_node.py runs each template in bash with a stubbed sudo. An install that returns 42 must make the script exit 42 before the next step, and status 0 must continue. On the base commit the three failure cases fail with assert 0 == 42.

I also ran the rendered templates on a fresh Ubuntu 24.04 VM, as the ubuntu user. I rendered PREPARE_NODE_TEMPLATE, COMMON_TEMPLATE and BOOTSTRAP_TEMPLATE from this branch (new) and from main (old) into files, and ran each one up to a marker line with this helper:

#!/bin/bash
# usage: cut.sh <template> <stop-marker>  -> runs template lines before marker, then prints REACHED_END
tpl=$1; marker=$2
awk -v m="$marker" "index(\$0, m)==1{exit} {print}" "$tpl" > /tmp/run.sh
echo "echo REACHED_END" >> /tmp/run.sh
bash /tmp/run.sh > /tmp/out.log 2>&1
rc=$?
echo "== $tpl rc=$rc reached=$(grep -c REACHED_END /tmp/out.log)"

Re-runs with everything already installed still pass:

Case Command Result
lxd installed from 5.21/stable ./cut.sh new_bootstrap.sh "# Bootstrap juju onto LXD" rc=0, reached end (sudo snap install lxd --channel 5.21/stable alone prints "already installed" and returns 0)
lxd refreshed to latest/stable same rc=0, reached end, lxd stays on latest/stable
juju 3.6/stable installed ./cut.sh new_common.sh "# Workaround a bug between snapd and juju" rc=0, "Using existing Juju installation."
openssh-server, curl, sed installed ./cut.sh new_prepare.sh '# Add $USER to the snap_daemon group' rc=0, reached end

Install failures now stop the script:

Case Old New
lxd not installed, snapd proxy set to http://127.0.0.1:9 (./cut.sh <v>_bootstrap.sh "if [ -n") rc=0, reached end rc=1, stopped after cannot install "lxd"
juju not installed, same snapd proxy (./cut.sh <v>_common.sh "# Workaround a bug between snapd and juju") rc=0, reached end rc=1, stopped after cannot install "juju"
curl removed, apt proxy set to http://127.0.0.1:9 (./cut.sh <v>_prepare.sh '# Add $USER to the snap_daemon group') rc=0, reached end rc=100, stopped after Failed to fetch ... curl

Links

Jira card: N/A

The generated preparation script kept going after a failed package,
Juju or LXD installation and could still exit 0, so the failure only
showed up later in sunbeam commands. Exit with the failing install
command's status instead.

Partial-Bug: #2068935
Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant