Skip to content

Commit cfcb683

Browse files
committed
test: Add integration test running on github runner
Signed-off-by: Xiaofeng Wang <[email protected]>
1 parent 735a0b0 commit cfcb683

File tree

5 files changed

+310
-0
lines changed

5 files changed

+310
-0
lines changed

.github/workflows/integration.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: bootc integration test
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
jobs:
7+
build:
8+
strategy:
9+
matrix:
10+
test_os: [fedora-42]
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Build bootc and bootc image
18+
env:
19+
TEST_OS: ${{ matrix.test_os }}
20+
run: tests/build.sh
21+
22+
- name: Archive bootc disk image - disk.raw
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: bootc-${{ matrix.test_os }}-disk
26+
path: /tmp/tmp-bootc-build/disk.raw
27+
retention-days: 1
28+
29+
- name: Archive SSH private key - id_rsa
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: bootc-${{ matrix.test_os }}-id_rsa
33+
path: /tmp/tmp-bootc-build/id_rsa
34+
retention-days: 1
35+
36+
test:
37+
strategy:
38+
matrix:
39+
test_os: [fedora-42]
40+
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Install dependence
47+
run: |
48+
sudo apt-get update
49+
sudo apt install qemu-kvm qemu-system
50+
pip install --user tmt
51+
52+
- name: Create folder to save disk image
53+
run: mkdir -p /tmp/tmp-bootc-build
54+
55+
- name: Download disk.raw
56+
uses: actions/download-artifact@v4
57+
with:
58+
name: bootc-${{ matrix.test_os }}-disk
59+
path: /tmp/tmp-bootc-build
60+
61+
- name: Download id_rsa
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: bootc-${{ matrix.test_os }}-id_rsa
65+
path: /tmp/tmp-bootc-build
66+
67+
- name: Run test
68+
run: tests/test.sh

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ test-bin-archive: all
6666
test-tmt:
6767
cargo xtask test-tmt
6868

69+
test:
70+
tests/build.sh && tests/test.sh
71+
6972
# This gates CI by default. Note that for clippy, we gate on
7073
# only the clippy correctness and suspicious lints, plus a select
7174
# set of default rustc warnings.

tests/build.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
set -exuo pipefail
3+
4+
# This script basically builds bootc from source using the provided base image,
5+
# then runs the target tests.
6+
7+
mkdir -p /tmp/tmp-bootc-build
8+
BOOTC_TEMPDIR="/tmp/tmp-bootc-build"
9+
10+
# Get OS info from TEST_OS env
11+
OS_ID=$(echo "$TEST_OS" | cut -d '-' -f 1)
12+
OS_VERSION_ID=$(echo "$TEST_OS" | cut -d '-' -f 2)
13+
14+
# Base image
15+
case "$OS_ID" in
16+
"centos")
17+
TIER1_IMAGE_URL="quay.io/centos-bootc/centos-bootc:stream${OS_VERSION_ID}"
18+
;;
19+
"fedora")
20+
TIER1_IMAGE_URL="quay.io/fedora/fedora-bootc:${OS_VERSION_ID}"
21+
;;
22+
esac
23+
24+
# Some tmt-* commands to image
25+
TMT_REBOOT_FILE=$(sudo find /usr/lib/ -type f -name tmt-reboot)
26+
TMT_SCRIPTS_FOLDER=$(dirname "$TMT_REBOOT_FILE")
27+
cp -r "$TMT_SCRIPTS_FOLDER" "$BOOTC_TEMPDIR/bin"
28+
29+
CONTAINERFILE="${BOOTC_TEMPDIR}/Containerfile"
30+
tee "$CONTAINERFILE" > /dev/null << CONTAINERFILEOF
31+
FROM $TIER1_IMAGE_URL as build
32+
33+
WORKDIR /code
34+
35+
RUN <<EORUN
36+
set -xeuo pipefail
37+
. /usr/lib/os-release
38+
case \$ID in
39+
centos|rhel) dnf config-manager --set-enabled crb;;
40+
fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';;
41+
esac
42+
dnf -y builddep contrib/packaging/bootc.spec
43+
dnf -y install git-core
44+
EORUN
45+
46+
RUN mkdir -p /build/target/dev-rootfs
47+
# git config --global --add safe.directory /code to fix "fatal: detected dubious ownership in repository at '/code'" error
48+
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome git config --global --add safe.directory /code && make test-bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out
49+
50+
FROM $TIER1_IMAGE_URL
51+
52+
# Inject our built code
53+
COPY --from=build /out/bootc.tar.zst /tmp
54+
RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vrf /tmp/*
55+
56+
RUN <<EORUN
57+
set -xeuo pipefail
58+
59+
# Provision test requirement
60+
/code/hack/provision-derived.sh
61+
# Also copy in some default install configs we use for testing
62+
cp -a /code/hack/install-test-configs/* /usr/lib/bootc/install/
63+
# And some test kargs
64+
cp -a /code/hack/test-kargs/* /usr/lib/bootc/kargs.d/
65+
66+
# For testing farm
67+
mkdir -p -m 0700 /var/roothome
68+
69+
# Enable ttyS0 console
70+
mkdir -p /usr/lib/bootc/kargs.d/
71+
cat <<KARGEOF >> /usr/lib/bootc/kargs.d/20-console.toml
72+
kargs = ["console=ttyS0,115200n8"]
73+
KARGEOF
74+
75+
# For test-22-logically-bound-install
76+
cp -a /code/tmt/tests/lbi/usr/. /usr
77+
ln -s /usr/share/containers/systemd/curl.container /usr/lib/bootc/bound-images.d/curl.container
78+
ln -s /usr/share/containers/systemd/curl-base.image /usr/lib/bootc/bound-images.d/curl-base.image
79+
ln -s /usr/share/containers/systemd/podman.image /usr/lib/bootc/bound-images.d/podman.image
80+
81+
rm -rf /var/cache /var/lib/dnf
82+
EORUN
83+
84+
# Some tmt-* commands to /usr/local/bin
85+
COPY bin /usr/local/bin
86+
CONTAINERFILEOF
87+
88+
LOCAL_IMAGE="localhost/bootc:test"
89+
sudo podman build \
90+
--retry 5 \
91+
--retry-delay 5s \
92+
--tls-verify=false \
93+
-v "$(pwd)":/code:z \
94+
-t "$LOCAL_IMAGE" \
95+
-f "$CONTAINERFILE" \
96+
"$BOOTC_TEMPDIR"
97+
98+
SSH_KEY=${BOOTC_TEMPDIR}/id_rsa
99+
ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa-sha2-256 -b 2048
100+
101+
sudo truncate -s 10G "${BOOTC_TEMPDIR}/disk.raw"
102+
103+
# For test-22-logically-bound-install
104+
sudo podman pull --retry 5 --retry-delay 5s quay.io/curl/curl:latest
105+
sudo podman pull --retry 5 --retry-delay 5s quay.io/curl/curl-base:latest
106+
sudo podman pull --retry 5 --retry-delay 5s registry.access.redhat.com/ubi9/podman:latest
107+
108+
sudo podman run \
109+
--rm \
110+
--privileged \
111+
--pid=host \
112+
--tls-verify=false \
113+
--security-opt label=type:unconfined_t \
114+
-v /var/lib/containers:/var/lib/containers \
115+
-v /dev:/dev \
116+
-v "$BOOTC_TEMPDIR":/output \
117+
"$LOCAL_IMAGE" \
118+
bootc install to-disk \
119+
--filesystem "xfs" \
120+
--root-ssh-authorized-keys "/output/id_rsa.pub" \
121+
--karg=console=ttyS0,115200 \
122+
--generic-image \
123+
--via-loopback \
124+
/output/disk.raw

tests/test.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
set -exuo pipefail
3+
4+
# This script runs disk image with qemu-system and run tmt against this vm.
5+
6+
BOOTC_TEMPDIR="/tmp/tmp-bootc-build"
7+
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
8+
SSH_KEY=${BOOTC_TEMPDIR}/id_rsa
9+
10+
ARCH=$(uname -m)
11+
case "$ARCH" in
12+
"aarch64")
13+
sudo qemu-system-aarch64 \
14+
-name bootc-vm \
15+
-enable-kvm \
16+
-machine virt \
17+
-cpu host \
18+
-m 2G \
19+
-bios /usr/share/AAVMF/AAVMF_CODE.fd \
20+
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
21+
-net nic,model=virtio \
22+
-net user,hostfwd=tcp::2222-:22 \
23+
-display none \
24+
-daemonize
25+
;;
26+
"x86_64")
27+
sudo qemu-system-x86_64 \
28+
-name bootc-vm \
29+
-enable-kvm \
30+
-cpu host \
31+
-m 2G \
32+
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
33+
-net nic,model=virtio \
34+
-net user,hostfwd=tcp::2222-:22 \
35+
-display none \
36+
-daemonize
37+
;;
38+
*)
39+
redprint "Only support x86_64 and aarch64"
40+
exit 1
41+
;;
42+
esac
43+
44+
wait_for_ssh_up() {
45+
SSH_STATUS=$(ssh "${SSH_OPTIONS[@]}" -i "$SSH_KEY" -p 2222 root@"${1}" '/bin/bash -c "echo -n READY"')
46+
if [[ $SSH_STATUS == READY ]]; then
47+
echo 1
48+
else
49+
echo 0
50+
fi
51+
}
52+
53+
for _ in $(seq 0 30); do
54+
RESULT=$(wait_for_ssh_up "localhost")
55+
if [[ $RESULT == 1 ]]; then
56+
echo "SSH is ready now! 🥳"
57+
break
58+
fi
59+
sleep 10
60+
done
61+
62+
# Make sure VM is ready for testing
63+
ssh "${SSH_OPTIONS[@]}" \
64+
-i "$SSH_KEY" \
65+
-p 2222 \
66+
root@localhost \
67+
"bootc status"
68+
69+
tmt run --all --verbose provision --how connect --guest localhost --port 2222 --user root --key "$SSH_KEY" plan --name '^/tmt/plans/bootc-integration/'

tmt/plans/bootc-integration.fmf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
execute:
2+
how: tmt
3+
4+
/test-01-readonly:
5+
summary: Execute booted readonly/nondestructive tests
6+
discover:
7+
how: fmf
8+
test:
9+
- /tmt/tests/test-01-readonly
10+
11+
/test-20-local-upgrade:
12+
summary: Execute local upgrade tests
13+
discover:
14+
how: fmf
15+
test:
16+
- /tmt/tests/test-20-local-upgrade
17+
18+
/test-21-logically-bound-switch:
19+
summary: Execute logically bound images tests for switching images
20+
discover:
21+
how: fmf
22+
test:
23+
- /tmt/tests/test-21-logically-bound-switch
24+
25+
/test-22-logically-bound-install:
26+
summary: Execute logically bound images tests for switching images
27+
environment+:
28+
LBI: enabled
29+
discover:
30+
how: fmf
31+
test:
32+
- /tmt/tests/test-22-logically-bound-install
33+
34+
/test-23-install-outside-container:
35+
summary: Execute tests for installing outside of a container
36+
discover:
37+
how: fmf
38+
test:
39+
- /tmt/tests/test-23-install-outside-container
40+
41+
/test-24-local-upgrade-reboot:
42+
summary: Execute local upgrade tests with automated reboot
43+
discover:
44+
how: fmf
45+
test:
46+
- /tmt/tests/test-24-local-upgrade-reboot

0 commit comments

Comments
 (0)