1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 06:45:13 +01:00

tests: Add a suite which runs tests under systemd

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 <walters@verbum.org>
This commit is contained in:
Colin Walters
2025-07-17 14:38:21 -04:00
parent b696395744
commit d4c19f7d31
6 changed files with 66 additions and 1 deletions

View File

@@ -56,7 +56,7 @@ jobs:
run: sudo apt update && sudo apt install just
- uses: actions/checkout@v4
- name: Build and run container integration tests
run: sudo just run-container-integration
run: sudo just run-container-integration run-container-external-tests
cargo-deny:
runs-on: ubuntu-latest
steps:

View File

@@ -10,5 +10,9 @@ build-integration-test-image *ARGS: build
run-container-integration: build-integration-test-image
podman run --rm localhost/bootc-integration bootc-integration-tests container
# These tests may spawn their own container images.
run-container-external-tests:
./tests/container/run localhost/bootc
unittest *ARGS:
podman build --jobs=4 --target units -t localhost/bootc-units --build-arg=unitargs={{ARGS}} .

View File

@@ -0,0 +1,11 @@
[Unit]
ConditionPathExists=!/etc/initrd-release
After=local-fs.target
RequiresMountsFor=/run/bootc-test-reboot
Before=bootc-test-reboot.service
PartOf=bootc-test-reboot.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=touch /run/bootc-test-reboot/success

View File

@@ -0,0 +1,12 @@
[Unit]
ConditionPathExists=!/etc/initrd-release
Requires=bootc-finish-test-reboot.service
After=bootc-finish-test-reboot.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=bootc internals reboot
[Install]
WantedBy=multi-user.target

22
tests/container/reboot/run Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# Verify that invoking `bootc internals reboot` actually invokes a reboot, when
# running inside systemd.
# xref:
# - https://github.com/bootc-dev/bootc/issues/1416
# - https://github.com/bootc-dev/bootc/issues/1419
set -euo pipefail
image=$1
tmpd=$(mktemp -d)
log() {
echo "$@"
"$@"
}
log timeout 120 podman run --rm --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"

16
tests/container/run Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
image=$1
shift
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