Skip to content

Commit 03fa72b

Browse files
authored
Merge pull request #1426 from cgwalters/test-reboot
Add a test case for our internal reboot command
2 parents 4e433ed + d4c19f7 commit 03fa72b

File tree

7 files changed

+70
-1
lines changed

7 files changed

+70
-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}} .

crates/lib/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ pub(crate) enum InternalsOpts {
472472
// The stateroot
473473
stateroot: String,
474474
},
475+
/// Initiate a reboot the same way we would after --apply; intended
476+
/// primarily for testing.
477+
Reboot,
475478
#[cfg(feature = "rhsm")]
476479
/// Publish subscription-manager facts to /etc/rhsm/facts/bootc.facts
477480
PublishRhsmFacts,
@@ -1230,6 +1233,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
12301233
Ok(())
12311234
}
12321235
},
1236+
InternalsOpts::Reboot => crate::reboot::reboot(),
12331237
InternalsOpts::Fsck => {
12341238
let sysroot = &get_storage().await?;
12351239
crate::fsck::fsck(&sysroot, std::io::stdout().lock()).await?;
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)