Skip to content

Commit 864b7f0

Browse files
henrywangcgwalters
authored andcommitted
test: Use bootc image copy-to-storage and add run_install helper
Replace the complex get_target_image function with a simpler approach: use `bootc image copy-to-storage` to copy the booted image to local container storage, then reference it as containers-storage:localhost/bootc. Also add a run_install helper in tap.nu to eliminate copy-pasted systemd-run boilerplate across install tests. Signed-off-by: Xiaofeng Wang <henrywangxf@me.com>
1 parent 6f06953 commit 864b7f0

File tree

5 files changed

+23
-102
lines changed

5 files changed

+23
-102
lines changed

tmt/tests/booted/tap.nu

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,15 @@ export def is_composefs [] {
1919
$st.status.booted.composefs? != null
2020
}
2121

22-
# Get the target image for install tests based on the running OS
23-
# This ensures the target image matches the host OS to avoid version mismatches
24-
# (e.g., XFS features created by newer mkfs.xfs not recognized by older grub2)
25-
export def get_target_image [] {
26-
# Parse os-release to get ID and VERSION_ID
27-
let os = open /usr/lib/os-release
28-
| lines
29-
| filter {|l| $l != "" and not ($l | str starts-with "#") }
30-
| parse "{key}={value}"
31-
| reduce -f {} {|it, acc|
32-
$acc | upsert $it.key ($it.value | str trim -c '"')
33-
}
34-
35-
let id = $os.ID
36-
let version_id = $os.VERSION_ID
37-
38-
# Construct the key for os-image-map.json
39-
let key = if $id == "centos" {
40-
# CentOS uses "centos-9" or "centos-10" format
41-
$"centos-($version_id)"
42-
} else if $id == "fedora" {
43-
$"fedora-($version_id)"
44-
} else if $id == "rhel" {
45-
# RHEL uses "rhel-9.8" or "rhel-10.2" format
46-
$"rhel-($version_id)"
47-
} else {
48-
# Fallback to centos-9 for unknown distros
49-
"centos-9"
50-
}
51-
52-
# Load the os-image-map.json - try multiple possible locations
53-
let possible_paths = [
54-
"hack/os-image-map.json",
55-
"../../../hack/os-image-map.json",
56-
"/var/home/bootc/hack/os-image-map.json"
57-
]
58-
59-
mut image_map = null
60-
for p in $possible_paths {
61-
if ($p | path exists) {
62-
$image_map = (open $p)
63-
break
64-
}
65-
}
66-
67-
# If map not found, use default centos-9 image
68-
if ($image_map == null) {
69-
return "docker://quay.io/centos-bootc/centos-bootc:stream9"
70-
}
71-
72-
let image = $image_map.base | get -i $key
73-
if ($image | is-empty) {
74-
# Fallback to centos-9 if key not found
75-
$"docker://($image_map.base.centos-9)"
76-
} else {
77-
$"docker://($image)"
78-
}
22+
# Run a bootc install command in an isolated mount namespace.
23+
# This handles the common setup needed for install tests run outside a container.
24+
export def run_install [cmd: string] {
25+
systemd-run -p MountFlags=slave -qdPG -- /bin/sh -c $"
26+
set -xeuo pipefail
27+
bootc usr-overlay
28+
if test -d /sysroot/ostree; then mount --bind /usr/share/empty /sysroot/ostree; fi
29+
rm -vrf /usr/lib/bootupd/updates
30+
rm -vrf /usr/lib/bootc/bound-images.d
31+
($cmd)
32+
"
7933
}

tmt/tests/booted/test-install-bootloader-none.nu

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66
use std assert
77
use tap.nu
88

9-
let target_image = (tap get_target_image)
10-
119
def main [] {
1210
tap begin "install with --bootloader=none"
1311

12+
# Copy the booted image to container storage for use as install source
13+
bootc image copy-to-storage
14+
let target_image = "containers-storage:localhost/bootc"
15+
1416
truncate -s 10G disk.img
1517

1618
setenforce 0
1719

18-
systemd-run -p MountFlags=slave -qdPG -- /bin/sh -c $"
19-
set -xeuo pipefail
20-
bootc usr-overlay
21-
if test -d /sysroot/ostree; then mount --bind /usr/share/empty /sysroot/ostree; fi
22-
rm -vrf /usr/lib/bootupd/updates
23-
rm -vrf /usr/lib/bootc/bound-images.d
24-
# Install with --bootloader=none - skips bootloader management
25-
bootc install to-disk --disable-selinux --via-loopback --filesystem xfs --bootloader=none --source-imgref ($target_image) ./disk.img
26-
"
20+
tap run_install $"bootc install to-disk --disable-selinux --via-loopback --filesystem xfs --bootloader=none --source-imgref ($target_image) ./disk.img"
2721

2822
rm -f disk.img
2923

tmt/tests/booted/test-install-no-boot-dir.nu

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@
66
use std assert
77
use tap.nu
88

9-
let target_image = (tap get_target_image)
10-
119
def main [] {
1210
tap begin "install to-filesystem without /boot"
1311

12+
# Copy the booted image to container storage for use as install source
13+
bootc image copy-to-storage
14+
let target_image = "containers-storage:localhost/bootc"
15+
1416
mkdir /var/mnt
1517
truncate -s 10G disk.img
1618
mkfs.ext4 disk.img
1719
mount -o loop disk.img /var/mnt
1820

1921
setenforce 0
2022

21-
systemd-run -p MountFlags=slave -qdPG -- /bin/sh -c $"
22-
set -xeuo pipefail
23-
bootc usr-overlay
24-
if test -d /sysroot/ostree; then mount --bind /usr/share/empty /sysroot/ostree; fi
25-
rm -vrf /usr/lib/bootupd/updates
26-
rm -vrf /usr/lib/bootc/bound-images.d
27-
# Install to filesystem without /boot - skips bootloader management
28-
bootc install to-filesystem --disable-selinux --bootloader=none --source-imgref ($target_image) /var/mnt
29-
"
23+
tap run_install $"bootc install to-filesystem --disable-selinux --bootloader=none --source-imgref ($target_image) /var/mnt"
3024

3125
umount /var/mnt
3226
rm -f disk.img

tmt/tests/booted/test-install-outside-container.nu

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ let install_cmd = if (tap is_composefs) {
3939
$"($base_args) --filesystem xfs ./disk.img"
4040
}
4141

42-
systemd-run -p MountFlags=slave -qdPG -- /bin/sh -c $"
43-
set -xeuo pipefail
44-
bootc usr-overlay
45-
if test -d /sysroot/ostree; then mount --bind /usr/share/empty /sysroot/ostree; fi
46-
# Note we do keep the other bootupd state
47-
rm -vrf /usr/lib/bootupd/updates
48-
# Another bootc install bug, we should not look at this in outside-of-container flows
49-
rm -vrf /usr/lib/bootc/bound-images.d
50-
($install_cmd)
51-
"
42+
tap run_install $install_cmd
5243

5344
tap ok

tmt/tests/booted/test-install-unified-flag.nu

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@ def main [] {
2626
# Disable SELinux enforcement for the install (same as test-install-outside-container)
2727
setenforce 0
2828

29-
# Perform the install with unified storage flag
30-
# We use systemd-run to handle mount namespace issues
31-
systemd-run -p MountFlags=slave -qdPG -- /bin/sh -c $"
32-
set -xeuo pipefail
33-
bootc usr-overlay
34-
if test -d /sysroot/ostree; then mount --bind /usr/share/empty /sysroot/ostree; fi
35-
# Note we do keep the other bootupd state
36-
rm -vrf /usr/lib/bootupd/updates
37-
# Another bootc install bug, we should not look at this in outside-of-container flows
38-
rm -vrf /usr/lib/bootc/bound-images.d
39-
# Install with unified storage flag to loopback disk
40-
bootc install to-disk --disable-selinux --via-loopback --filesystem xfs --experimental-unified-storage --source-imgref ($target_image) ./disk.img
41-
"
29+
tap run_install $"bootc install to-disk --disable-selinux --via-loopback --filesystem xfs --experimental-unified-storage --source-imgref ($target_image) ./disk.img"
4230

4331
# Cleanup
4432
rm -f disk.img

0 commit comments

Comments
 (0)