#!/bin/bash## kola:## exclusive: false## description: Verify that bootupd works.# We generally implement project-owned tests run in the pipeline# and be able to run the existing bootupd tests.# See https://github.com/coreos/fedora-coreos-config/pull/677set -xeuo pipefail# shellcheck disable=SC1091. "$KOLA_EXT_DATA/commonlib.sh"# Not all streams on which this test runs has bootupd on all arches yet. On# x86_64 and aarch64, we always expect bootupd to be installed. On ppc64le and# s390x, let's just conditionally check that *if* bootupd is installed, then# it's functioning as expected. We can harden it more once we've hard cut over# to 9.4.current_arch="$(arch)"check_bootloader_service_inactive() {local bl_activebl_active=$(systemctl is-active bootloader-update.service 2>&1 || true)if [ "${bl_active}" != "inactive" ]; thenfatal "bootloader-update.service is ${bl_active} on ${current_arch}"fi}check_grub_version() {local package="$1"local format="$2"local versionversion=$(rpm -q "$package" --qf "$format")if [ -z "$version" ]; thenfatal "Could not retrieve version for package ${package}"fiif ! bootupctl status | grep -F "${version}"; thenfatal "bootupctl status output should include ${package} package version"fi}check_state_file=case "$current_arch" inaarch64|x86_64)# on these arches, we always expect state files to existcheck_state_file=1# aarch64 (and x86_64) uses uefi firmware, should check grub2check_grub_version "grub2-common" '%{EVR}';;ppc64le|s390x)# For ppc64le and s390x, only check if bootupd is installedif ! rpm -q bootupd &>/dev/null; thenexit 0ficheck_bootloader_service_inactive# ppc64le-specific checksif [ "$current_arch" = "ppc64le" ]; then# ppc64le has it if built by osbuild, otherwise not# https://github.com/coreos/fedora-coreos-tracker/issues/2187# We now also look for the aleph created by bootc as it# replaced the one created by osbuild since moving to# `bootc install` to create disk images.if [ -e /sysroot/.aleph-version.json ] || [ -e /sysroot/.bootc-aleph.json ]; thencheck_state_file=1fi# ppc64le (and x86_64) uses bios firmware, should check grub2-toolscheck_grub_version "grub2-tools" '%{NEVRA}'fi;;*) fatal "Unhandled architecture: ${current_arch}" ;;esacstate_file=/boot/bootupd-state.jsonif [ -n "${check_state_file}" ] && [ ! -f "${state_file}" ]; thenfatal "${state_file} not present"fi# Verify `bootupctl status` output contains related content.# https://github.com/coreos/bootupd/issues/694# The aleph-version field in JSON output was added in bootupd v0.2.36# TODO: remove check when bootupd >= 0.2.36 lands in RHCOSbootupd_version=$(rpm -q --queryformat '%{VERSION}' bootupd)required_version="0.2.36"if vergte "${bootupd_version}" "${required_version}"; thenif ! bootupctl status --json | jq -e '."aleph-version"' > /dev/null; thenfatal "bootupctl status --json output should include 'aleph-version'"fielseif ! bootupctl status | grep -i "aleph version"; thenfatal "bootupctl status output should include 'Aleph version'"fifiok bootupctl