Skip to content

Commit e25e928

Browse files
authored
Merge pull request bootc-dev#729 from ckyrouac/bound-tmt
boundimage: Add tmt tests for bound images
2 parents fae684b + 35b1324 commit e25e928

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

plans/test-21-logically-bound.fmf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
provision:
3+
how: virtual
4+
# Generated by make test-tmt
5+
image: file://./target/testvm/disk.qcow2
6+
disk: 20
7+
summary: Execute local upgrade tests
8+
execute:
9+
how: tmt
10+
# We avoid writing nontrivial shell script as a general rule,
11+
# so this is written in nu.
12+
script: exec nu tests/booted/test-logically-bound.nu

tests/booted/test-logically-bound.nu

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# This test does:
2+
# bootc image switch bootc-bound-image
3+
# <verify bound images are pulled>
4+
# <reboot>
5+
# <verify booted state>
6+
# bootc upgrade
7+
# <verify new boudn images are pulled>
8+
# <reboot>
9+
# <verify booted state>
10+
11+
use std assert
12+
use tap.nu
13+
14+
# This code runs on *each* boot.
15+
bootc status
16+
let st = bootc status --json | from json
17+
let booted = $st.status.booted.image
18+
19+
def initial_setup [] {
20+
bootc image copy-to-storage
21+
podman images
22+
podman image inspect localhost/bootc | from json
23+
}
24+
25+
def build_image [name images containers] {
26+
let td = mktemp -d
27+
cd $td
28+
mkdir usr/share/containers/systemd
29+
30+
mut dockerfile = "FROM localhost/bootc
31+
COPY usr/ /usr/
32+
RUN echo sanity check > /usr/share/bound-image-sanity-check.txt
33+
" | save Dockerfile
34+
35+
for image in $images {
36+
echo $"[Image]\nImage=($image.image)" | save $"usr/share/containers/systemd/($image.name).image"
37+
if $image.bound == true {
38+
# these extra RUNs are suboptimal
39+
# however, this is just a test image and the extra RUNs will only add a couple extra layers
40+
# the benefit is simplified file creation, i.e. we don't need to handle adding "&& \" to each line
41+
echo $"RUN ln -s /usr/share/containers/systemd/($image.name).image /usr/lib/bootc/bound-images.d/($image.name).image\n" | save Dockerfile --append
42+
}
43+
}
44+
45+
for container in $containers {
46+
echo $"[Container]\nImage=($container.image)" | save $"usr/share/containers/systemd/($container.name).container"
47+
if $container.bound == true {
48+
echo $"RUN ln -s /usr/share/containers/systemd/($container.name).container /usr/lib/bootc/bound-images.d/($container.name).container\n" | save Dockerfile --append
49+
}
50+
}
51+
52+
# Build it
53+
podman build -t $name .
54+
# Just sanity check it
55+
let v = podman run --rm $name cat /usr/share/bound-image-sanity-check.txt | str trim
56+
assert equal $v "sanity check"
57+
}
58+
59+
def verify_images [images containers] {
60+
let bound_images = $images | where bound == true
61+
let bound_containers = $containers | where bound == true
62+
let num_bound = ($bound_images | length) + ($bound_containers | length)
63+
64+
let image_names = podman images --format json | from json | select -i Names
65+
66+
for $image in $bound_images {
67+
let found = $image_names | where Names == [$image.image]
68+
assert (($found | length) > 0) $"($image.image) not found"
69+
}
70+
71+
for $container in $bound_containers {
72+
let found = $image_names | where Names == [$container.image]
73+
assert (($found | length) > 0) $"($container.image) not found"
74+
}
75+
}
76+
77+
def first_boot [] {
78+
tap begin "bootc switch with bound images"
79+
80+
initial_setup
81+
82+
# build a bootc image that includes bound images
83+
let images = [
84+
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" },
85+
{ "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }
86+
]
87+
88+
let containers = [{
89+
"bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine"
90+
}]
91+
92+
let image_name = "localhost/bootc-bound"
93+
build_image $image_name $images $containers
94+
bootc switch --transport containers-storage $image_name
95+
verify_images $images $containers
96+
tmt-reboot
97+
}
98+
99+
def second_boot [] {
100+
print "verifying second boot after switch"
101+
assert equal $booted.image.transport containers-storage
102+
assert equal $booted.image.image localhost/bootc-bound
103+
104+
# verify images are still there after boot
105+
let images = [
106+
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" },
107+
{ "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }
108+
]
109+
110+
let containers = [{
111+
"bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine"
112+
}]
113+
verify_images $images $containers
114+
115+
# build a new bootc image with an additional bound image
116+
print "bootc upgrade with another bound image"
117+
let image_name = "localhost/bootc-bound"
118+
let more_images = $images | append [{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" }]
119+
build_image $image_name $more_images $containers
120+
bootc upgrade
121+
verify_images $more_images $containers
122+
tmt-reboot
123+
}
124+
125+
def third_boot [] {
126+
print "verifying third boot after upgrade"
127+
assert equal $booted.image.transport containers-storage
128+
assert equal $booted.image.image localhost/bootc-bound
129+
130+
let images = [
131+
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" },
132+
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" },
133+
{ "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }
134+
]
135+
136+
let containers = [{
137+
"bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine"
138+
}]
139+
140+
verify_images $images $containers
141+
tap ok
142+
}
143+
144+
def main [] {
145+
match $env.TMT_REBOOT_COUNT? {
146+
null | "0" => first_boot,
147+
"1" => second_boot,
148+
"2" => third_boot,
149+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
150+
}
151+
}

0 commit comments

Comments
 (0)