Skip to content

Commit 3def229

Browse files
ci: Add tests for grub-cc and systemd-boot
We don't have e2e upgrade tests for now, but we can atleast test if the installations are working well Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 3a798bd commit 3def229

3 files changed

Lines changed: 106 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
concurrency:
1414
group: ${{ github.workflow }}-${{ github.ref }}
15-
cancel-in-progress: true
15+
cancel-in-progress: false
1616

1717
env:
1818
CARGO_TERM_COLOR: always
@@ -74,7 +74,7 @@ jobs:
7474
build_args=()
7575
7676
if [[ "${{ matrix.grubcc }}" == "1" ]]; then
77-
dockerfile=Dockerfile.grubcc
77+
dockerfile=Dockerfile.bls
7878
build_args=(--build-arg "grubcc=${{ matrix.grubcc }}")
7979
fi
8080
@@ -143,3 +143,13 @@ jobs:
143143
run: |
144144
set -xeuo pipefail
145145
sudo podman run --rm -v $PWD:/run/src -w /run/src --privileged "$IMG_NAME" tests/tests/generate-update-metadata.sh
146+
147+
- name: Test GrubCC and SystemdBoot
148+
run: |
149+
if [[ "${{ matrix.grubcc }}" == "0" ]]; then
150+
exit 0
151+
fi
152+
153+
set -xeuo pipefail
154+
sudo ./scripts/test-bootloader.sh "$IMG_NAME" "grub-cc"
155+
sudo ./scripts/test-bootloader.sh "$IMG_NAME" "systemd-boot"

Dockerfile.grubcc renamed to Dockerfile.bls

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Dockerfile to test GrubCC and systemd-boot
12
# Build from the current git into a fedora44 container image.
23

34
ARG base=quay.io/fedora/fedora-bootc:44
@@ -42,15 +43,14 @@ mv ./*.rpm grub-cc.rpm
4243
EOF
4344

4445
FROM $base
45-
ARG grubcc
4646
# Clean out the default to ensure we're using our updated content
4747
RUN rpm -e bootupd
4848
COPY --from=build /out/ /
4949
COPY --from=grub-cc-download /grub-cc.rpm /var/grub-cc.rpm
5050
# Install bootc from copr
5151
RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EORUN
5252
set -xeuo pipefail
53-
dnf -y install dnf-plugins-core bootc
53+
dnf -y install dnf-plugins-core bootc systemd-boot tree
5454
dnf clean all
5555
rm -rf /var/log
5656
rm -rf /var/lib
@@ -59,6 +59,24 @@ rm -rf /run/rhsm
5959
rm -rf /tmp/*
6060
EORUN
6161

62+
# Install systemd-boot
63+
RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EOF
64+
set -eux
65+
# epoch for systemd-boot-unsigned is "(none)"
66+
evr=$(rpm -q --qf '%{EPOCH}:%{VERSION}-%{RELEASE}\n' systemd-boot-unsigned)
67+
rpm -ql systemd-boot-unsigned
68+
69+
. /etc/os-release
70+
71+
# Create the expected directory structure at /usr/lib/efi/grub-cc/<evr>/EFI/fedora/
72+
mkdir -p "/usr/lib/efi/systemd-boot/${evr}/EFI/$ID"
73+
74+
# TODO: Handle arm
75+
cp /usr/lib/systemd/boot/efi/systemd-boot*.efi "/usr/lib/efi/systemd-boot/${evr}/EFI/$ID/grubx64.efi"
76+
77+
EOF
78+
79+
# Install grub-cc
6280
RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EOF
6381

6482
set -eux
@@ -68,11 +86,6 @@ cleanup() {
6886
rm -rvf /var/grub-cc*
6987
}
7088

71-
if [[ ${grubcc} != 1 ]]; then
72-
cleanup
73-
exit 0
74-
fi
75-
7689
# Extract and install grub-cc at the correct path
7790
mkdir /var/grub-cc
7891
rpm2archive /var/grub-cc.rpm | tar -xvz -C /var/grub-cc

scripts/test-bootloader.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
IMG_NAME=$1
6+
BOOTLOADER=$2
7+
8+
cat <<-EOF > sfdisk-buf
9+
label: gpt
10+
label-id: 65be9332-59ba-11f1-9b26-6a8e2ab625e4
11+
size=1Gib, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, name="EFI-SYSTEM"
12+
type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, name="root"
13+
EOF
14+
15+
truncate -s4G "${BOOTLOADER}-test.img"
16+
17+
cat sfdisk-buf | sfdisk --wipe=always "${BOOTLOADER}-test.img"
18+
19+
mkdir -p /var/mnt
20+
21+
# Also update kernel partition tables
22+
loopdev=$(losetup --find --show --partscan "${BOOTLOADER}-test.img")
23+
sleep 1
24+
25+
mkfs.vfat "${loopdev}p1"
26+
mkfs.ext4 "${loopdev}p2"
27+
28+
mount "${loopdev}p2" /var/mnt
29+
30+
ESP="/var/mnt/efi"
31+
32+
mkdir -p $ESP
33+
mount "${loopdev}p1" $ESP
34+
35+
36+
# Test installing the bootloader
37+
podman run --rm --net=host --privileged --pid=host \
38+
--privileged \
39+
--security-opt label=type:unconfined_t \
40+
--env RUST_LOG=trace \
41+
-v /dev:/dev \
42+
-v /var/mnt:/var/mnt \
43+
"$IMG_NAME" \
44+
bootupctl backend install --bootloader "$BOOTLOADER" /var/mnt -vvvv
45+
46+
# Make sure bootupd-state.json is in the esp
47+
test -f "$ESP/bootupd-state.json"
48+
49+
version=$(cat "$ESP/bootupd-state.json" | jq -r ".installed.EFI.meta.version")
50+
51+
if [[ $version != *shim* ]]; then echo "shim not found in version"; exit 1; fi
52+
if [[ $version != *"$BOOTLOADER"* ]]; then echo "$BOOTLOADER not found in version"; exit 1; fi
53+
54+
# Test if the correct binary has been installed
55+
actualShasum=$(podman run --rm "$IMG_NAME" find "/usr/lib/efi/$BOOTLOADER" -type f -exec sha512sum {} + | awk '{print $1}')
56+
actualShasum="sha512:$actualShasum"
57+
58+
if [[ $(uname -m) == "x64" ]]; then
59+
grubName="grubx64.efi"
60+
else
61+
grubName="grubaa64.efi"
62+
fi
63+
64+
# TODO: Remove hardcoded "fedora" once we have support in centos
65+
storedShasum=$(cat "$ESP/bootupd-state.json" | jq -r --arg grub "$grubName" '.installed.EFI.filetree.children["fedora/\($grub)"].sha512')
66+
67+
test "$actualShasum" == "$storedShasum"
68+
69+
efiBinShasum=$(find "$ESP" -type f -name "$grubName" -exec sha512sum {} + | awk '{print $1}')
70+
efiBinShasum="sha512:$efiBinShasum"
71+
72+
test "$efiBinShasum" == "$actualShasum"
73+
74+
umount -Rl /var/mnt

0 commit comments

Comments
 (0)