From 2248f8b30d379954b040c9a99b8468a89f45d5c2 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 22 Mar 2023 16:37:46 -0400 Subject: [PATCH] tests/kola: move LUKS checks to shared file Prep for adding another LUKS where we want the same checks. --- .../root-reprovision/luks/data/luks-test.sh | 59 +++++++++++++++++++ tests/kola/root-reprovision/luks/test.sh | 56 +----------------- 2 files changed, 61 insertions(+), 54 deletions(-) create mode 100755 tests/kola/root-reprovision/luks/data/luks-test.sh diff --git a/tests/kola/root-reprovision/luks/data/luks-test.sh b/tests/kola/root-reprovision/luks/data/luks-test.sh new file mode 100755 index 0000000000..fe4b0dc3fe --- /dev/null +++ b/tests/kola/root-reprovision/luks/data/luks-test.sh @@ -0,0 +1,59 @@ +# This file is sourced by both `ext.config.root-reprovision.luks` +# and `ext.config.root-reprovision.luks.autosave-xfs`. + +. $KOLA_EXT_DATA/commonlib.sh + +srcdev=$(findmnt -nvr / -o SOURCE) +[[ ${srcdev} == /dev/mapper/myluksdev ]] + +blktype=$(lsblk -o TYPE "${srcdev}" --noheadings) +[[ ${blktype} == crypt ]] + +fstype=$(findmnt -nvr / -o FSTYPE) +[[ ${fstype} == xfs ]] +ok "source is XFS on LUKS device" + +rootflags=$(findmnt /sysroot -no OPTIONS) +if ! grep prjquota <<< "${rootflags}"; then + fatal "missing prjquota in root mount flags: ${rootflags}" +fi +ok "root mounted with prjquota" + +table=$(dmsetup table myluksdev) +if ! grep -q allow_discards <<< "${table}"; then + fatal "missing allow_discards in root DM table: ${table}" +fi +if ! grep -q no_read_workqueue <<< "${table}"; then + fatal "missing no_read_workqueue in root DM table: ${table}" +fi +ok "discard and custom option enabled for root LUKS" + +# while we're here, sanity-check that boot is mounted by UUID +if ! systemctl cat boot.mount | grep -q What=/dev/disk/by-uuid; then + systemctl cat boot.mount + fatal "boot mounted not by UUID" +fi +ok "boot mounted by UUID" + +case "${AUTOPKGTEST_REBOOT_MARK:-}" in + "") + # check that ignition-ostree-growfs ran + if [ ! -e /run/ignition-ostree-growfs.stamp ]; then + fatal "ignition-ostree-growfs did not run" + fi + + # reboot once to sanity-check we can find root on second boot + /tmp/autopkgtest-reboot rebooted + ;; + + rebooted) + grep root=UUID= /proc/cmdline + grep rd.luks.name= /proc/cmdline + ok "found root kargs" + + # while we're here, sanity-check that we have a boot=UUID karg too + grep boot=UUID= /proc/cmdline + ok "found boot karg" + ;; + *) fatal "unexpected mark: ${AUTOPKGTEST_REBOOT_MARK}";; +esac diff --git a/tests/kola/root-reprovision/luks/test.sh b/tests/kola/root-reprovision/luks/test.sh index 8ec72f6bb8..ff3d283fa1 100755 --- a/tests/kola/root-reprovision/luks/test.sh +++ b/tests/kola/root-reprovision/luks/test.sh @@ -14,57 +14,5 @@ set -xeuo pipefail . $KOLA_EXT_DATA/commonlib.sh -srcdev=$(findmnt -nvr / -o SOURCE) -[[ ${srcdev} == /dev/mapper/myluksdev ]] - -blktype=$(lsblk -o TYPE "${srcdev}" --noheadings) -[[ ${blktype} == crypt ]] - -fstype=$(findmnt -nvr / -o FSTYPE) -[[ ${fstype} == xfs ]] -ok "source is XFS on LUKS device" - -rootflags=$(findmnt /sysroot -no OPTIONS) -if ! grep prjquota <<< "${rootflags}"; then - fatal "missing prjquota in root mount flags: ${rootflags}" -fi -ok "root mounted with prjquota" - -table=$(dmsetup table myluksdev) -if ! grep -q allow_discards <<< "${table}"; then - fatal "missing allow_discards in root DM table: ${table}" -fi -if ! grep -q no_read_workqueue <<< "${table}"; then - fatal "missing no_read_workqueue in root DM table: ${table}" -fi -ok "discard and custom option enabled for root LUKS" - -# while we're here, sanity-check that boot is mounted by UUID -if ! systemctl cat boot.mount | grep -q What=/dev/disk/by-uuid; then - systemctl cat boot.mount - fatal "boot mounted not by UUID" -fi -ok "boot mounted by UUID" - -case "${AUTOPKGTEST_REBOOT_MARK:-}" in - "") - # check that ignition-ostree-growfs ran - if [ ! -e /run/ignition-ostree-growfs.stamp ]; then - fatal "ignition-ostree-growfs did not run" - fi - - # reboot once to sanity-check we can find root on second boot - /tmp/autopkgtest-reboot rebooted - ;; - - rebooted) - grep root=UUID= /proc/cmdline - grep rd.luks.name= /proc/cmdline - ok "found root kargs" - - # while we're here, sanity-check that we have a boot=UUID karg too - grep boot=UUID= /proc/cmdline - ok "found boot karg" - ;; - *) fatal "unexpected mark: ${AUTOPKGTEST_REBOOT_MARK}";; -esac +# run the tests +. $KOLA_EXT_DATA/luks-test.sh