|
| 1 | +# number: 37 |
| 2 | +# tmt: |
| 3 | +# summary: Verify upgrade --check populates cached update in status |
| 4 | +# duration: 30m |
| 5 | +# extra: |
| 6 | +# fixme_skip_if_composefs: true |
| 7 | +# |
| 8 | +# TODO: This test uses containers-storage transport which is not yet |
| 9 | +# supported on the composefs backend. Remove the skip once composefs |
| 10 | +# supports copy-to-storage / switch --transport containers-storage. |
| 11 | +# |
| 12 | +# This test verifies that `bootc upgrade --check` caches registry |
| 13 | +# metadata and that `bootc status` renders the cached update. |
| 14 | +# Flow: |
| 15 | +# 1. Build derived image v1, switch to it, reboot |
| 16 | +# 2. Build v2, run `bootc upgrade --check`, verify status shows v2 as cached update |
| 17 | +# 3. Build v3, run `bootc upgrade --check` again, verify status now shows v3 |
| 18 | +use std assert |
| 19 | +use tap.nu |
| 20 | + |
| 21 | +# This code runs on *each* boot. |
| 22 | +bootc status |
| 23 | +let st = bootc status --json | from json |
| 24 | +let booted = $st.status.booted.image |
| 25 | + |
| 26 | +def imgsrc [] { |
| 27 | + "localhost/bootc-test-check" |
| 28 | +} |
| 29 | + |
| 30 | +# Run on the first boot - build v1 and switch to it |
| 31 | +def initial_build [] { |
| 32 | + tap begin "upgrade --check cached update in status" |
| 33 | + |
| 34 | + bootc image copy-to-storage |
| 35 | + |
| 36 | + # A simple derived container that adds a file with a version label |
| 37 | + "FROM localhost/bootc |
| 38 | +LABEL org.opencontainers.image.version=v1 |
| 39 | +RUN echo v1 > /usr/share/test-upgrade-check |
| 40 | +" | save Dockerfile |
| 41 | + podman build -t (imgsrc) . |
| 42 | + |
| 43 | + # Switch into the derived image |
| 44 | + bootc switch --transport containers-storage (imgsrc) |
| 45 | + tmt-reboot |
| 46 | +} |
| 47 | + |
| 48 | +# Second boot: verify on v1, then test upgrade --check with v2 and v3 |
| 49 | +def second_boot [] { |
| 50 | + print "verifying second boot - should be on v1" |
| 51 | + assert equal $booted.image.transport containers-storage |
| 52 | + assert equal $booted.image.image (imgsrc) |
| 53 | + |
| 54 | + let v1_content = open /usr/share/test-upgrade-check | str trim |
| 55 | + assert equal $v1_content "v1" |
| 56 | + |
| 57 | + let booted_digest = $booted.imageDigest |
| 58 | + print $"booted digest: ($booted_digest)" |
| 59 | + |
| 60 | + # Initially there should be no cached update |
| 61 | + let initial_status = bootc status --json | from json |
| 62 | + assert ($initial_status.status.booted.cachedUpdate == null) "No cached update initially" |
| 63 | + |
| 64 | + # Build v2 with same tag - this is a newer image |
| 65 | + "FROM localhost/bootc |
| 66 | +LABEL org.opencontainers.image.version=v2 |
| 67 | +RUN echo v2 > /usr/share/test-upgrade-check |
| 68 | +" | save --force Dockerfile |
| 69 | + podman build -t (imgsrc) . |
| 70 | + |
| 71 | + # Run upgrade --check (metadata only, no deployment) |
| 72 | + print "Running bootc upgrade --check for v2" |
| 73 | + bootc upgrade --check |
| 74 | + |
| 75 | + # Verify status now shows cached update |
| 76 | + let status_after_v2 = bootc status --json | from json |
| 77 | + assert ($status_after_v2.status.booted.cachedUpdate != null) "cachedUpdate should be populated after upgrade --check" |
| 78 | + |
| 79 | + let v2_cached = $status_after_v2.status.booted.cachedUpdate |
| 80 | + print $"v2 cached digest: ($v2_cached.imageDigest)" |
| 81 | + assert ($v2_cached.imageDigest != $booted_digest) "Cached update digest should differ from booted" |
| 82 | + |
| 83 | + # Verify human-readable output contains update info |
| 84 | + let human_output = bootc status --format humanreadable |
| 85 | + print $"Human output:\n($human_output)" |
| 86 | + assert ($human_output | str contains "UpdateVersion:") "Human-readable output should show UpdateVersion line" |
| 87 | + assert ($human_output | str contains "UpdateDigest:") "Human-readable output should show UpdateDigest line" |
| 88 | + |
| 89 | + # Now build v3 - another update on the same tag |
| 90 | + "FROM localhost/bootc |
| 91 | +LABEL org.opencontainers.image.version=v3 |
| 92 | +RUN echo v3 > /usr/share/test-upgrade-check |
| 93 | +" | save --force Dockerfile |
| 94 | + podman build -t (imgsrc) . |
| 95 | + |
| 96 | + # Run upgrade --check again |
| 97 | + print "Running bootc upgrade --check for v3" |
| 98 | + bootc upgrade --check |
| 99 | + |
| 100 | + # Verify status now shows v3 as the cached update (not v2) |
| 101 | + let status_after_v3 = bootc status --json | from json |
| 102 | + assert ($status_after_v3.status.booted.cachedUpdate != null) "cachedUpdate should still be populated" |
| 103 | + |
| 104 | + let v3_cached = $status_after_v3.status.booted.cachedUpdate |
| 105 | + print $"v3 cached digest: ($v3_cached.imageDigest)" |
| 106 | + assert ($v3_cached.imageDigest != $booted_digest) "v3 cached digest should differ from booted" |
| 107 | + assert ($v3_cached.imageDigest != $v2_cached.imageDigest) "v3 cached digest should differ from v2" |
| 108 | + |
| 109 | + # Verify human-readable output updated to v3 |
| 110 | + let human_output_v3 = bootc status --format humanreadable |
| 111 | + assert ($human_output_v3 | str contains "UpdateVersion:") "Human-readable output should show UpdateVersion line after v3 check" |
| 112 | + assert ($human_output_v3 | str contains $v3_cached.imageDigest) "Human-readable output should show v3 digest" |
| 113 | + |
| 114 | + tap ok |
| 115 | +} |
| 116 | + |
| 117 | +def main [] { |
| 118 | + match $env.TMT_REBOOT_COUNT? { |
| 119 | + null | "0" => initial_build, |
| 120 | + "1" => second_boot, |
| 121 | + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, |
| 122 | + } |
| 123 | +} |
0 commit comments