Skip to content

Commit d4c19f7

Browse files
committed
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 <[email protected]>
1 parent b696395 commit d4c19f7

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: sudo apt update && sudo apt install just
5757
- uses: actions/checkout@v4
5858
- name: Build and run container integration tests
59-
run: sudo just run-container-integration
59+
run: sudo just run-container-integration run-container-external-tests
6060
cargo-deny:
6161
runs-on: ubuntu-latest
6262
steps:

Justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ build-integration-test-image *ARGS: build
1010
run-container-integration: build-integration-test-image
1111
podman run --rm localhost/bootc-integration bootc-integration-tests container
1212

13+
# These tests may spawn their own container images.
14+
run-container-external-tests:
15+
./tests/container/run localhost/bootc
16+
1317
unittest *ARGS:
1418
podman build --jobs=4 --target units -t localhost/bootc-units --build-arg=unitargs={{ARGS}} .
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
ConditionPathExists=!/etc/initrd-release
3+
After=local-fs.target
4+
RequiresMountsFor=/run/bootc-test-reboot
5+
Before=bootc-test-reboot.service
6+
PartOf=bootc-test-reboot.service
7+
8+
[Service]
9+
Type=oneshot
10+
RemainAfterExit=yes
11+
ExecStop=touch /run/bootc-test-reboot/success
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
ConditionPathExists=!/etc/initrd-release
3+
Requires=bootc-finish-test-reboot.service
4+
After=bootc-finish-test-reboot.service
5+
6+
[Service]
7+
Type=oneshot
8+
RemainAfterExit=yes
9+
ExecStart=bootc internals reboot
10+
11+
[Install]
12+
WantedBy=multi-user.target

tests/container/reboot/run

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Verify that invoking `bootc internals reboot` actually invokes a reboot, when
3+
# running inside systemd.
4+
# xref:
5+
# - https://github.com/bootc-dev/bootc/issues/1416
6+
# - https://github.com/bootc-dev/bootc/issues/1419
7+
set -euo pipefail
8+
image=$1
9+
tmpd=$(mktemp -d)
10+
log() {
11+
echo "$@"
12+
"$@"
13+
}
14+
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
15+
ls -al $tmpd
16+
if test '!' -f $tmpd/success; then
17+
echo "reboot failed" 1>&2
18+
rm -rf "$tmpd"
19+
exit 1
20+
fi
21+
rm -rf "$tmpd"
22+
echo "ok reboot"

tests/container/run

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
image=$1
4+
shift
5+
6+
cd $(dirname $0)
7+
8+
tests=$(find . -maxdepth 1 -type d)
9+
for case in $tests; do
10+
if test $case = .; then continue; fi
11+
echo "Running: $case"
12+
cd $case
13+
./run $image
14+
cd -
15+
echo "ok $case"
16+
done

0 commit comments

Comments
 (0)