|
| 1 | +# This test does: |
| 2 | +# bootc image copy-to-storage |
| 3 | +# podman build <from that image> |
| 4 | +# bootc switch <to the local image> |
| 5 | +# <verify booted state> |
| 6 | +# Then another build, and reboot into verifying that |
| 7 | +use std assert |
| 8 | +use tap.nu |
| 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 | + |
| 14 | +# This code runs on *each* boot. |
| 15 | +# Here we just capture information. |
| 16 | +bootc status |
| 17 | +let st = bootc status --json | from json |
| 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 | +} |
| 26 | + |
| 27 | +# Run on the first boot |
| 28 | +def initial_build [] { |
| 29 | + tap begin "local image push + pull + upgrade" |
| 30 | + |
| 31 | + let td = mktemp -d |
| 32 | + cd $td |
| 33 | + |
| 34 | + do --ignore-errors { podman image rm localhost/bootc o+e>| ignore } |
| 35 | + bootc image copy-to-storage |
| 36 | + let img = podman image inspect localhost/bootc | from json |
| 37 | + |
| 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 |
| 41 | + "FROM localhost/bootc |
| 42 | +COPY usr/ /usr/ |
| 43 | +RUN echo test content > /usr/share/blah.txt |
| 44 | +" | save Dockerfile |
| 45 | + # Build it |
| 46 | + podman build -t localhost/bootc-derived . |
| 47 | + # Just sanity check it |
| 48 | + let v = podman run --rm localhost/bootc-derived cat /usr/share/blah.txt | str trim |
| 49 | + assert equal $v "test content" |
| 50 | + # Now, fetch it back into the bootc storage! |
| 51 | + bootc switch --transport containers-storage localhost/bootc-derived |
| 52 | + # And reboot into it |
| 53 | + tmt-reboot |
| 54 | +} |
| 55 | + |
| 56 | +# The second boot; verify we're in the derived image |
| 57 | +def second_boot [] { |
| 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 |
| 63 | + let t = open /usr/share/blah.txt | str trim |
| 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 | + |
| 118 | + tap ok |
| 119 | +} |
| 120 | + |
| 121 | +def main [] { |
| 122 | + # See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test |
| 123 | + match $env.TMT_REBOOT_COUNT? { |
| 124 | + null | "0" => initial_build, |
| 125 | + "1" => second_boot, |
| 126 | + "2" => third_boot, |
| 127 | + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, |
| 128 | + } |
| 129 | +} |
0 commit comments