Skip to content

Commit

Permalink
tests/booted: Also verify karg changes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cgwalters committed Jun 23, 2024
1 parent f67eb6c commit 5c5b02a
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions tests/booted/002-test-image-pushpull-upgrade.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@
# bootc image push
# podman build <from that image>
# bootc switch <to the local image>
# <verify booted state>
# Then another build, and reboot into verifying that
use std assert
use tap.nu

const kargsv0 = ["testarg=foo", "othertestkarg", "thirdkarg=bar"]
const kargsv1 = ["testarg=foo", "thirdkarg=baz"]
let removed = ($kargsv0 | filter { not ($in in $kargsv1) })

# This code runs on *each* boot.
# Here we just capture information.
bootc status
let st = bootc status --json | from json
let booted = $st.status.booted.image.image
let booted = $st.status.booted.image

# Parse the kernel commandline into a list.
# This is not a proper parser, but good enough
# for what we need here.
def parse_cmdline [] {
open /proc/cmdline | str trim | split row " "
}

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

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

# The second boot; verify we're in the derived image
def second_boot [] {
assert equal $booted.transport containers-storage
assert equal $booted.image localhost/bootc-derived
print "verifying second boot"
# booted from the local container storage and image
assert equal $booted.image.transport containers-storage
assert equal $booted.image.image localhost/bootc-derived
# We wrote this file
let t = open /usr/share/blah.txt | str trim
assert equal $t "test content"

# Verify we have updated kargs
let cmdline = parse_cmdline
print $"cmdline=($cmdline)"
for x in $kargsv0 {
print $"verifying karg: ($x)"
assert ($x in $cmdline)
}

# Now do another build where we drop one of the kargs
let td = mktemp -d
cd $td

mkdir usr/lib/bootc/kargs.d
{ kargs: $kargsv1 } | to toml | save usr/lib/bootc/kargs.d/05-testkargs.toml
"FROM localhost/bootc
COPY usr/ /usr/
RUN echo test content2 > /usr/share/blah.txt
" | save Dockerfile
# Build it
podman build -t localhost/bootc-derived .
let booted_digest = $booted.imageDigest
print booted_digest = $booted_digest
# We should already be fetching updates from container storage
bootc upgrade
# Verify we staged an update
let st = bootc status --json | from json
let staged_digest = $st.status.staged.image.imageDigest
assert ($booted_digest != $staged_digest)
# And reboot into the upgrade
tmt-reboot
}

# Check we have the updated kargs
def third_boot [] {
print "verifying third boot"
assert equal $booted.image.transport containers-storage
assert equal $booted.image.image localhost/bootc-derived
let t = open /usr/share/blah.txt | str trim
assert equal $t "test content2"

# Verify we have updated kargs
let cmdline = parse_cmdline
print $"cmdline=($cmdline)"
for x in $kargsv1 {
print $"Verifying karg ($x)"
assert ($x in $cmdline)
}
# And the kargs that should be removed are gone
for x in $removed {
assert not ($removed in $cmdline)
}

tap ok
}

Expand All @@ -51,6 +123,7 @@ def main [] {
match $env.TMT_REBOOT_COUNT? {
null | "0" => initial_build,
"1" => second_boot,
$o => { error make {msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
"2" => third_boot,
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
}
}

0 comments on commit 5c5b02a

Please sign in to comment.