Skip to content

Commit b975721

Browse files
committed
test: add integration tests for 'bootc switch --apply'
Signed-off-by: Robert Sturla <[email protected]>
1 parent b290ad2 commit b975721

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

tmt/plans/integration.fmf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ execute:
5454
test:
5555
- /tmt/tests/bootc-install-provision
5656
- /tmt/tests/test-23-install-outside-container
57+
58+
/test-24-local-upgrade-reboot:
59+
summary: Execute local upgrade tests with automated reboot
60+
discover:
61+
how: fmf
62+
test:
63+
- /tmt/tests/bootc-install-provision
64+
- /tmt/tests/test-24-local-upgrade-reboot
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This test does:
2+
# bootc image copy-to-storage
3+
# podman build <from that image>
4+
# bootc switch <into that image> --apply
5+
# Verify we boot into the new image
6+
#
7+
use std assert
8+
use tap.nu
9+
10+
const kargsv0 = ["testarg=foo", "othertestkarg", "thirdkarg=bar"]
11+
12+
# This code runs on *each* boot.
13+
# Here we just capture information.
14+
bootc status
15+
let st = bootc status --json | from json
16+
let booted = $st.status.booted.image
17+
18+
# Parse the kernel commandline into a list.
19+
# This is not a proper parser, but good enough
20+
# for what we need here.
21+
def parse_cmdline [] {
22+
open /proc/cmdline | str trim | split row " "
23+
}
24+
25+
# Run on the first boot
26+
def initial_build [] {
27+
tap begin "local image push + pull + upgrade"
28+
29+
bootc image copy-to-storage
30+
let img = podman image inspect localhost/bootc | from json
31+
32+
mkdir usr/lib/bootc/kargs.d
33+
{ kargs: $kargsv0 } | to toml | save usr/lib/bootc/kargs.d/05-testkargs.toml
34+
# A simple derived container that adds a file, but also injects some kargs
35+
"FROM localhost/bootc
36+
COPY usr/ /usr/
37+
" | save Dockerfile
38+
# Build it
39+
podman build -t localhost/bootc-derived .
40+
41+
let orig_root_mtime = ls -Dl /ostree/bootc | get modified
42+
43+
# Now, switch into the new image
44+
bash -c $"bootc switch --apply --transport containers-storage localhost/bootc-derived"
45+
46+
# We cannot perform any other checks here since the system will be automatically rebooted
47+
}
48+
49+
# Check we have the updated image
50+
def second_boot [] {
51+
print "verifying second boot"
52+
assert equal $booted.image.transport containers-storage
53+
assert equal $booted.image.image localhost/bootc-derived
54+
55+
# Verify we have updated kargs
56+
let cmdline = parse_cmdline
57+
print $"cmdline=($cmdline)"
58+
for x in $kargsv0 {
59+
print $"Verifying karg ($x)"
60+
assert ($x in $cmdline)
61+
}
62+
63+
tap ok
64+
}
65+
66+
def main [] {
67+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
68+
match $env.TMT_REBOOT_COUNT? {
69+
null | "0" => initial_build,
70+
"1" => second_boot,
71+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
72+
}
73+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
summary: Execute local upgrade tests
2+
test: nu booted/test-image-pushpull-upgrade-reboot.nu
3+
duration: 30m

0 commit comments

Comments
 (0)