|
| 1 | +# number: 51 |
| 2 | +# extra: |
| 3 | +# export_image: true |
| 4 | +# tmt: |
| 5 | +# summary: Switch to a derived image using an OCI delta and verify after reboot |
| 6 | +# duration: 30m |
| 7 | +# adjust: |
| 8 | +# - when: distro != fedora |
| 9 | +# enabled: false |
| 10 | +# because: oci-delta is packaged in Fedora |
| 11 | +# - when: boot_type == uki and seal_state == sealed |
| 12 | +# enabled: false |
| 13 | +# because: the guest-local UKI builder produces unsigned images |
| 14 | +# |
| 15 | +use std assert |
| 16 | +use tap.nu |
| 17 | + |
| 18 | +const image = "localhost/bootc-delta-target:latest" |
| 19 | +const delta = "/var/tmp/image-1-to-2.oci-delta" |
| 20 | +const state = "/var/tmp/bootc-delta-state.json" |
| 21 | +const marker = "/usr/share/testing-bootc-delta" |
| 22 | + |
| 23 | +def initial_build [] { |
| 24 | + tap begin "switch from OCI delta" |
| 25 | + assert (not ($marker | path exists)) |
| 26 | + let st = bootc status --json | from json |
| 27 | + |
| 28 | + if not (tap is_composefs) { |
| 29 | + let automounted = ( |
| 30 | + do { ^findmnt --mountpoint /boot --types autofs --noheadings } | complete |
| 31 | + ).exit_code == 0 |
| 32 | + if $automounted { |
| 33 | + # An expired /boot breaks ostree finalization: https://github.com/bootc-dev/bootc/issues/2402 |
| 34 | + let dropin = "/etc/systemd/system/boot.automount.d/bootc-delta-test.conf" |
| 35 | + mkdir ($dropin | path dirname) |
| 36 | + "[Automount]\nTimeoutIdleSec=0\n" | save $dropin |
| 37 | + systemctl daemon-reload |
| 38 | + systemctl restart boot.automount |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + let source_archive = $env.BOOTC_source_image_archive? | default "/sysroot/bootc-source.oci.tar" |
| 43 | + assert ($source_archive | path exists) $"Missing source image archive: ($source_archive)" |
| 44 | + skopeo copy $"oci-archive:($source_archive)" containers-storage:localhost/bootc |
| 45 | + |
| 46 | + (tap make_uki_containerfile $" |
| 47 | + FROM localhost/bootc as base |
| 48 | + RUN echo delta-upgrade > ($marker) |
| 49 | + ") | save Dockerfile |
| 50 | + podman build --network=none -t $image . |
| 51 | + |
| 52 | + let target = skopeo inspect $"containers-storage:($image)" | from json |
| 53 | + let reference = $"localhost/bootc-delta-target@($target.Digest)" |
| 54 | + assert ($target.Digest != $st.status.booted.image.imageDigest) |
| 55 | + |
| 56 | + oci-delta create $"oci-archive:($source_archive)" $"containers-storage:($image)" $delta |
| 57 | + # Keep the target available only through the delta. |
| 58 | + podman rmi $image |
| 59 | + |
| 60 | + { |
| 61 | + image: $reference |
| 62 | + digest: $target.Digest |
| 63 | + composefs: (tap is_composefs) |
| 64 | + } | to json | save $state |
| 65 | + |
| 66 | + bootc switch --from-delta $delta $reference |
| 67 | + let staged = (bootc status --json | from json).status.staged.image |
| 68 | + assert equal $staged.image.transport registry |
| 69 | + assert equal $staged.image.image $reference |
| 70 | + assert equal $staged.imageDigest $target.Digest |
| 71 | + assert (not ($marker | path exists)) |
| 72 | + tmt-reboot |
| 73 | +} |
| 74 | + |
| 75 | +def verify_delta [] { |
| 76 | + let expected = open $state |
| 77 | + let booted = (bootc status --json | from json).status.booted.image |
| 78 | + assert equal $booted.image.transport registry |
| 79 | + assert equal $booted.image.image $expected.image |
| 80 | + assert equal $booted.imageDigest $expected.digest |
| 81 | + assert equal (open $marker | str trim) delta-upgrade |
| 82 | + assert equal (tap is_composefs) $expected.composefs |
| 83 | + bootc internals fsck |
| 84 | + tap ok |
| 85 | +} |
| 86 | + |
| 87 | +def main [] { |
| 88 | + match $env.TMT_REBOOT_COUNT? { |
| 89 | + null | "0" => initial_build, |
| 90 | + "1" => verify_delta, |
| 91 | + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, |
| 92 | + } |
| 93 | +} |
0 commit comments