Skip to content

Commit 704338d

Browse files
henrywangcgwalters
authored andcommitted
test: Add Packit and gating test
Use 'system-reinstall-bootc' to re-install TF runner from package mode to image mode Signed-off-by: Xiaofeng Wang <[email protected]>
1 parent a507380 commit 704338d

File tree

8 files changed

+250
-18
lines changed

8 files changed

+250
-18
lines changed

.packit.yaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,23 @@ jobs:
6464
failure_comment:
6565
message: "bootc Copr build failed for {commit_sha}. @admin check logs {logs_url} and packit dashboard {packit_dashboard_url}"
6666

67-
# TODO: Readd some tmt tests that install the built RPM and e.g. test out system-reinstall-bootc
68-
# - job: tests
69-
# trigger: pull_request
70-
# targets:
71-
# - centos-stream-9-x86_64
72-
# - centos-stream-9-aarch64
73-
# - centos-stream-10-x86_64
74-
# - centos-stream-10-aarch64
75-
# - fedora-42-x86_64
76-
# - fedora-42-aarch64
77-
# - fedora-rawhide-x86_64
78-
# - fedora-rawhide-aarch64
79-
# tmt_plan: /integration
80-
# skip_build: true
81-
# identifier: integration-test
67+
- job: tests
68+
trigger: pull_request
69+
targets:
70+
- centos-stream-9-x86_64
71+
- centos-stream-9-aarch64
72+
- centos-stream-10-x86_64
73+
- centos-stream-10-aarch64
74+
- fedora-42-x86_64
75+
- fedora-42-aarch64
76+
- fedora-rawhide-x86_64
77+
- fedora-rawhide-aarch64
78+
tmt_plan: /tmt/plans/integration
79+
tf_extra_params:
80+
environments:
81+
- tmt:
82+
context:
83+
running_env: "packit"
8284

8385
- job: propose_downstream
8486
trigger: release

hack/Containerfile.packit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Build image for system-reinstall-bootc test
2+
3+
# Use centos-bootc:stream10 as default
4+
FROM quay.io/centos-bootc/centos-bootc:stream10
5+
6+
WORKDIR /bootc-test
7+
8+
# Some rhts-*, rstrnt-* and tmt-* commands are in /usr/local/bin
9+
COPY bin /usr/local/bin
10+
# Save testing farm run files
11+
COPY ARTIFACTS /var/ARTIFACTS
12+
# Copy bootc repo
13+
COPY test-artifacts /var/share/test-artifacts
14+
15+
RUN <<EORUN
16+
set -xeuo pipefail
17+
. /usr/lib/os-release
18+
if [[ $ID == "rhel" ]]; then
19+
cp rhel.repo /etc/yum.repos.d/
20+
fi
21+
cp test-artifacts.repo /etc/yum.repos.d/
22+
dnf -y update bootc
23+
./provision-derived.sh
24+
25+
# For test-22-logically-bound-install
26+
cp -a lbi/usr/. /usr
27+
for x in curl.container curl-base.image podman.image; do
28+
ln -s /usr/share/containers/systemd/$x /usr/lib/bootc/bound-images.d/$x
29+
done
30+
31+
# Add some testing kargs into our dev builds
32+
install -D -t /usr/lib/bootc/kargs.d test-kargs/*
33+
# Also copy in some default install configs we use for testing
34+
install -D -t /usr/lib/bootc/install/ install-test-configs/*
35+
36+
# Remove bootc repo, bootc updated already
37+
rm -rf /var/share/test-artifacts /etc/yum.repos.d/test-artifacts.repo
38+
# Clean up dnf
39+
dnf -y clean all
40+
rm -rf /var/cache /var/lib/dnf
41+
42+
# Finally, test our own linting
43+
# bootc container lint --fatal-warnings
44+
EORUN

hack/os-image-map.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"rhel-9.8": "images.paas.redhat.com/bootc/rhel-bootc:latest-9.8",
3+
"rhel-10.2": "images.paas.redhat.com/bootc/rhel-bootc:latest-10.2",
4+
"centos-9": "quay.io/centos-bootc/centos-bootc:stream9",
5+
"centos-10": "quay.io/centos-bootc/centos-bootc:stream10",
6+
"fedora-42": "quay.io/fedora/fedora-bootc:42",
7+
"fedora-43": "quay.io/fedora/fedora-bootc:43",
8+
"fedora-44": "quay.io/fedora/fedora-bootc:rawhide"
9+
}

hack/packit-reboot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
# tmt-reboot and reboot do not work in this case
4+
# reboot in ansible is the only way to reboot in tmt prepare
5+
- name: Reboot after system-reinstall-bootc
6+
hosts: all
7+
tasks:
8+
- name: Check system mode
9+
shell: bootc status --json | jq -r '.status.type'
10+
register: os_mode
11+
12+
# null type means package mode
13+
- name: Reboot system to image mode
14+
reboot:
15+
when: os_mode.stdout == 'null'
16+
17+
- name: Wait for connection to become reachable/usable
18+
wait_for_connection:
19+
delay: 30

hack/provision-packit.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
set -exuo pipefail
3+
4+
# Check environment
5+
printenv
6+
7+
# This script only runs on Packit and gating environment
8+
# Do not run this script for image mode system
9+
if command -v bootc >/dev/null && bootc status --json | grep '"type":"bootcHost"'; then
10+
echo "This system is Image Mode."
11+
exit 0
12+
fi
13+
14+
# Install required packages
15+
dnf install -y podman skopeo jq bootc system-reinstall-bootc expect ansible-core
16+
17+
# temp folder to save building files and folders
18+
BOOTC_TEMPDIR=$(mktemp -d)
19+
trap 'rm -rf -- "$BOOTC_TEMPDIR"' EXIT
20+
21+
# Copy files and folders in hack to TEMPDIR
22+
cp -a . "$BOOTC_TEMPDIR"
23+
24+
# Keep testing farm run folder
25+
cp -r /var/ARTIFACTS "$BOOTC_TEMPDIR"
26+
27+
# Copy bootc repo
28+
cp -r /var/share/test-artifacts "$BOOTC_TEMPDIR"
29+
30+
ARCH=$(uname -m)
31+
# Get OS info
32+
source /etc/os-release
33+
34+
# Some rhts-*, rstrnt-* and tmt-* commands are in /usr/local/bin
35+
if [[ -d /var/lib/tmt/scripts ]]; then
36+
cp -r /var/lib/tmt/scripts "$BOOTC_TEMPDIR"
37+
else
38+
cp -r /usr/local/bin "$BOOTC_TEMPDIR"
39+
fi
40+
41+
# Get base image URL
42+
TEST_OS="${ID}-${VERSION_ID}"
43+
BASE=$(cat os-image-map.json | jq --arg v "$TEST_OS" '.[$v]')
44+
45+
if [[ "$ID" == "rhel" ]]; then
46+
# OSCI gating only
47+
CURRENT_COMPOSE_ID=$(skopeo inspect --no-tags --retry-times=5 --tls-verify=false "docker://${BASE}" | jq -r '.Labels."redhat.compose-id"')
48+
49+
if [[ -n ${CURRENT_COMPOSE_ID} ]]; then
50+
if [[ ${CURRENT_COMPOSE_ID} == *-updates-* ]]; then
51+
BATCH_COMPOSE="updates/"
52+
else
53+
BATCH_COMPOSE=""
54+
fi
55+
else
56+
BATCH_COMPOSE="updates/"
57+
CURRENT_COMPOSE_ID=latest-RHEL-$VERSION_ID
58+
fi
59+
60+
# use latest compose if specific compose is not accessible
61+
RC=$(curl -skIw '%{http_code}' -o /dev/null "http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/STATUS")
62+
if [[ $RC != "200" ]]; then
63+
CURRENT_COMPOSE_ID=latest-RHEL-${VERSION_ID%%}
64+
fi
65+
66+
# generate rhel repo
67+
tee "${BOOTC_TEMPDIR}/rhel.repo" >/dev/null <<REPOEOF
68+
[rhel-baseos]
69+
name=baseos
70+
baseurl=http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/compose/BaseOS/${ARCH}/os/
71+
enabled=1
72+
gpgcheck=0
73+
74+
[rhel-appstream]
75+
name=appstream
76+
baseurl=http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/compose/AppStream/${ARCH}/os/
77+
enabled=1
78+
gpgcheck=0
79+
REPOEOF
80+
cp "${BOOTC_TEMPDIR}/rhel.repo" /etc/yum.repos.d
81+
fi
82+
83+
# Fedora CI: https://github.com/fedora-ci/dist-git-pipeline/blob/master/Jenkinsfile#L145
84+
# OSCI: https://gitlab.cee.redhat.com/osci-pipelines/dist-git-pipeline/-/blob/master/Jenkinsfile?ref_type=heads#L93
85+
if [[ -v KOJI_TASK_ID ]] || [[ -v CI_KOJI_TASK_ID ]]; then
86+
# Just left those ls commands here to ring the bell for me when something changed
87+
echo "$TMT_SOURCE_DIR"
88+
ls -al "$TMT_SOURCE_DIR"
89+
ls -al "$TMT_SOURCE_DIR/SRPMS"
90+
fi
91+
92+
ls -al /etc/yum.repos.d
93+
cat /etc/yum.repos.d/test-artifacts.repo
94+
ls -al /var/share/test-artifacts
95+
96+
# copy bootc rpm repo into image building root
97+
cp /etc/yum.repos.d/test-artifacts.repo "$BOOTC_TEMPDIR"
98+
99+
# Let's check things in hack folder
100+
ls -al "$BOOTC_TEMPDIR" "${BOOTC_TEMPDIR}/bin"
101+
102+
# Do not use just because it's only available on Fedora, not on CS and RHEL
103+
podman build --jobs=4 --from "$BASE" -v "$BOOTC_TEMPDIR":/bootc-test:z -t localhost/bootc-integration -f "${BOOTC_TEMPDIR}/Containerfile.packit" "$BOOTC_TEMPDIR"
104+
105+
# Keep these in sync with what's used in hack/lbi
106+
podman pull -q --retry 5 --retry-delay 5s quay.io/curl/curl:latest quay.io/curl/curl-base:latest registry.access.redhat.com/ubi9/podman:latest
107+
108+
# Run system-reinstall-bootc
109+
# TODO make it more scriptable instead of expect + send
110+
./system-reinstall-bootc.exp

hack/system-reinstall-bootc.exp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/expect -f
2+
3+
# Set a timeout
4+
set timeout 600
5+
6+
spawn system-reinstall-bootc localhost/bootc-integration
7+
8+
expect {
9+
"Then you can login as * using those keys. \\\[Y/n\\\]" {
10+
send "\r"
11+
exp_continue
12+
}
13+
"NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue? \\\[y/N\\\]" {
14+
send "y"
15+
exp_continue
16+
}
17+
"NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue? \\\[Y/n\\\]" {
18+
send "\r"
19+
exp_continue
20+
}
21+
"Press \\\<enter\\\> to continue" {
22+
send "\r"
23+
exp_continue
24+
}
25+
"Operation complete, rebooting in 10 seconds. Press Ctrl-C to cancel reboot, or press enter to continue immediately" {
26+
send "\x03"
27+
}
28+
}
29+
30+
# Wait for the program to complete
31+
expect eof

tmt/plans/integration.fmf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
provision:
22
how: virtual
3-
# Build via `./tests/build.sh`
43
image: $@{test_disk_image}
4+
prepare:
5+
# Replace package mode with image mode
6+
- how: shell
7+
script:
8+
- pwd && ls -al
9+
- if [[ -d hack ]]; then cd hack && ./provision-packit.sh; fi
10+
# tmt-reboot and reboot do not work in this case
11+
# reboot in ansible is the only way to reboot in tmt prepare
12+
- how: ansible
13+
playbook:
14+
- https://github.com/henrywang/bootc/raw/refs/heads/gating/hack/packit-reboot.yml
515
execute:
616
how: tmt
717

@@ -60,11 +70,18 @@ execute:
6070
how: fmf
6171
test:
6272
- /tmt/tests/test-26-examples-build
73+
adjust:
74+
- when: running_env == packit
75+
enabled: false
76+
because: packit tests use RPM bootc and does not install /usr/lib/bootc/initramfs-setup
6377

6478
/test-27-custom-selinux-policy:
6579
summary: Execute restorecon test on system with custom selinux policy
6680
discover:
6781
how: fmf
6882
test:
69-
- /tmt/tests/bootc-install-provision
7083
- /tmt/tests/test-27-custom-selinux-policy
84+
adjust:
85+
- when: running_env == packit
86+
enabled: false
87+
because: tmt-reboot does not work with systemd reboot in testing farm environment

tmt/tests/booted/test-custom-selinux-policy.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN mkdir /opt123; echo \"/opt123 /opt\" >> /etc/selinux/targeted/contexts/files
2323
podman build -t localhost/bootc-derived .
2424

2525
bootc switch --soft-reboot=auto --transport containers-storage localhost/bootc-derived
26-
26+
2727
assert (not ("/opt123" | path exists))
2828

2929
# https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test

0 commit comments

Comments
 (0)