Skip to content

Commit 45d33d0

Browse files
tests: Add test for composefs gc
Disable `upgrade-preflight-disk-check` for composefs Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 549759e commit 45d33d0

5 files changed

Lines changed: 180 additions & 4 deletions

File tree

Justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test-container: build build-units
117117
podman run --rm --env=BOOTC_variant={{variant}} --env=BOOTC_base={{base}} --env=BOOTC_boot_type={{boot_type}} {{base_img}} bootc-integration-tests container
118118

119119
[group('core')]
120-
test-composefs bootloader filesystem boot_type seal_state:
120+
test-composefs bootloader filesystem boot_type seal_state *ARGS:
121121
@if [ "{{seal_state}}" = "sealed" ] && [ "{{filesystem}}" = "xfs" ]; then \
122122
echo "Invalid combination: sealed requires filesystem that supports fs-verity (ext4, btrfs)"; \
123123
exit 1; \
@@ -138,6 +138,7 @@ test-composefs bootloader filesystem boot_type seal_state:
138138
--filesystem={{filesystem}} \
139139
--seal-state={{seal_state}} \
140140
--boot-type={{boot_type}} \
141+
{{ARGS}} \
141142
$(if [ "{{boot_type}}" = "uki" ]; then echo "readonly"; else echo "integration"; fi)
142143

143144
# Run cargo fmt and clippy checks in container

tmt/plans/integration.fmf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,23 @@ execute:
182182
test:
183183
- /tmt/tests/tests/test-34-user-agent
184184

185+
/plan-35-composefs-gc:
186+
summary: Test composefs garbage collection with same and different kernel+initrd
187+
discover:
188+
how: fmf
189+
test:
190+
- /tmt/tests/tests/test-35-composefs-gc
191+
192+
/plan-35-upgrade-preflight-disk-check:
193+
summary: Verify pre-flight disk space check rejects images with inflated layer sizes
194+
discover:
195+
how: fmf
196+
test:
197+
- /tmt/tests/tests/test-35-upgrade-preflight-disk-check
198+
extra-fixme_skip_if_composefs: true
199+
185200
/plan-36-rollback:
186-
summary: Test bootc rollback functionality through image switch and rollback cycle
201+
summary: Test bootc rollback functionality
187202
discover:
188203
how: fmf
189204
test:
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# number: 35
2+
# tmt:
3+
# summary: Test composefs garbage collection with same and different kernel+initrd
4+
# duration: 30m
5+
6+
use std assert
7+
use tap.nu
8+
9+
# bootc status
10+
let st = bootc status --json | from json
11+
let booted = $st.status.booted.image
12+
13+
if not (tap is_composefs) or ($st.status.booted.composefs.bootType | str downcase) == "uki" {
14+
exit 0
15+
}
16+
17+
# Create a large file in a new container image, then bootc switch to the image
18+
def first_boot [] {
19+
bootc image copy-to-storage
20+
21+
echo $"
22+
FROM localhost/bootc
23+
RUN dd if=/dev/zero of=/usr/share/large-test-file bs=1k count=1337
24+
RUN echo 'large-file-marker' | dd of=/usr/share/large-test-file conv=notrunc
25+
" | podman build -t localhost/bootc-derived . -f -
26+
27+
let current_time = (date now)
28+
29+
bootc switch --transport containers-storage localhost/bootc-derived
30+
31+
# Find the large file's verity and save it
32+
# nu has its own built in find which sucks, so we use the other one
33+
# TODO: Replace this with some concrete API
34+
# See: https://github.com/composefs/composefs-rs/pull/236
35+
let file_path = (
36+
/usr/bin/find /sysroot/composefs/objects -type f -size 1337k -newermt ($current_time | format date "%Y-%m-%d %H:%M:%S")
37+
| xargs grep -lx "large-file-marker"
38+
)
39+
40+
echo $file_path | save /var/large-file-marker-objpath
41+
cat /var/large-file-marker-objpath
42+
43+
echo $st.status.booted.composefs.verity | save /var/first-verity
44+
45+
tmt-reboot
46+
}
47+
48+
# Create a container image derived from the first boot image, but update the initrd
49+
def second_boot [] {
50+
assert equal $booted.image.image "localhost/bootc-derived"
51+
52+
let path = cat /var/large-file-marker-objpath
53+
54+
echo "\$path"
55+
echo $path
56+
57+
assert ($path | path exists)
58+
59+
# Create another image with a different initrd so we can test kernel + initrd cleanup
60+
61+
echo "
62+
FROM localhost/bootc
63+
64+
RUN echo 'echo hello' > /usr/bin/hello
65+
RUN chmod +x /usr/bin/hello
66+
67+
RUN mkdir /usr/lib/dracut/modules.d/99something
68+
69+
RUN cat <<-EOF > /usr/lib/dracut/modules.d/99something/module-setup.sh
70+
#!/usr/bin/bash
71+
72+
check() {
73+
return 0
74+
}
75+
76+
depends() {
77+
return 0
78+
}
79+
80+
install() {
81+
inst '/usr/bin/hello' /bin/hello
82+
}
83+
EOF
84+
85+
RUN set -x; kver=$(cd /usr/lib/modules && echo *); dracut -vf --add bootc /usr/lib/modules/$kver/initramfs.img $kver;
86+
" | lines | each { str trim } | str join "\n" | podman build -t localhost/bootc-derived-initrd . -f -
87+
88+
bootc switch --transport containers-storage localhost/bootc-derived-initrd
89+
90+
tmt-reboot
91+
}
92+
93+
# The large file should've been GC'd as we switched to an image derived from the original one
94+
def third_boot [] {
95+
assert equal $booted.image.image "localhost/bootc-derived-initrd"
96+
97+
let path = cat /var/large-file-marker-objpath
98+
assert (not ($"/sysroot/composefs/objects/($path)" | path exists))
99+
100+
# Also assert we have two different kernel + initrd pairs
101+
let booted_verity = (bootc status --json | from json).status.booted.composefs.verity
102+
103+
let bootloader = (bootc status --json | from json).status.booted.composefs.bootloader
104+
105+
let boot_dir = if ($bootloader | str downcase) == "systemd" {
106+
# TODO: Some concrete API for this would be great
107+
mkdir /var/tmp/efi
108+
mount /dev/vda2 /var/tmp/efi
109+
"/var/tmp/efi/EFI/Linux"
110+
} else {
111+
"/sysroot/boot"
112+
}
113+
114+
assert ($"($boot_dir)/($booted_verity)" | path exists)
115+
116+
# This is for the rollback, but since the rollback and the very
117+
# first boot have the same kernel + initrd pair, and this rollback
118+
# was deployed after the first boot, we will still be using the very
119+
# first verity for the boot binary name
120+
assert ($"($boot_dir)/(cat /var/first-verity)" | path exists)
121+
122+
echo $"($boot_dir)/($booted_verity)" | save /var/to-be-deleted-kernel
123+
124+
# Now we create a new image derived from the current kernel + initrd
125+
# Switching to this and rebooting should remove the old kernel + initrd
126+
echo "
127+
FROM localhost/bootc-derived-initrd
128+
RUN echo 'another file' > /usr/share/another-one
129+
" | podman build -t localhost/bootc-final . -f -
130+
131+
132+
bootc switch --transport containers-storage localhost/bootc-final
133+
134+
tmt-reboot
135+
}
136+
137+
def fourth_boot [] {
138+
assert equal $booted.image.image "localhost/bootc-final"
139+
assert (not ((cat /var/to-be-deleted-kernel | path exists)))
140+
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+
"3" => fourth_boot,
150+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
151+
}
152+
}
153+

tmt/tests/booted/test-upgrade-preflight-disk-check.nu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# tmt:
33
# summary: Verify pre-flight disk space check rejects images with inflated layer sizes
44
# duration: 10m
5+
# extra:
6+
# fixme_skip_if_composefs: true
57
#
68
# This test does NOT require a reboot.
79
# It constructs a minimal fake OCI image directory that claims to have an

tmt/tests/tests.fmf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,18 @@
102102
duration: 10m
103103
test: python3 booted/test-user-agent.py
104104

105+
/test-35-composefs-gc:
106+
summary: Test composefs garbage collection with same and different kernel+initrd
107+
duration: 30m
108+
test: nu booted/test-composefs-gc.nu
109+
105110
/test-35-upgrade-preflight-disk-check:
106111
summary: Verify pre-flight disk space check rejects images with inflated layer sizes
107-
duration: 20m
112+
duration: 10m
108113
test: nu booted/test-upgrade-preflight-disk-check.nu
109114

110115
/test-36-rollback:
111-
summary: Test bootc rollback functionality through image switch and rollback cycle
116+
summary: Test bootc rollback functionality
112117
duration: 30m
113118
test: nu booted/test-rollback.nu
114119

0 commit comments

Comments
 (0)