Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cci.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cosaPod(memory: "7168Mi", cpu: "4") {
// The previous e2e leaves things only having built an ostree update
shwrap("cosa build && cosa osbuild qemu")
// bootupd really can't break upgrades for the OS
kola(cosaDir: "${env.WORKSPACE}", extraArgs: "ext.*bootupd*", skipUpgrade: true, skipBasicScenarios: true)
kola(cosaDir: "${env.WORKSPACE}", extraArgs: "ext.*bootupd* --qemu-firmware=uefi", skipUpgrade: true, skipBasicScenarios: true)
}
} finally {
archiveArtifacts allowEmptyArchive: true, artifacts: 'tmp/console.txt'
Expand Down
7 changes: 6 additions & 1 deletion src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ impl Component for Bios {
}

fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {
get_component_update(sysroot, self)
let content_metadata = get_component_update(sysroot, self)?;
// Failed as expected if booted with BIOS and no update metadata
if content_metadata.is_none() && !sysroot.exists("sys/firmware/efi")? {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not !is_efi_booted instead of testing the /sys path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concern that it might be not suitable for ppc, as is_efi_booted() is for x86_64, or maybe it is better to move is_efi_booted() out of efi.rs. WDYT?

anyhow::bail!("Failed to find BIOS update metadata");
}
Ok(content_metadata)
}

fn run_update(&self, rootcxt: &RootContext, _: &InstalledContent) -> Result<InstalledContent> {
Expand Down
7 changes: 6 additions & 1 deletion src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,12 @@ impl Component for Efi {
}

fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {
get_component_update(sysroot, self)
let content_metadata = get_component_update(sysroot, self)?;
// Failed as expected if booted with EFI and no update metadata
if content_metadata.is_none() && is_efi_booted()? {
anyhow::bail!("Failed to find EFI update metadata");
}
Ok(content_metadata)
}

fn validate(&self, current: &InstalledContent) -> Result<ValidationResult> {
Expand Down
50 changes: 45 additions & 5 deletions tests/kola/test-bootupd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ prepare_efi_update() {
rm -rf ${bootupdir}/EFI.json
}

# backup: update_metadata_move EFI EFI-bak
# restore: update_metadata_move EFI-bak EFI
update_metadata_move() {
local src="${bootupdir}/$1.json"
local dst="${bootupdir}/$2.json"

[ -w "$bootupdir" ]
[ -f "$src" ]
[ ! -e "$dst" ]

mv -- "$src" "$dst"
}

# Find the files under usr/lib/efi after transferred
shim_path=$(find ${efilib} -name shim.efi)
shimx64_path=$(find ${efilib} -name ${shimx64})
Expand Down Expand Up @@ -115,12 +128,39 @@ bootupctl update | tee out.txt
assert_file_has_content_literal out.txt 'No update available for any component'
assert_not_file_has_content_literal out.txt 'Updated EFI'

# Verify that we skipped update if update metadata not found
mount -o remount,rw /boot
rm -f /boot/bootupd-state.json ${bootupdir}/BIOS.json
bootupctl update | tee out.txt
assert_file_has_content out.txt 'Adopted and updated: EFI: grub2-.*'
assert_not_file_has_content out.txt 'Adopted and updated: BIOS:'
rm -f /boot/bootupd-state.json

if [ -d /sys/firmware/efi ]; then
# EFI boot: verify update failed if metadata is missing EFI.json
# Backup EFI.json and restore it later, or validate will fail
update_metadata_move EFI EFI-bak
if bootupctl update 2>err.txt; then
fatal "Should fail as missing EFI update metadata (booted with EFI)"
fi
update_metadata_move EFI-bak EFI

# Should succeed if BIOS metadata is missing
rm -f ${bootupdir}/BIOS.json
bootupctl update | tee out.txt
assert_file_has_content out.txt 'Adopted and updated: EFI:'
assert_not_file_has_content out.txt 'Adopted and updated: BIOS:'

else
# BIOS boot: verify update failed if metadata is missing BIOS.json
# Backup BIOS.json and restore it later, or validate will fail
update_metadata_move BIOS BIOS-bak
if bootupctl update 2>err.txt; then
fatal "Should fail as missing BIOS update metadata (booted with BIOS)"
fi
update_metadata_move BIOS-bak BIOS

# Should succeed if EFI metadata is missing
rm -f ${bootupdir}/EFI.json
bootupctl update | tee out.txt
assert_file_has_content out.txt 'Adopted and updated: BIOS:'
assert_not_file_has_content out.txt 'Adopted and updated: EFI:'
fi

echo "some additions" >> ${tmpefisubdir}/${shimx64}
if bootupctl validate 2>err.txt; then
Expand Down