Skip to content

Commit 43dbe5d

Browse files
henrywangclaude
andcommitted
tests: Use OS-matched target image in install tests
Add get_target_image function to tap.nu that selects the appropriate bootc target image based on the running OS. This avoids version mismatches (e.g., XFS features created by newer mkfs.xfs not recognized by older grub2). The function parses /usr/lib/os-release and looks up the image from hack/os-image-map.json, with fallbacks for missing configurations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Xiaofeng Wang <henrywangxf@me.com>
1 parent 043cc79 commit 43dbe5d

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

tmt/tests/booted/tap.nu

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,65 @@ 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+
}
79+
}
80+
2281
# Run a bootc install command in an isolated mount namespace.
2382
# This handles the common setup needed for install tests run outside a container.
2483
export def run_install [cmd: string] {

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

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

9-
# In this test we install a generic image mainly because it keeps
10-
# this test in theory independent of starting from a bootc host,
11-
# but also because it's useful to test "skew" between the bootc binary
12-
# doing the install and the target image.
13-
let target_image = "docker://quay.io/centos-bootc/centos-bootc:stream9"
9+
# Use an OS-matched target image to avoid version mismatches
10+
# (e.g., XFS features created by newer mkfs.xfs not recognized by older grub2)
11+
let target_image = (tap get_target_image)
1412

1513
# setup filesystem
1614
mkdir /var/mnt

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use std assert
1313
use tap.nu
1414

15-
# Use a generic target image to test skew between the bootc binary doing
16-
# the install and the target image
17-
let target_image = "docker://quay.io/centos-bootc/centos-bootc:stream9"
15+
# Use an OS-matched target image to avoid version mismatches
16+
# (e.g., XFS features created by newer mkfs.xfs not recognized by older grub2)
17+
let target_image = (tap get_target_image)
1818

1919
def main [] {
2020
tap begin "install with experimental unified storage flag"

0 commit comments

Comments
 (0)