Skip to content

Commit b777459

Browse files
committed
tests/booted: Also verify karg changes
We might as well roll in a bunch of things into this "local container build changes" test. I wanted to get some coverage for kargs, so this adds some. Signed-off-by: Colin Walters <[email protected]>
1 parent c22fd98 commit b777459

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

tests/booted/002-test-image-pushpull-upgrade.nu

+78-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
# bootc image push
33
# podman build <from that image>
44
# bootc switch <to the local image>
5+
# <verify booted state>
6+
# Then another build, and reboot into verifying that
57
use std assert
68
use tap.nu
79

10+
const kargsv0 = ["testarg=foo", "othertestkarg", "thirdkarg=bar"]
11+
const kargsv1 = ["testarg=foo", "thirdkarg=baz"]
12+
let removed = ($kargsv0 | filter { not ($in in $kargsv1) })
13+
814
# This code runs on *each* boot.
915
# Here we just capture information.
1016
bootc status
1117
let st = bootc status --json | from json
12-
let booted = $st.status.booted.image.image
18+
let booted = $st.status.booted.image
19+
20+
# Parse the kernel commandline into a list.
21+
# This is not a proper parser, but good enough
22+
# for what we need here.
23+
def parse_cmdline [] {
24+
open /proc/cmdline | str trim | split row " "
25+
}
1326

1427
# Run on the first boot
1528
def initial_build [] {
@@ -22,8 +35,11 @@ def initial_build [] {
2235
bootc image push
2336
let img = podman image inspect localhost/bootc | from json
2437

25-
# A simple derived container
38+
mkdir usr/lib/bootc/kargs.d
39+
{ kargs: $kargsv0 } | to toml | save usr/lib/bootc/kargs.d/05-testkargs.toml
40+
# A simple derived container that adds a file, but also injects some kargs
2641
"FROM localhost/bootc
42+
COPY usr/ /usr/
2743
RUN echo test content > /usr/share/blah.txt
2844
" | save Dockerfile
2945
# Build it
@@ -39,10 +55,66 @@ RUN echo test content > /usr/share/blah.txt
3955

4056
# The second boot; verify we're in the derived image
4157
def second_boot [] {
42-
assert equal $booted.transport containers-storage
43-
assert equal $booted.image localhost/bootc-derived
58+
print "verifying second boot"
59+
# booted from the local container storage and image
60+
assert equal $booted.image.transport containers-storage
61+
assert equal $booted.image.image localhost/bootc-derived
62+
# We wrote this file
4463
let t = open /usr/share/blah.txt | str trim
4564
assert equal $t "test content"
65+
66+
# Verify we have updated kargs
67+
let cmdline = parse_cmdline
68+
print $"cmdline=($cmdline)"
69+
for x in $kargsv0 {
70+
print $"verifying karg: ($x)"
71+
assert ($x in $cmdline)
72+
}
73+
74+
# Now do another build where we drop one of the kargs
75+
let td = mktemp -d
76+
cd $td
77+
78+
mkdir usr/lib/bootc/kargs.d
79+
{ kargs: $kargsv1 } | to toml | save usr/lib/bootc/kargs.d/05-testkargs.toml
80+
"FROM localhost/bootc
81+
COPY usr/ /usr/
82+
RUN echo test content2 > /usr/share/blah.txt
83+
" | save Dockerfile
84+
# Build it
85+
podman build -t localhost/bootc-derived .
86+
let booted_digest = $booted.imageDigest
87+
print booted_digest = $booted_digest
88+
# We should already be fetching updates from container storage
89+
bootc upgrade
90+
# Verify we staged an update
91+
let st = bootc status --json | from json
92+
let staged_digest = $st.status.staged.image.imageDigest
93+
assert ($booted_digest != $staged_digest)
94+
# And reboot into the upgrade
95+
tmt-reboot
96+
}
97+
98+
# Check we have the updated kargs
99+
def third_boot [] {
100+
print "verifying third boot"
101+
assert equal $booted.image.transport containers-storage
102+
assert equal $booted.image.image localhost/bootc-derived
103+
let t = open /usr/share/blah.txt | str trim
104+
assert equal $t "test content2"
105+
106+
# Verify we have updated kargs
107+
let cmdline = parse_cmdline
108+
print $"cmdline=($cmdline)"
109+
for x in $kargsv1 {
110+
print $"Verifying karg ($x)"
111+
assert ($x in $cmdline)
112+
}
113+
# And the kargs that should be removed are gone
114+
for x in $removed {
115+
assert not ($removed in $cmdline)
116+
}
117+
46118
tap ok
47119
}
48120

@@ -51,6 +123,7 @@ def main [] {
51123
match $env.TMT_REBOOT_COUNT? {
52124
null | "0" => initial_build,
53125
"1" => second_boot,
54-
$o => { error make {msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
126+
"2" => third_boot,
127+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
55128
}
56129
}

0 commit comments

Comments
 (0)