Skip to content

Commit b313845

Browse files
committed
tests: Add test test-tmt-on-coreos
To workaround bootc-dev/bcvk#174, will build `bootc-integration-coreos` container firstly and save it to `bootc.tar`, then load on Ostree OS to install. Signed-off-by: Huijing Hei <hhei@redhat.com>
1 parent a04ec67 commit b313845

File tree

7 files changed

+173
-4
lines changed

7 files changed

+173
-4
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,24 @@ jobs:
197197
- name: Unit and container integration tests
198198
run: just test-container
199199

200-
- name: Run TMT tests
200+
- name: Run TMT integration tests
201201
run: |
202202
if [ "${{ matrix.variant }}" = "composefs-sealeduki-sdboot" ]; then
203203
just test-composefs
204204
else
205-
just test-tmt
205+
just test-tmt integration
206+
fi
207+
just clean-local-images
208+
209+
- name: Run TMT test about bootc install on coreos
210+
run: |
211+
# Only test fedora-43 on fedora-coreos:testing-devel
212+
if [ "${{ matrix.test_os }}" = "fedora-43" ] && [ "${{ matrix.variant }}" = "ostree" ]; then
213+
just build-testimage-coreos target/packages
214+
just test-tmt-on-coreos plan-bootc-install-on-coreos
215+
just clean-local-images
216+
else
217+
echo "skipped"
206218
fi
207219
208220
- name: Archive TMT logs

Justfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ _git-build-vars:
6666
echo "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH}"
6767
echo "VERSION=${VERSION}"
6868

69+
# Needed by bootc install on ostree
70+
fedora-coreos := "quay.io/fedora/fedora-coreos:testing-devel"
71+
6972
# The default target: build the container image from current sources.
7073
# Note commonly you might want to override the base image via e.g.
7174
# `just build --build-arg=base=quay.io/fedora/fedora-bootc:42`
@@ -179,6 +182,8 @@ validate:
179182
#
180183
# To run an individual test, pass it as an argument like:
181184
# `just test-tmt readonly`
185+
#
186+
# To run the integration tests, execute `just test-tmt integration`
182187
test-tmt *ARGS: build-integration-test-image _build-upgrade-image
183188
@just test-tmt-nobuild {{ARGS}}
184189

@@ -192,6 +197,19 @@ _build-upgrade-image:
192197
test-tmt-nobuild *ARGS:
193198
cargo xtask run-tmt --env=BOOTC_variant={{variant}} --upgrade-image={{integration_upgrade_img}} {{integration_img}} {{ARGS}}
194199

200+
# Build test container image for testing on coreos with SKIP_CONFIGS=1,
201+
# without configs and no curl container image
202+
build-testimage-coreos PATH:
203+
@just build-from-package {{PATH}}
204+
cd hack && podman build {{base_buildargs}} --build-arg SKIP_CONFIGS=1 -t {{integration_img}}-coreos -f Containerfile .
205+
206+
# Run test bootc install on coreos (FCOS)
207+
# BOOTC_target is `bootc-integration-coreos`, it will be used for bootc install.
208+
# Run `just build-testimage-coreos target/packages` to build test image firstly,
209+
# then run `just test-tmt-on-coreos plan-bootc-install-on-coreos`
210+
test-tmt-on-coreos *ARGS:
211+
cargo xtask run-tmt --env=BOOTC_variant={{variant}} --env=BOOTC_target={{integration_img}}-coreos:latest {{fedora-coreos}} {{ARGS}}
212+
195213
# Cleanup all test VMs created by tmt tests
196214
tmt-vm-cleanup:
197215
bcvk libvirt rm --stop --force --label bootc.test=1
@@ -206,6 +224,8 @@ test-container: build-units build-integration-test-image
206224
clean-local-images:
207225
podman images --filter "label={{testimage_label}}"
208226
podman images --filter "label={{testimage_label}}" --format "{{{{.ID}}" | xargs -r podman rmi -f
227+
podman image prune -f
228+
podman rmi {{fedora-coreos}} -f
209229

210230
# Print the container image reference for a given short $ID-VERSION_ID for NAME
211231
# and 'base' or 'buildroot-base' for TYPE (base image type)

crates/xtask/src/tmt.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ fn build_firmware_args(sh: &Shell, image: &str) -> Result<Vec<String>> {
137137
Ok(r)
138138
}
139139

140+
/// Detect VARIANT_ID from container image by reading os-release
141+
/// Returns string like "coreos" or empty
142+
#[context("Detecting distro from image")]
143+
fn detect_variantid_from_image(sh: &Shell, image: &str) -> Result<Option<String>> {
144+
let variant_id = cmd!(
145+
sh,
146+
"podman run --rm {image} bash -c '. /usr/lib/os-release && echo $VARIANT_ID'"
147+
)
148+
.read()
149+
.context("Failed to run image as container to detect distro")?;
150+
151+
let variant_id = variant_id.trim();
152+
if variant_id.is_empty() {
153+
return Ok(None);
154+
}
155+
156+
Ok(Some(variant_id.to_string()))
157+
}
158+
140159
/// Check if a distro supports --bind-storage-ro
141160
/// CentOS 9 lacks systemd.extra-unit.* support required for bind-storage-ro
142161
fn distro_supports_bind_storage_ro(distro: &str) -> bool {
@@ -269,18 +288,25 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
269288

270289
// Detect distro from the image
271290
let distro = detect_distro_from_image(sh, image)?;
291+
// Detect VARIANT_ID from the image
292+
// As this can not be empty value in context, use "unknown" instead
293+
let variant_id = detect_variantid_from_image(sh, image)?.unwrap_or("unknown".to_string());
272294

273295
let context = args
274296
.context
275297
.iter()
276298
.map(|v| format!("--context={}", v))
277299
.chain(std::iter::once(format!("--context=running_env=image_mode")))
278300
.chain(std::iter::once(format!("--context=distro={}", distro)))
301+
.chain(std::iter::once(format!(
302+
"--context=VARIANT_ID={variant_id}"
303+
)))
279304
.collect::<Vec<_>>();
280305
let preserve_vm = args.preserve_vm;
281306

282307
println!("Using bcvk image: {}", image);
283308
println!("Detected distro: {}", distro);
309+
println!("Detected VARIANT_ID: {variant_id}");
284310

285311
let firmware_args = build_firmware_args(sh, image)?;
286312

@@ -295,6 +321,14 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
295321
.run()
296322
.with_context(|| format!("Copying tmt files to {}", workdir))?;
297323

324+
// Workaround for https://github.com/bootc-dev/bcvk/issues/174
325+
// Save the container image to tar, this will be synced to tested OS
326+
if variant_id == "coreos" {
327+
cmd!(sh, "podman save -q -o {workdir}/tmt/tests/bootc.tar localhost/bootc-integration-coreos:latest")
328+
.run()
329+
.with_context(|| format!("Saving container image to tar"))?;
330+
}
331+
298332
// Change to workdir for running tmt commands
299333
let _dir = sh.push_dir(workdir);
300334

@@ -387,7 +421,12 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
387421
distro
388422
);
389423
}
390-
424+
// Add --filesystem=xfs by default on fedora-coreos
425+
if variant_id == "coreos" {
426+
if distro.starts_with("fedora") {
427+
opts.push("--filesystem=xfs".to_string());
428+
}
429+
}
391430
opts
392431
};
393432

@@ -406,7 +445,6 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
406445
test_results.push((plan.to_string(), false, None));
407446
continue;
408447
}
409-
410448
// Ensure VM cleanup happens even on error (unless --preserve-vm is set)
411449
let cleanup_vm = || {
412450
if preserve_vm {

hack/Containerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ EORUN
1818

1919
# And the configs
2020
FROM extended
21+
ARG SKIP_CONFIGS
2122
RUN --mount=type=bind,from=context,target=/run/context <<EORUN
23+
# Do not need the configs when testing installation on ostree
24+
echo "SKIP_CONFIGS=${SKIP_CONFIGS:-<unset>}"
25+
if [ -n "${SKIP_CONFIGS:-}" ]; then
26+
echo "Skipping configs installation"
27+
exit 0
28+
fi
2229
set -xeuo pipefail
2330
cd /run/context
2431
# For test-22-logically-bound-install

tmt/plans/tests-install.fmf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
discover:
2+
how: fmf
3+
execute:
4+
how: tmt
5+
# Because of the two issues, run tmt on github runner directly failed
6+
# - selinux disabled on ubuntu (https://github.com/teemtee/tmt/issues/3364)
7+
# - uefi firmware is not supported (https://github.com/teemtee/tmt/issues/4203)
8+
provision:
9+
how: virtual
10+
hardware:
11+
boot:
12+
method: uefi
13+
image: fedora-coreos-next
14+
user: root
15+
memory: 4096
16+
disk: 20
17+
18+
/plan-bootc-install-on-coreos:
19+
summary: Execute bootc install on ostree OS
20+
adjust:
21+
- when: VARIANT_ID != coreos
22+
enabled: false
23+
because: this needs to start an ostree OS firstly
24+
discover:
25+
how: fmf
26+
test:
27+
- /tmt/tests/test-install/test-bootc-install-on-coreos
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# number: 50
2+
# tmt:
3+
# summary: Test bootc install on ostree OS
4+
# duration: 30m
5+
# adjust:
6+
# - when: VARIANT_ID != coreos
7+
# enabled: false
8+
# because: this needs to start an ostree OS firstly
9+
#
10+
#!/bin/bash
11+
set -eux
12+
13+
echo "Testing bootc install on ostree"
14+
15+
# BOOTC_target is integration image
16+
[ -n "$BOOTC_target" ]
17+
18+
if [ "$TMT_REBOOT_COUNT" -eq 0 ]; then
19+
echo "Running before first reboot"
20+
pwd
21+
ls -l
22+
# Verify testing on ostree OS
23+
if [ ! -f "/run/ostree-booted" ]; then
24+
echo "Should be ostree OS"
25+
exit 1
26+
fi
27+
# workaround for https://github.com/bootc-dev/bcvk/issues/174
28+
bootc_tar=bootc.tar
29+
[ -f ${bootc_tar} ]
30+
podman load -q -i ${bootc_tar}
31+
podman image exists ${BOOTC_target} && rm -f ${bootc_tar}
32+
33+
# Run bootc install using the same stateroot for shared /var
34+
stateroot=$(bootc status --json | jq -r .status.booted.ostree.stateroot)
35+
podman run \
36+
--rm --privileged \
37+
-v /dev:/dev \
38+
-v /:/target \
39+
-v /var/lib/containers:/var/lib/containers \
40+
--pid=host \
41+
--security-opt label=type:unconfined_t \
42+
${BOOTC_target} \
43+
bootc install to-existing-root \
44+
--stateroot=${stateroot} \
45+
--skip-fetch-check \
46+
--acknowledge-destructive \
47+
--karg=console=ttyS0,115200n8
48+
49+
bootc status
50+
tmt-reboot
51+
elif [ "$TMT_REBOOT_COUNT" -eq 1 ]; then
52+
echo 'After the reboot'
53+
booted=$(bootc status --json | jq -r .status.booted.image.image.image)
54+
[ ${booted} == ${BOOTC_target} ]
55+
fi
56+
57+
echo "Run bootc install on ostree OS successfully"

tmt/tests/test-install.fmf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/test-bootc-install-on-coreos:
2+
summary: Test bootc install on coreos
3+
duration: 30m
4+
adjust:
5+
- when: VARIANT_ID != coreos
6+
enabled: false
7+
because: this needs to start an ostree OS firstly
8+
test: bash install/test-on-ostree/test-install-on-ostree.sh

0 commit comments

Comments
 (0)