Skip to content

Commit db36a9c

Browse files
tests: Update tests for new and old layouts
Update e2e tests to handle both, new i.e. `/usr/lib/efi`, and old i.e. `/usr/lib/bootupd/updates` layouts, depending upon the existence of `/usr/lib/efi` Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 0e5fe60 commit db36a9c

3 files changed

Lines changed: 81 additions & 24 deletions

File tree

tests/e2e-update/e2e-update-in-vm.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,21 @@ ok validate
5353

5454
bootupctl status | tee out.txt
5555
assert_file_has_content_literal out.txt 'Component EFI'
56-
assert_file_has_content_literal out.txt ' Installed: grub2-1:'
57-
assert_not_file_has_content out.txt ' Installed:.*test_bootupd_payload'
58-
assert_not_file_has_content out.txt ' Installed:.*'"${TARGET_GRUB_EVR}"
59-
assert_file_has_content out.txt 'Update: Available:.*'"${TARGET_GRUB_EVR}"
60-
assert_file_has_content out.txt 'Update: Available:.*test_bootupd_payload-1.0'
56+
57+
if [[ -d /usr/lib/efi ]]; then
58+
assert_file_has_content_literal out.txt ' Installed: grub2-1:'
59+
assert_not_file_has_content out.txt ' Installed:.*test_bootupd_payload'
60+
assert_not_file_has_content out.txt ' Installed:.*'"${TARGET_GRUB_EVR}"
61+
assert_file_has_content out.txt 'Update: Available:.*'"${TARGET_GRUB_EVR}"
62+
assert_file_has_content out.txt 'Update: Available:.*test_bootupd_payload-1.0'
63+
else
64+
assert_file_has_content_literal out.txt ' Installed: grub2-efi-x64-'
65+
assert_not_file_has_content out.txt ' Installed:.*test_bootupd_payload'
66+
assert_not_file_has_content out.txt ' Installed:.*'"${TARGET_GRUB_PKG}"
67+
assert_file_has_content out.txt 'Update: Available:.*'"${TARGET_GRUB_PKG}"
68+
assert_file_has_content out.txt 'Update: Available:.*test_bootupd_payload-1.0'
69+
fi
70+
6171
bootupctl status --print-if-available > out.txt
6272
assert_file_has_content_literal 'out.txt' 'Updates available: BIOS EFI'
6373
ok update avail

tests/e2e-update/e2e-update.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ case $(arch) in
7777
*) fatal "Unhandled arch $(arch)";;
7878
esac
7979
target_grub_name=grub2-efi-${grubarch}
80+
target_grub_pkg=$(rpm -qp --queryformat='%{nevra}\n' ${overrides}/rpm/${target_grub_name}-2*.rpm)
8081
target_grub_evr=$(rpm -qp --queryformat='%{evr}\n' ${overrides}/rpm/${target_grub_name}-2*.rpm)
8182
target_commit=$(cosa meta --get-value ostree-commit)
8283
echo "Target commit: ${target_commit}"
@@ -97,6 +98,7 @@ systemd:
9798
RemainAfterExit=yes
9899
Environment=TARGET_COMMIT=${target_commit}
99100
Environment=TARGET_GRUB_NAME=${target_grub_name}
101+
Environment=TARGET_GRUB_PKG=${target_grub_pkg}
100102
Environment=TARGET_GRUB_EVR=${target_grub_evr}
101103
Environment=SRCDIR=/run/bootupd-source
102104
# Run via shell because selinux denies systemd writing to 9p apparently

tests/kola/test-bootupd

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -xeuo pipefail
44
. ${KOLA_EXT_DATA}/libtest.sh
55

66
tmpdir=$(mktemp -d)
7-
cd ${tmpdir}
7+
cd "${tmpdir}"
88
echo "using tmpdir: ${tmpdir}"
99
touch .testtmp
1010
trap cleanup EXIT
@@ -21,20 +21,38 @@ function cleanup () {
2121

2222
# Mount the EFI partition.
2323
tmpefimount=$(mount_tmp_efi)
24-
bootmount=/boot
24+
# Path to <tmp_efi_mount>/EFI
2525
tmpefidir=${tmpefimount}/EFI
26+
# /usr/lib/bootupd/updates
2627
bootupdir=/usr/lib/bootupd/updates
28+
# fedora
2729
efisubdir=fedora
30+
# /usr/lib/bootupd/updates/EFI
31+
efiupdir=${bootupdir}/EFI
32+
# /usr/lib/ostree-boot/efi/EFI
33+
ostbaseefi=/usr/lib/ostree-boot/efi/EFI
34+
# /usr/lib/ostree-boot/efi/EFI/fedora
35+
ostefi=${ostbaseefi}/${efisubdir}
2836
shimx64=shimx64.efi
2937
grubx64=grubx64.efi
30-
efilib=/usr/lib/efi
38+
usrlibefi=/usr/lib/efi
39+
# Path to <tmp_efi_mount>/EFI/fedora
3140
tmpefisubdir=${tmpefidir}/${efisubdir}
3241

42+
if [ -d efilib ]; then efilib_exists=true; else efilib_exists=false; fi
43+
3344
prepare_efi_update() {
3445
test -w /usr
3546
rm -rf ${bootupdir}/EFI.json
3647
}
3748

49+
prepare_efi_update_old_layout() {
50+
test -w /usr
51+
mkdir -p ${ostbaseefi}
52+
cp -a ${efiupdir}.orig/* ${ostbaseefi}/
53+
rm -rf ${efiupdir} ${bootupdir}/EFI.json
54+
}
55+
3856
# backup: update_metadata_move EFI EFI-bak
3957
# restore: update_metadata_move EFI-bak EFI
4058
update_metadata_move() {
@@ -48,18 +66,30 @@ update_metadata_move() {
4866
mv -- "$src" "$dst"
4967
}
5068

51-
# Find the files under usr/lib/efi after transferred
52-
shim_path=$(find ${efilib} -name shim.efi)
53-
shimx64_path=$(find ${efilib} -name ${shimx64})
54-
grubx64_path=$(find ${efilib} -name ${grubx64})
69+
if $efilib_exists; then
70+
# Find the files under usr/lib/efi after transferred
71+
shim_path=$(find ${usrlibefi} -name shim.efi)
72+
shimx64_path=$(find ${usrlibefi} -name ${shimx64})
73+
grubx64_path=$(find ${usrlibefi} -name ${grubx64})
5574

56-
test -n "${shimx64_path}" && test -n "${grubx64_path}"
57-
! test -d "/usr/lib/bootupd/updates/EFI"
75+
test -n "${shimx64_path}" && test -n "${grubx64_path}"
76+
test -d "/usr/lib/bootupd/updates/EFI" && exit 1
77+
else
78+
shim_path=$(find ${bootupdir} -name shim.efi)
79+
shimx64_path=$(find ${bootupdir} -name ${shimx64})
80+
grubx64_path=$(find ${bootupdir} -name ${grubx64})
81+
82+
test -n "${shimx64_path}" && test -n "${grubx64_path}"
83+
fi
5884

5985
bootupctl status > out.txt
6086
evr=$(rpm -q grub2-common --qf '%{EVR}')
6187
assert_file_has_content_literal out.txt 'Component EFI'
62-
assert_file_has_content_literal out.txt ' Installed: grub2-'"${evr}"
88+
if $efilib_exists; then
89+
assert_file_has_content_literal out.txt ' Installed: grub2-'"${evr}"
90+
else
91+
assert_file_has_content_literal out.txt ' Installed: grub2-efi-x64-'
92+
fi
6393
assert_file_has_content_literal out.txt 'Update: At latest version'
6494
assert_file_has_content out.txt '^CoreOS aleph version:'
6595
ok status
@@ -75,10 +105,16 @@ assert_file_has_content err.txt 'error: This command requires root privileges'
75105
# From here we'll fake updates
76106
test -w /usr || rpm-ostree usroverlay
77107

78-
prepare_efi_update
108+
if $efilib_exists; then
109+
prepare_efi_update
110+
rm -v "${shim_path}"
111+
echo bootupd-test-changes >> "${grubx64_path}"
112+
else
113+
prepare_efi_update_old_layout
114+
rm -v ${ostefi}/shim.efi
115+
echo bootupd-test-changes >> ${ostefi}/grubx64.efi
116+
fi
79117

80-
rm -v ${shim_path}
81-
echo bootupd-test-changes >> ${grubx64_path}
82118
/usr/libexec/bootupd generate-update-metadata /
83119
ver=$(jq -r .version < ${bootupdir}/EFI.json)
84120
vers=$(jq -r .versions < ${bootupdir}/EFI.json)
@@ -92,14 +128,23 @@ mv new.json ${bootupdir}/EFI.json
92128

93129
bootupctl status | tee out.txt
94130
assert_file_has_content_literal out.txt 'Component EFI'
95-
assert_file_has_content_literal out.txt ' Installed: grub2-'"${evr}"
131+
if $efilib_exists; then
132+
assert_file_has_content_literal out.txt ' Installed: grub2-'"${evr}"
133+
else
134+
assert_file_has_content_literal out.txt ' Installed: grub2-efi-x64-'
135+
fi
96136
assert_not_file_has_content out.txt ' Installed: grub2-.*,test'
97137
assert_file_has_content_literal out.txt 'Update: Available:'
98138
ok update avail
99139

100140
bootupctl status --json > status.json
101141
jq -r '.components.EFI.installed.version' < status.json > installed.txt
102-
assert_file_has_content installed.txt '^grub2-'"${evr}"
142+
143+
if $efilib_exists; then
144+
assert_file_has_content installed.txt '^grub2-'"${evr}"
145+
else
146+
assert_file_has_content installed.txt '^grub2-efi-x64'
147+
fi
103148

104149
bootupctl update | tee out.txt
105150
assert_file_has_content out.txt 'Updated EFI: grub2-.*,test'
@@ -115,13 +160,13 @@ ok validate after update
115160

116161
# FIXME see above
117162
# assert_file_has_content ${tmpefidir}/${efisubdir}/somenew.efi 'somenewfile'
118-
if test -f ${tmpefisubdir}/shim.efi; then
163+
if test -f "${tmpefisubdir}/shim.efi"; then
119164
fatal "failed to remove file"
120165
fi
121-
if ! grep -q 'bootupd-test-changes' ${tmpefisubdir}/${grubx64}; then
166+
if ! grep -q 'bootupd-test-changes' "${tmpefisubdir}/${grubx64}"; then
122167
fatal "failed to update modified file"
123168
fi
124-
cmp ${tmpefisubdir}/${shimx64} ${shimx64_path}
169+
cmp "${tmpefisubdir}/${shimx64}" "${shimx64_path}"
125170
ok filesystem changes
126171

127172
bootupctl update | tee out.txt
@@ -162,7 +207,7 @@ else
162207
assert_not_file_has_content out.txt 'Adopted and updated: EFI:'
163208
fi
164209

165-
echo "some additions" >> ${tmpefisubdir}/${shimx64}
210+
echo "some additions" >> "${tmpefisubdir}/${shimx64}"
166211
if bootupctl validate 2>err.txt; then
167212
fatal "unexpectedly passed validation"
168213
fi

0 commit comments

Comments
 (0)