Skip to content

eBPF-based security platform

contrib: support Fedora and RHEL hosts for the test VM

Puranjay Mohane55822bdfa8a
diff --git a/contrib/build-kernel-package.sh b/contrib/build-kernel-package.sh
index a798ecba..4f987334 100755
--- a/contrib/build-kernel-package.sh
+++ b/contrib/build-kernel-package.sh
@@ -51,7 +51,7 @@ if [[ -z "${KERNEL_LOCALVERSION:-}" ]]; then
KERNEL_LOCALVERSION="-shirudo-${KERNEL_TAG#v}"
fi
fi
-PACKAGE_FORMAT="${PACKAGE_FORMAT:-deb}"
+PACKAGE_FORMAT="${PACKAGE_FORMAT:-$TEST_VM_HOST_PKG_FORMAT}"
case "$PACKAGE_FORMAT" in
deb)
PACKAGE_SUFFIX="debs"
diff --git a/contrib/build-test-vm-bundle.sh b/contrib/build-test-vm-bundle.sh
index 40893ca2..81b2794a 100755
--- a/contrib/build-test-vm-bundle.sh
+++ b/contrib/build-test-vm-bundle.sh
@@ -46,11 +46,12 @@ validate_package_cert()
die "TEST_VM_PACKAGE_CERT is not a readable, non-empty regular file: $PACKAGE_CERT"
}
+# require_command COMMAND DEB-PACKAGE [RPM-PACKAGE]
require_command()
{
- local command_name="$1" package_name="$2"
+ local command_name="$1" deb_package="$2" rpm_package="${3:-$2}"
command -v "$command_name" >/dev/null 2>&1 ||
- die "missing host command: $command_name (install with: sudo apt-get install -y $package_name)"
+ die "missing host command: $command_name (install with: $(test_vm_install_cmd "$(test_vm_pkg "$deb_package" "$rpm_package")"))"
}
check_libguestfs_host()
@@ -82,6 +83,8 @@ prepare_ubuntu_libguestfs_kernel()
{
local cache_dir index metadata package version kernel_version filename deb tmp
local module_package module_filename kernel_info module_info module_root
+
+ require_command dpkg-deb dpkg
cache_dir="$LIBGUESTFS_KERNEL_CACHE/$UBUNTU_CODENAME"
index="$cache_dir/Packages.gz"
metadata="$cache_dir/kernel.info"
@@ -187,13 +190,15 @@ prepare_ubuntu_libguestfs_kernel()
return 0
}
+# Each entry is command:Debian package:RPM package.
for dependency in \
- "flock:util-linux" "curl:curl" "sha256sum:coreutils" "awk:gawk" \
- "qemu-img:qemu-utils" "virt-customize:libguestfs-tools" \
- "dpkg-deb:dpkg" "openssl:openssl" \
- "gzip:gzip" "depmod:kmod"; do
- IFS=: read -r command_name package_name <<<"$dependency"
- require_command "$command_name" "$package_name"
+ "flock:util-linux:util-linux" "curl:curl:curl" \
+ "sha256sum:coreutils:coreutils" "awk:gawk:gawk" \
+ "qemu-img:qemu-utils:qemu-img" \
+ "virt-customize:libguestfs-tools:guestfs-tools" \
+ "openssl:openssl:openssl" "gzip:gzip:gzip" "depmod:kmod:kmod"; do
+ IFS=: read -r command_name deb_package rpm_package <<<"$dependency"
+ require_command "$command_name" "$deb_package" "$rpm_package"
done
check_libguestfs_host
@@ -267,7 +272,7 @@ bundle_is_current()
}
command -v flock >/dev/null 2>&1 ||
- die "flock is required; install it with: sudo apt-get install -y util-linux"
+ die "flock is required; install it with: $(test_vm_install_cmd util-linux)"
validate_package_cert
diff --git a/contrib/prepare-test-vm-runtime.sh b/contrib/prepare-test-vm-runtime.sh
index 1ce81f91..9060937e 100755
--- a/contrib/prepare-test-vm-runtime.sh
+++ b/contrib/prepare-test-vm-runtime.sh
@@ -6,6 +6,9 @@
set -euo pipefail
+# shellcheck source=contrib/test-vm-arch.sh
+. "$(dirname "${BASH_SOURCE[0]}")/test-vm-arch.sh"
+
ROOTFS=
CACHE_DIR=
PACKAGE_FILE=
@@ -35,9 +38,9 @@ done
die "runtime disk size must be a positive QEMU size such as 4G or 512M"
command -v qemu-img >/dev/null 2>&1 ||
- die "qemu-img is required; install it with: sudo apt-get install -y qemu-utils"
+ die "qemu-img is required; install it with: $(test_vm_install_cmd "$(test_vm_pkg qemu-utils qemu-img)")"
command -v virt-customize >/dev/null 2>&1 ||
- die "virt-customize is required; install it with: sudo apt-get install -y libguestfs-tools"
+ die "virt-customize is required; install it with: $(test_vm_install_cmd "$(test_vm_pkg libguestfs-tools guestfs-tools)")"
IMAGE="$CACHE_DIR/$RUNTIME_KEY.qcow2"
if [[ -s "$IMAGE" ]]; then
diff --git a/contrib/test-vm-arch.sh b/contrib/test-vm-arch.sh
index d1a691ad..c5b89cdc 100644
--- a/contrib/test-vm-arch.sh
+++ b/contrib/test-vm-arch.sh
@@ -2,11 +2,12 @@
# shellcheck shell=sh disable=SC2034
# Copyright (c) 2026 Authors of shirudo
#
-# Host architecture names for the test VM tooling. Sourced by the contrib
-# scripts and evaluated by testing/Makefile, so POSIX sh. TEST_VM_ARCH
-# overrides the detected architecture. Any other than x86-64 and arm64
-# gets the x86-64 names, so that host-side targets still evaluate, and
-# TEST_VM_ARCH_SUPPORTED=0, which refuses a kernel build and a boot.
+# Host architecture and package manager for the test VM tooling. Sourced
+# by the contrib scripts and evaluated by testing/Makefile, so POSIX sh.
+# TEST_VM_ARCH and TEST_VM_HOST_PKG override the detection. An
+# architecture other than x86-64 and arm64 gets the x86-64 names, so that
+# host-side targets still evaluate, and TEST_VM_ARCH_SUPPORTED=0, which
+# refuses a kernel build and a boot.
: "${TEST_VM_ARCH:=$(uname -m)}"
@@ -20,6 +21,7 @@ esac
if [ "$TEST_VM_ARCH" = aarch64 ]; then
TEST_VM_ARCH_QEMU=qemu-system-aarch64
TEST_VM_ARCH_QEMU_DEB=qemu-system-arm
+ TEST_VM_ARCH_QEMU_RPM=qemu-system-aarch64-core
TEST_VM_ARCH_CONSOLE=ttyAMA0
TEST_VM_ARCH_KIMAGE=Image
TEST_VM_ARCH_KIMAGE_SRC=arch/arm64/boot/Image
@@ -28,9 +30,49 @@ if [ "$TEST_VM_ARCH" = aarch64 ]; then
else
TEST_VM_ARCH_QEMU=qemu-system-x86_64
TEST_VM_ARCH_QEMU_DEB=qemu-system-x86
+ TEST_VM_ARCH_QEMU_RPM=qemu-system-x86-core
TEST_VM_ARCH_CONSOLE=ttyS0
TEST_VM_ARCH_KIMAGE=bzImage
TEST_VM_ARCH_KIMAGE_SRC=arch/x86/boot/bzImage
TEST_VM_ARCH_DEB=amd64
TEST_VM_ARCH_MIRROR=https://archive.ubuntu.com/ubuntu
fi
+
+# dnf on Fedora, RHEL and their derivatives as os-release names them, apt
+# anywhere else.
+if [ -z "${TEST_VM_HOST_PKG:-}" ]; then
+ TEST_VM_HOST_PKG=apt
+ if [ -r /etc/os-release ]; then
+ case " $(. /etc/os-release; echo "${ID:-} ${ID_LIKE:-}") " in
+ *" fedora "*|*" rhel "*|*" centos "*) TEST_VM_HOST_PKG=dnf ;;
+ esac
+ fi
+fi
+if [ "$TEST_VM_HOST_PKG" = dnf ]; then
+ TEST_VM_HOST_PKG_FORMAT=rpm
+else
+ TEST_VM_HOST_PKG=apt
+ TEST_VM_HOST_PKG_FORMAT=deb
+fi
+
+# test_vm_pkg DEB RPM: the name of the package on this host.
+test_vm_pkg()
+{
+ if [ "$TEST_VM_HOST_PKG" = dnf ]; then
+ printf '%s\n' "$2"
+ else
+ printf '%s\n' "$1"
+ fi
+}
+
+# test_vm_install_cmd PACKAGE...: the command that installs them here.
+test_vm_install_cmd()
+{
+ if [ "$TEST_VM_HOST_PKG" = dnf ]; then
+ printf 'sudo dnf install -y'
+ else
+ printf 'sudo apt-get install -y --no-install-recommends'
+ fi
+ printf ' %s' "$@"
+ printf '\n'
+}
diff --git a/contrib/test-vm.sh b/contrib/test-vm.sh
index f7bdc11a..b608fef8 100755
--- a/contrib/test-vm.sh
+++ b/contrib/test-vm.sh
@@ -35,7 +35,8 @@ fi
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# shellcheck source=contrib/test-vm-arch.sh
. "${REPO_ROOT}/contrib/test-vm-arch.sh"
-QEMU_BIN="$TEST_VM_ARCH_QEMU"
+# TEST_VM_QEMU names another emulator, such as RHEL's /usr/libexec/qemu-kvm.
+QEMU_BIN="${TEST_VM_QEMU:-$TEST_VM_ARCH_QEMU}"
VM_ROOT_INPUT="${TEST_VM_WORK_DIR:-${REPO_ROOT}/build/test-vm}"
if [[ "$VM_ROOT_INPUT" == /* ]]; then
VM_ROOT="$VM_ROOT_INPUT"
@@ -112,18 +113,19 @@ HOST_MEMORY_REPORT=""
FAILURE_LOG_DIR=""
FINAL_STATUS=1
LEAVE_RUNNING=0
+# Each entry is command:Debian package:RPM package.
HOST_DEPENDENCIES=(
- "curl:curl"
- "sha256sum:coreutils"
- "awk:mawk"
- "${QEMU_BIN}:${TEST_VM_ARCH_QEMU_DEB}"
- "qemu-img:qemu-utils"
- "swtpm:swtpm"
- "cloud-localds:cloud-image-utils"
- "timeout:coreutils"
- "flock:util-linux"
- "ssh-keygen:openssh-client"
- "ss:iproute2"
+ "curl:curl:curl"
+ "sha256sum:coreutils:coreutils"
+ "awk:mawk:gawk"
+ "${QEMU_BIN}:${TEST_VM_ARCH_QEMU_DEB}:${TEST_VM_ARCH_QEMU_RPM}"
+ "qemu-img:qemu-utils:qemu-img"
+ "swtpm:swtpm:swtpm"
+ "cloud-localds:cloud-image-utils:cloud-utils"
+ "timeout:coreutils:coreutils"
+ "flock:util-linux:util-linux"
+ "ssh-keygen:openssh-client:openssh-clients"
+ "ss:iproute2:iproute"
)
SSH_PORT_MIN=22000
@@ -285,23 +287,23 @@ validate_bpm_oci()
print_dependency_install_command()
{
- printf ' sudo apt-get install -y --no-install-recommends'
- printf ' %q' "$@"
- printf '\n'
+ printf ' %s\n' "$(test_vm_install_cmd "$@")"
}
check_host_dependencies()
{
local command_name
+ local deb_package
local package
local requirement
+ local rpm_package
local -a missing_commands=()
local -a missing_packages=()
local -A package_seen=()
for requirement in "${HOST_DEPENDENCIES[@]}"; do
- command_name="${requirement%%:*}"
- package="${requirement#*:}"
+ IFS=: read -r command_name deb_package rpm_package <<<"$requirement"
+ package="$(test_vm_pkg "$deb_package" "$rpm_package")"
if ! command -v "$command_name" >/dev/null 2>&1; then
missing_commands+=("$command_name")
if [[ -z "${package_seen[$package]+present}" ]]; then
@@ -1170,7 +1172,7 @@ validate_package_cert
validate_bpm_tree_config
validate_bpm_oci
if [[ "$VM_INITRD" == 1 ]]; then
- HOST_DEPENDENCIES+=("dracut:dracut-core" "lsinitrd:dracut-core" "file:file")
+ HOST_DEPENDENCIES+=("dracut:dracut-core:dracut" "lsinitrd:dracut-core:dracut" "file:file:file")
[[ "$EUID" == 0 ]] || die "TEST_VM_INITRD=1 builds the initrd with dracut, which needs root"
fi
check_host_dependencies
diff --git a/testing/Makefile b/testing/Makefile
index 2ce5dafc..8c2529be 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -25,7 +25,7 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \
KERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)
override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)
-PACKAGE_FORMAT ?= deb
+PACKAGE_FORMAT ?= $(call test-vm-arch,TEST_VM_HOST_PKG_FORMAT)
TEST_VM_WORK_DIR ?= build/test-vm
override TEST_VM_WORK_DIR := $(call root-path,$(TEST_VM_WORK_DIR))
diff --git a/testing/t0015-test-vm-cli.sh b/testing/t0015-test-vm-cli.sh
index 08f903ac..5888cf5a 100755
--- a/testing/t0015-test-vm-cli.sh
+++ b/testing/t0015-test-vm-cli.sh
@@ -44,7 +44,7 @@ test_expect_success 'test-vm prints an install command for missing dependencies'
ln -s /bin/true "$WORK/fake-bin/$command_name" || return 1
done &&
printf kernel >"$WORK/bzImage" &&
- ! PATH="$WORK/fake-bin" \
+ ! PATH="$WORK/fake-bin" TEST_VM_ARCH=x86_64 TEST_VM_HOST_PKG=apt \
TEST_VM_WORK_DIR="$WORK/missing-dependency" \
TEST_VM_KERNEL="$WORK/bzImage" "$RUNNER" \
>"$WORK/missing-dependency.out" 2>&1 &&
@@ -64,7 +64,7 @@ test_expect_success 'test-vm requires the QEMU emulator of the host architecture
ln -s /bin/true "$WORK/arm-bin/$command_name" || return 1
done &&
printf kernel >"$WORK/Image" &&
- ! PATH="$WORK/arm-bin" TEST_VM_ARCH=aarch64 \
+ ! PATH="$WORK/arm-bin" TEST_VM_ARCH=aarch64 TEST_VM_HOST_PKG=apt \
TEST_VM_WORK_DIR="$WORK/missing-arm-qemu" \
TEST_VM_KERNEL="$WORK/Image" "$RUNNER" \
>"$WORK/missing-arm-qemu.out" 2>&1 &&
@@ -73,6 +73,98 @@ test_expect_success 'test-vm requires the QEMU emulator of the host architecture
grep -q "qemu-system-arm" "$WORK/missing-arm-qemu.out"
'
+test_expect_success 'test-vm prints dnf package names on a Fedora or RHEL host' '
+ ! PATH="$WORK/fake-bin" TEST_VM_ARCH=x86_64 TEST_VM_HOST_PKG=dnf \
+ TEST_VM_WORK_DIR="$WORK/missing-dependency-dnf" \
+ TEST_VM_KERNEL="$WORK/bzImage" "$RUNNER" \
+ >"$WORK/missing-dependency-dnf.out" 2>&1 &&
+ grep -q "sudo dnf install -y cloud-utils" \
+ "$WORK/missing-dependency-dnf.out" &&
+ grep -q "openssh-clients" "$WORK/missing-dependency-dnf.out" &&
+ ! grep -q "apt-get" "$WORK/missing-dependency-dnf.out" &&
+ ! PATH="$WORK/arm-bin" TEST_VM_ARCH=aarch64 TEST_VM_HOST_PKG=dnf \
+ TEST_VM_WORK_DIR="$WORK/missing-arm-qemu-dnf" \
+ TEST_VM_KERNEL="$WORK/Image" "$RUNNER" \
+ >"$WORK/missing-arm-qemu-dnf.out" 2>&1 &&
+ grep -q "qemu-system-aarch64-core" "$WORK/missing-arm-qemu-dnf.out"
+'
+
+test_expect_success 'TEST_VM_QEMU names another emulator' '
+ mkdir "$WORK/kvm-bin" &&
+ ln -s /bin/bash "$WORK/kvm-bin/bash" &&
+ ln -s /usr/bin/dirname "$WORK/kvm-bin/dirname" &&
+ for command_name in curl sha256sum awk qemu-kvm qemu-img swtpm \
+ cloud-localds timeout tee flock ssh-keygen ss
+ do
+ ln -s /bin/true "$WORK/kvm-bin/$command_name" || return 1
+ done &&
+ ! PATH="$WORK/kvm-bin" TEST_VM_ARCH=x86_64 \
+ TEST_VM_WORK_DIR="$WORK/no-qemu" \
+ TEST_VM_KERNEL="$WORK/bzImage" "$RUNNER" \
+ >"$WORK/no-qemu.out" 2>&1 &&
+ grep -q "missing host commands: qemu-system-x86_64" "$WORK/no-qemu.out" &&
+ ! PATH="$WORK/kvm-bin" TEST_VM_ARCH=x86_64 TEST_VM_QEMU=qemu-kvm \
+ TEST_VM_WORK_DIR="$WORK/qemu-kvm" \
+ TEST_VM_KERNEL="$WORK/bzImage" "$RUNNER" \
+ >"$WORK/qemu-kvm.out" 2>&1 &&
+ ! grep -q "missing host commands" "$WORK/qemu-kvm.out" &&
+ grep -q "host VM bundle is missing" "$WORK/qemu-kvm.out"
+'
+
+test_expect_success 'the host package manager is detected from os-release' '
+ sed "s|/etc/os-release|$WORK/os-release|g" ../contrib/test-vm-arch.sh \
+ >"$WORK/arch-os.sh" &&
+ host_pkg() {
+ printf "%s\n" "$@" >"$WORK/os-release" &&
+ (unset TEST_VM_HOST_PKG; . "$WORK/arch-os.sh"; echo "$TEST_VM_HOST_PKG")
+ } &&
+ test "$(host_pkg ID=fedora)" = dnf &&
+ test "$(host_pkg ID=centos "ID_LIKE=\"rhel fedora\"")" = dnf &&
+ test "$(host_pkg ID=rocky "ID_LIKE=\"rhel centos fedora\"")" = dnf &&
+ test "$(host_pkg ID=ubuntu ID_LIKE=debian)" = apt &&
+ test "$(host_pkg ID=debian)" = apt &&
+ (
+ TEST_VM_HOST_PKG=dnf &&
+ . ../contrib/test-vm-arch.sh &&
+ test "$TEST_VM_HOST_PKG_FORMAT" = rpm &&
+ test "$(test_vm_install_cmd a b)" = "sudo dnf install -y a b"
+ )
+'
+
+test_expect_success 'the bundle and runtime scripts print hints for the host package manager' '
+ mkdir "$WORK/bundle-bin" &&
+ ln -s /usr/bin/dirname "$WORK/bundle-bin/dirname" &&
+ ln -s /usr/bin/uname "$WORK/bundle-bin/uname" &&
+ for command_name in flock curl sha256sum awk qemu-img
+ do
+ ln -s /bin/true "$WORK/bundle-bin/$command_name" || return 1
+ done &&
+ ! PATH="$WORK/bundle-bin" TEST_VM_HOST_PKG=dnf \
+ TEST_VM_WORK_DIR="$WORK/bundle-dnf" /bin/bash \
+ ../contrib/build-test-vm-bundle.sh >"$WORK/bundle-dnf.out" 2>&1 &&
+ grep -q "virt-customize (install with: sudo dnf install -y guestfs-tools)" \
+ "$WORK/bundle-dnf.out" &&
+ printf rootfs >"$WORK/hint-rootfs" &&
+ ! PATH="$WORK/bundle-bin" TEST_VM_HOST_PKG=dnf /bin/bash \
+ ../contrib/prepare-test-vm-runtime.sh --rootfs "$WORK/hint-rootfs" \
+ --cache-dir "$WORK/hint-cache" \
+ --package-file ../contrib/test-vm-runtime-packages \
+ --runtime-key hint --key-output "$WORK/hint-key" \
+ >"$WORK/runtime-dnf.out" 2>&1 &&
+ grep -q "virt-customize is required; install it with: sudo dnf install -y guestfs-tools" \
+ "$WORK/runtime-dnf.out"
+'
+
+test_expect_success 'the kernel package format follows the host package manager' '
+ printf "print:\n\t@echo \$(PACKAGE_FORMAT)\n" >"$WORK/print.mk" &&
+ format() {
+ make -s -C .. -f testing/Makefile -f "$WORK/print.mk" print "$@"
+ } &&
+ test "$(TEST_VM_HOST_PKG=dnf format)" = rpm &&
+ test "$(TEST_VM_HOST_PKG=apt format)" = deb &&
+ test "$(TEST_VM_HOST_PKG=dnf format PACKAGE_FORMAT=deb)" = deb
+'
+
test_expect_success 'test-vm boots arm64 on the virt machine with PCI disks' '
grep -q "virt,gic-version=host" "$RUNNER" &&
grep -q "virtio-blk-pci,drive=rootdisk" "$RUNNER" &&