Skip to content

Commit edc933f

Browse files
Johan-Liebert1cgwalters
authored andcommitted
tmt: Add test for rollback
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 4d8fcbc commit edc933f

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

tmt/plans/integration.fmf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,11 @@ execute:
181181
how: fmf
182182
test:
183183
- /tmt/tests/tests/test-34-user-agent
184+
185+
/plan-36-rollback:
186+
summary: Test bootc rollback functionality through image switch and rollback cycle
187+
discover:
188+
how: fmf
189+
test:
190+
- /tmt/tests/tests/test-36-rollback
184191
# END GENERATED PLANS

tmt/tests/booted/test-rollback.nu

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# number: 36
2+
# tmt:
3+
# summary: Test bootc rollback functionality
4+
# duration: 30m
5+
#
6+
# This test verifies bootc rollback functionality:
7+
# 1. Captures the initial deployment state
8+
# 2. Switches to a different image
9+
# 3. Verifies the switch was successful
10+
# 4. Performs bootc rollback
11+
# 5. Reboots and verifies we're back to the original deployment
12+
13+
use std assert
14+
use tap.nu
15+
use bootc_testlib.nu
16+
17+
bootc status
18+
journalctl --list-boots
19+
20+
let st = bootc status --json | from json
21+
let booted = $st.status.booted.image
22+
23+
def imgsrc [] {
24+
$env.BOOTC_upgrade_image? | default "localhost/bootc-derived-local"
25+
}
26+
27+
# Run on the first boot - capture initial state and switch to new image
28+
def initial_switch [] {
29+
tap begin "bootc rollback test"
30+
31+
print "=== Initial boot - capturing state and switching image ==="
32+
33+
# Store initial deployment information for later verification
34+
let initial_st = bootc status --json | from json
35+
let initial_image = $initial_st.status.booted.image
36+
37+
$initial_image | to json | save /var/bootc-initial-state.json
38+
39+
let imgsrc = imgsrc
40+
41+
if ($imgsrc | str ends-with "-local") {
42+
bootc image copy-to-storage
43+
44+
print "Building derived container"
45+
"FROM localhost/bootc
46+
RUN echo 'This is the rollback target image' > /usr/share/bootc-rollback-marker
47+
" | save Dockerfile
48+
49+
podman build -t $imgsrc .
50+
print $"Built derived image: ($imgsrc)"
51+
}
52+
53+
print $"Switching to ($imgsrc)"
54+
bootc switch --transport containers-storage $imgsrc
55+
56+
print "Switch completed, rebooting to new image..."
57+
tmt-reboot
58+
}
59+
60+
# Check that we successfully switched to the new image and then rollback
61+
def second_boot_rollback [] {
62+
print "=== Second boot - verifying switch and performing rollback ==="
63+
64+
# Verify we're running the new image
65+
assert equal $booted.image.image $"(imgsrc)"
66+
print "Successfully switched to new image"
67+
68+
assert ("/usr/share/bootc-rollback-marker" | path exists)
69+
print "New image artifacts verified"
70+
71+
print "Performing bootc rollback..."
72+
bootc rollback
73+
74+
print "Rollback initiated, rebooting to previous deployment..."
75+
tmt-reboot
76+
}
77+
78+
def back_to_first_depl [boot_count] {
79+
print $"=== ($boot_count) boot - verifying rollback success ==="
80+
81+
# Load the original state we saved and verify we're back to the original image
82+
let original_state = cat /var/bootc-initial-state.json | from json
83+
84+
assert equal $booted.image $original_state.image
85+
print $"Successfully rolled back to original image: ($booted.image.image)"
86+
87+
if ("/usr/share/bootc-rollback-marker" | path exists) {
88+
error make { msg: "Rollback target marker still present - rollback may have failed" }
89+
}
90+
}
91+
92+
# Verify that rollback was successful and we're back to original deployment
93+
def third_boot_verify [] {
94+
back_to_first_depl Third
95+
96+
# Finally test a double rollback, to make sure the rollback state is queued then unqueued
97+
bootc rollback
98+
bootc rollback
99+
100+
tmt-reboot
101+
}
102+
103+
def fourth_boot_verify [] {
104+
back_to_first_depl Fourth
105+
tap ok
106+
}
107+
108+
def main [] {
109+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
110+
match $env.TMT_REBOOT_COUNT? {
111+
null | "0" => initial_switch,
112+
"1" => second_boot_rollback,
113+
"2" => third_boot_verify,
114+
"3" => fourth_boot_verify,
115+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
116+
}
117+
}

tmt/tests/tests.fmf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@
101101
summary: Verify bootc sends correct User-Agent header to registries
102102
duration: 10m
103103
test: python3 booted/test-user-agent.py
104+
105+
/test-36-rollback:
106+
summary: Test bootc rollback functionality through image switch and rollback cycle
107+
duration: 30m
108+
test: nu booted/test-rollback.nu

0 commit comments

Comments
 (0)