Skip to content

Commit

Permalink
tests/kola: refactor kernel-replace to build containers first
Browse files Browse the repository at this point in the history
Factor out the container building into their own functions and
create both container images on the first boot so we know earlier
if the `podman build` with the kernel replace fails.
  • Loading branch information
dustymabe committed Jan 28, 2025
1 parent 55bf5fd commit 6f86533
Showing 1 changed file with 62 additions and 44 deletions.
106 changes: 62 additions & 44 deletions tests/kola/rpm-ostree/kernel-replace
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,13 @@ cd $(mktemp -d)
OS_ID=$(. /etc/os-release; echo $ID)
imagepath=/var/tmp/coreos.ociarchive
imagespec="oci-archive:${imagepath}"
derived_imagepath=/var/tmp/coreos-derived.ociarchive
derived_imagespec="oci-archive:${derived_imagepath}"
arch=$(arch)

# we only want to query repos once but need the info on multiple boots, so write out state to /var
if [ ! -f /var/kola-kernel.evr ]; then
case "$OS_ID" in
rhcos|scos|rhel|centos)
c9s_mirror="https://mirror.stream.centos.org/9-stream/BaseOS/${arch}/os"
# we're probably already on CentOS and running the latest kernel. so
# here we need to instead pick whatever the latest that's *not* the same
kver=$(dnf repoquery kernel --qf '%{EVR}' --repofrompath=tmp,"${c9s_mirror}" --disablerepo '*' --enablerepo tmp | \
grep -v "$(rpm -q kernel --qf '%{EVR}')" | tail -n1)
kver="${kver}.${arch}"
url="${c9s_mirror}/Packages/kernel"
;;
fedora)
# to get the version to use: koji latest-pkg f40 kernel
# XXX: once we can rely on dnf in FCOS, use repoquery also here
kver="6.8.5-301.fc40.${arch}"
url="https://kojipkgs.fedoraproject.org//packages/kernel/6.8.5/301.fc40/${arch}/kernel"
;;
*)
echo "Unknown OS_ID: ${OS_ID}"
exit 1
;;
esac
echo "$kver" > /var/kola-kernel.evr
echo "$url" > /var/kola-kernel.url
else
kver=$(cat /var/kola-kernel.evr)
url=$(cat /var/kola-kernel.url)
fi

case "${AUTOPKGTEST_REBOOT_MARK:-}" in
"")
# Take the existing ostree commit, and export it to a container image, then rebase to it.
build_base_ociarchive() {
# Take the existing ostree commit, and export it to a container image/ociarchive
rpm-ostree status --json > status.json
checksum=$(jq -r '.deployments[0].checksum' < status.json)
v0=$(jq -r '.deployments[0].version' < status.json)
Expand All @@ -96,27 +68,73 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
# Since we're switching OS update stream, turn off zincati
systemctl mask --now zincati
ostree container encapsulate "${encapsulate_args[@]}" --repo=/ostree/repo ${checksum} "${imagespec}"
# This one keeps --experimental, but we also test without it below
rpm-ostree rebase --experimental "ostree-unverified-image:${imagespec}"
ostree container image list --repo=/ostree/repo | tee imglist.txt
# Test rebasing back to ostree https://github.com/coreos/rpm-ostree/issues/3677
rpm-ostree rebase "$checksum"
rpm-ostree rebase "ostree-unverified-image:${imagespec}"
/tmp/autopkgtest-reboot 1
;;
1)
}

build_derived_ociarchive() {
# we only want to query repos once but need the info on multiple boots, so write out state to /var
if [ ! -f /var/kola-kernel.evr ]; then
case "$OS_ID" in
rhcos|scos|rhel|centos)
c9s_mirror="https://mirror.stream.centos.org/9-stream/BaseOS/${arch}/os"
# we're probably already on CentOS and running the latest kernel. so
# here we need to instead pick whatever the latest that's *not* the same
kver=$(dnf repoquery kernel --qf '%{EVR}' --repofrompath=tmp,"${c9s_mirror}" --disablerepo '*' --enablerepo tmp | \
grep -v "$(rpm -q kernel --qf '%{EVR}')" | tail -n1)
kver="${kver}.${arch}"
url="${c9s_mirror}/Packages/kernel"
;;
fedora)
# to get the version to use: koji latest-pkg f40 kernel
# XXX: once we can rely on dnf in FCOS, use repoquery also here
kver="6.8.5-301.fc40.${arch}"
url="https://kojipkgs.fedoraproject.org//packages/kernel/6.8.5/301.fc40/${arch}/kernel"
;;
*)
echo "Unknown OS_ID: ${OS_ID}"
exit 1
;;
esac
echo "$kver" > /var/kola-kernel.evr
echo "$url" > /var/kola-kernel.url
else
kver=$(cat /var/kola-kernel.evr)
url=$(cat /var/kola-kernel.url)
fi

td=$(mktemp -d)
cd ${td}
pushd ${td}
cat > Containerfile << EOF
FROM $imagespec
RUN rpm-ostree override replace \
$url-{,core-,modules-,modules-core-,modules-extra-}$kver.rpm && \
rpm-ostree cleanup -m && \
ostree container commit
EOF
derived_imagepath=/var/tmp/coreos-derived.ociarchive
derived_imagespec="oci-archive:${derived_imagepath}"
podman build --net=host -t "${derived_imagespec}" --squash .
popd
}

case "${AUTOPKGTEST_REBOOT_MARK:-}" in
"")
# First thing, let's create the base and derived OCI archive image files
build_base_ociarchive
build_derived_ociarchive

# Since we're switching OS update streams, turn off zincati
systemctl mask --now zincati

# Rebase a few times to test the mechanisms
#
# This one keeps --experimental, but we also test without it below
rpm-ostree rebase --experimental "ostree-unverified-image:${imagespec}"
ostree container image list --repo=/ostree/repo | tee imglist.txt
# Test rebasing back to ostree https://github.com/coreos/rpm-ostree/issues/3677
rpm-ostree rebase "$checksum"
rpm-ostree rebase "ostree-unverified-image:${imagespec}"
/tmp/autopkgtest-reboot 1
;;
1)
# Now test rebasing to the derived kernel-replaced image
rpm-ostree --version
rpm-ostree rebase "ostree-unverified-image:$derived_imagespec"
ostree container image list --repo=/ostree/repo
Expand Down

0 comments on commit 6f86533

Please sign in to comment.