Skip to content

Commit 0e72bc0

Browse files
tmt: Add test for download only switch
Mostly AI generated Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent e7bc1c8 commit 0e72bc0

3 files changed

Lines changed: 170 additions & 0 deletions

File tree

‎tmt/plans/integration.fmf‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ execute:
294294
test:
295295
- /tmt/tests/tests/test-46-etc-merge-conflict
296296

297+
/plan-47-download-only-switch:
298+
summary: Execute download-only switch tests
299+
discover:
300+
how: fmf
301+
test:
302+
- /tmt/tests/tests/test-47-download-only-switch
303+
297304
/plan-48-composefs-uki-dumpfile:
298305
summary: Test composefs UKI dumpfile diff print
299306
discover:
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# number: 47
2+
# tmt:
3+
# summary: Execute download-only switch tests
4+
# duration: 40m
5+
#
6+
# This test does:
7+
# bootc image copy-to-storage
8+
# podman build <from that image> (v1)
9+
# bootc switch <into that image> (v1)
10+
# Verify we boot into the new image (v1)
11+
# podman build updated image (v2)
12+
# bootc switch --download-only <to v2> (stage v2 in download-only mode)
13+
# reboot (should still boot into v1, staged deployment discarded)
14+
# verify staged deployment is null (discarded on reboot)
15+
# bootc switch --download-only <to v2> (re-stage v2 in download-only mode)
16+
# bootc switch --from-downloaded (clear download-only mode without fetching from image source)
17+
# reboot (should boot into v2)
18+
#
19+
use std assert
20+
use tap.nu
21+
use bootc_testlib.nu
22+
23+
# This code runs on *each* boot.
24+
# Here we just capture information.
25+
bootc status
26+
journalctl --list-boots
27+
28+
let st = bootc status --json | from json
29+
let booted = $st.status.booted.image
30+
31+
def imgsrc [] {
32+
$env.BOOTC_upgrade_image? | default "localhost/bootc-derived-local"
33+
}
34+
35+
# Run on the first boot - build v1 and switch to it
36+
def initial_build [] {
37+
tap begin "download-only switch test"
38+
39+
let imgsrc = imgsrc
40+
# This test only works in local mode
41+
assert ($imgsrc | str ends-with "-local") "This test requires local mode"
42+
43+
bootc image copy-to-storage
44+
45+
# Create test file v1 on host
46+
"v1" | save testing-bootc-switch-apply
47+
48+
# A simple derived container (v1) that adds a file
49+
let dockerfile = $"FROM localhost/bootc as base
50+
COPY testing-bootc-switch-apply /usr/share/testing-bootc-switch-apply
51+
"
52+
(tap make_uki_containerfile $dockerfile) | save Dockerfile
53+
# Build it
54+
podman build -t $imgsrc .
55+
56+
# Now, switch into the new image
57+
print $"Applying ($imgsrc)"
58+
bootc switch --transport containers-storage ($imgsrc)
59+
tmt-reboot
60+
}
61+
62+
# Check we have the updated image (v1), then test --download-only with switch
63+
def second_boot [] {
64+
print "verifying second boot - should be on v1"
65+
assert equal $booted.image.transport containers-storage
66+
assert equal $booted.image.image $"(imgsrc)"
67+
68+
# Verify the v1 file exists
69+
assert ("/usr/share/testing-bootc-switch-apply" | path exists) "v1 file should exist"
70+
let v1_content = open /usr/share/testing-bootc-switch-apply | str trim
71+
assert equal $v1_content "v1"
72+
73+
# Build v2 - a different derived image with a different tag
74+
let imgsrc = imgsrc
75+
let v2_image = $"($imgsrc)-v2"
76+
# Create test file v2 on host
77+
"v2" | save --force testing-bootc-switch-apply
78+
79+
let dockerfile = $"FROM localhost/bootc as base
80+
COPY testing-bootc-switch-apply /usr/share/testing-bootc-switch-apply
81+
"
82+
(tap make_uki_containerfile $dockerfile) | save --force Dockerfile
83+
podman build -t $v2_image .
84+
85+
# Now switch with --download-only (should set deployment to download-only mode)
86+
print $"Switching with --download-only to v2"
87+
bootc switch --download-only --transport containers-storage ($v2_image)
88+
89+
# Verify deployment is staged and in download-only mode
90+
let status_json = bootc status --json | from json
91+
assert ($status_json.status.staged != null) "Staged deployment should exist"
92+
assert ($status_json.status.staged.downloadOnly) "Staged deployment should be in download-only mode"
93+
94+
# Reboot - should still boot into v1 since deployment is in download-only mode
95+
tmt-reboot
96+
}
97+
98+
# Third boot - verify still on v1, staged deployment discarded, re-stage and clear download-only mode
99+
def third_boot [] {
100+
print "verifying third boot - should still be on v1 (download-only deployment was discarded)"
101+
102+
# Verify we're still on v1
103+
let v1_content = open /usr/share/testing-bootc-switch-apply | str trim
104+
assert equal $v1_content "v1" "Should still be on v1 after download-only reboot"
105+
106+
# Verify that the staged deployment was discarded on reboot, as is expected for download-only deployments
107+
let status_before = bootc status --json | from json
108+
assert ($status_before.status.staged == null) "Staged deployment should be discarded after rebooting with a download-only deployment"
109+
110+
# Re-run switch --download-only to re-stage the deployment
111+
let imgsrc = imgsrc
112+
let v2_image = $"($imgsrc)-v2"
113+
print "Re-staging with switch --download-only"
114+
bootc switch --download-only --transport containers-storage ($v2_image)
115+
116+
# Verify via JSON that deployment is in download-only mode again
117+
let status_json = bootc status --json | from json
118+
assert ($status_json.status.staged != null) "Staged deployment should exist"
119+
assert ($status_json.status.staged.downloadOnly) "Staged deployment should be in download-only mode"
120+
121+
# Now clear download-only mode by running switch --from-downloaded (without fetching from image source)
122+
print "Clearing download-only mode with bootc switch --from-downloaded"
123+
bootc switch --from-downloaded
124+
125+
# Verify via JSON that deployment is not in download-only mode
126+
let status_after_json = bootc status --json | from json
127+
assert (not $status_after_json.status.staged.downloadOnly) "Staged deployment should not be in download-only mode"
128+
129+
# Reboot to apply the update
130+
tmt-reboot
131+
}
132+
133+
# Fourth boot - verify we're on v2
134+
def fourth_boot [] {
135+
print "verifying fourth boot - should be on v2"
136+
assert equal $booted.image.transport containers-storage
137+
138+
let imgsrc = imgsrc
139+
let v2_image = $"($imgsrc)-v2"
140+
assert equal $booted.image.image $v2_image
141+
142+
# Verify v2 file content
143+
let v2_content = open /usr/share/testing-bootc-switch-apply | str trim
144+
assert equal $v2_content "v2" "Should be on v2 after clearing download-only and reboot"
145+
146+
tap ok
147+
}
148+
149+
def main [] {
150+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
151+
match $env.TMT_REBOOT_COUNT? {
152+
null | "0" => initial_build,
153+
"1" => second_boot,
154+
"2" => third_boot,
155+
"3" => fourth_boot,
156+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
157+
}
158+
}

‎tmt/tests/tests.fmf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ check:
184184
duration: 15m
185185
test: nu booted/test-etc-merge-conflict.nu
186186

187+
/test-47-download-only-switch:
188+
summary: Execute download-only switch tests
189+
duration: 40m
190+
test: nu booted/test-download-only-switch.nu
191+
187192
/test-48-composefs-uki-dumpfile:
188193
summary: Test composefs UKI dumpfile diff print
189194
duration: 30m

0 commit comments

Comments
 (0)