Skip to content

Conversation

@cgwalters
Copy link
Collaborator

Followup to bd6b372

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new internal reboot command and an integration test to verify its functionality. The changes to the Rust code are straightforward and look correct. My review focuses on the new shell scripts, where I've identified opportunities to improve robustness and portability. Overall, this is a valuable addition for ensuring the reliability of the reboot mechanism.

Comment on lines 9 to 22
tmpd=$(mktemp -d)
log() {
echo "$@"
"$@"
}
log timeout -f 120 podman run --rm -ti --systemd=always --privileged -v /sys:/sys:ro --label bootc.test=reboot --net=none -v $(pwd):/src:ro -v $tmpd:/run/bootc-test-reboot $image /bin/sh -c 'cp /src/*.service /etc/systemd/system && systemctl enable bootc-test-reboot && exec /sbin/init' || true
ls -al $tmpd
if test '!' -f $tmpd/success; then
echo "reboot failed" 1>&2
rm -rf "$tmpd"
exit 1
fi
rm -rf "$tmpd"
echo "ok reboot"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a trap ensures the temporary directory created by mktemp is cleaned up reliably, even if the script is interrupted. This also simplifies the script by removing duplicated rm commands.

tmpd=$(mktemp -d)
trap 'rm -rf -- "$tmpd"' EXIT
log() {
  echo "$@"
  "$@"
}
log timeout 120 podman run --rm -ti --systemd=always --privileged -v /sys:/sys:ro --label bootc.test=reboot --net=none -v "$(pwd)":/src:ro -v "$tmpd":/run/bootc-test-reboot "$image" /bin/sh -c 'cp /src/*.service /etc/systemd/system && systemctl enable bootc-test-reboot && exec /sbin/init' || true
ls -al "$tmpd"
if [ ! -f "$tmpd/success" ]; then
  echo "reboot failed" >&2
  exit 1
fi
echo "ok reboot"

echo "$@"
"$@"
}
log timeout -f 120 podman run --rm -ti --systemd=always --privileged -v /sys:/sys:ro --label bootc.test=reboot --net=none -v $(pwd):/src:ro -v $tmpd:/run/bootc-test-reboot $image /bin/sh -c 'cp /src/*.service /etc/systemd/system && systemctl enable bootc-test-reboot && exec /sbin/init' || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Several variables ($(pwd), $tmpd, $image) are unquoted. They should be quoted to prevent issues if their values contain spaces or special characters.

log timeout -f 120 podman run --rm -ti --systemd=always --privileged -v /sys:/sys:ro --label bootc.test=reboot --net=none -v "$(pwd)":/src:ro -v "$tmpd":/run/bootc-test-reboot "$image" /bin/sh -c 'cp /src/*.service /etc/systemd/system && systemctl enable bootc-test-reboot && exec /sbin/init' || true

Comment on lines +9 to +16
for case in $tests; do
if test $case = .; then continue; fi
echo "Running: $case"
cd $case
./run $image
cd -
echo "ok $case"
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The for case in $tests loop is subject to word splitting, which will cause issues with directory names that contain spaces or other special characters. Using a while read loop with find -print0 is the standard, robust way to iterate over find's output.

find . -maxdepth 1 -type d -print0 | while IFS= read -r -d '' case; do
  if [ "$case" = "." ]; then continue; fi
  echo "Running: $case"
  cd $case
  ./run $image
  cd -
  echo "ok $case"
done

Comment on lines +6 to +16
cd $(dirname $0)

tests=$(find . -maxdepth 1 -type d)
for case in $tests; do
if test $case = .; then continue; fi
echo "Running: $case"
cd $case
./run $image
cd -
echo "ok $case"
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Path variables like $(dirname "$0") and $case should be quoted.

cd "$(dirname "$0")"

find . -maxdepth 1 -type d -print0 | while IFS= read -r -d '' case; do
  if [ "$case" = "." ]; then continue; fi
  echo "Running: $case"
  cd "$case"
  ./run $image
  cd -
  echo "ok $case"
done

Comment on lines +12 to +14
cd $case
./run $image
cd -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a subshell (...) to run commands in a different directory is often cleaner and safer than cd ...; cd -.

find . -maxdepth 1 -type d -print0 | while IFS= read -r -d '' case; do
  if [ "$case" = "." ]; then continue; fi
  echo "Running: $case"
  (
    cd -- "$case" && ./run "$image"
  )
  echo "ok $case"
done

This is intended to aid unit testing outside of `upgrade --apply`.

Signed-off-by: Colin Walters <[email protected]>
And add a single test which verifies that our internal `reboot`
code actually does what it should (via systemd-run etc.)

This took me way, way too long to do...there were so many missteps
and confusion. First of all, I kept trying to use `systemd.extra-unit`
from https://www.freedesktop.org/software/systemd/man/latest/systemd-debug-generator.html#
but that doesn't exist in stream9.

I spent way too long trying to debug the fact that switching from
`podman run <image> /sbin/init` to `podman run <image> /bin/sh -c '<stuff> && exec /sbin/init`
fails because in the latter case podman's auto-detection fails and
we need to explicitly say `--systemd=always`. In retrospect obvious...but oh well.

On the positive side, I think with some cleanup we could extend this model
and generalize it for "test running in a container with systemd" (with
a lot of cleanup really)

Signed-off-by: Colin Walters <[email protected]>
Copy link
Contributor

@jmarrero jmarrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cgwalters cgwalters enabled auto-merge July 18, 2025 13:12
@cgwalters cgwalters merged commit 03fa72b into bootc-dev:main Jul 18, 2025
35 of 36 checks passed
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.

2 participants