|
| 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 | +} |
0 commit comments