From 92d95685f76c35c555a80602c12be3fec19d70fb Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 23 Jun 2024 08:47:32 -0400 Subject: [PATCH] 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 --- .../booted/002-test-image-pushpull-upgrade.nu | 83 +++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/tests/booted/002-test-image-pushpull-upgrade.nu b/tests/booted/002-test-image-pushpull-upgrade.nu index 3d9e3bbfe..f73ccc663 100644 --- a/tests/booted/002-test-image-pushpull-upgrade.nu +++ b/tests/booted/002-test-image-pushpull-upgrade.nu @@ -2,14 +2,27 @@ # bootc image push # podman build # bootc switch +# +# 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 [] { @@ -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 @@ -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 } @@ -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)" } }, } }