2
2
# bootc image push
3
3
# podman build <from that image>
4
4
# bootc switch <to the local image>
5
+ # <verify booted state>
6
+ # Then another build, and reboot into verifying that
5
7
use std assert
6
8
use tap .nu
7
9
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
+
8
14
# This code runs on *each* boot.
9
15
# Here we just capture information.
10
16
bootc status
11
17
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
+ }
13
26
14
27
# Run on the first boot
15
28
def initial_build [] {
@@ -22,8 +35,11 @@ def initial_build [] {
22
35
bootc image push
23
36
let img = podman image inspect localhost/bootc | from json
24
37
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
26
41
" FROM localhost/bootc
42
+ COPY usr/ /usr/
27
43
RUN echo test content > /usr/share/blah.txt
28
44
" | save Dockerfile
29
45
# Build it
@@ -39,10 +55,66 @@ RUN echo test content > /usr/share/blah.txt
39
55
40
56
# The second boot; verify we're in the derived image
41
57
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
44
63
let t = open /usr/share/blah.txt | str trim
45
64
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
+
46
118
tap ok
47
119
}
48
120
@@ -51,6 +123,7 @@ def main [] {
51
123
match $env .TMT_REBOOT_COUNT ? {
52
124
null | " 0" => initial_build ,
53
125
" 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 )" } },
55
128
}
56
129
}
0 commit comments