diff --git a/test/test-functions b/test/test-functions index 79a7f5a71c..00a808bf28 100644 --- a/test/test-functions +++ b/test/test-functions @@ -951,13 +951,20 @@ install_multipath() { install_lvm() { image_install lvm image_install "${ROOTLIBDIR:?}"/system/lvm2-lvmpolld.{service,socket} - image_install "${ROOTLIBDIR:?}"/system/{blk-availability,lvm2-monitor,lvm2-pvscan@}.service + image_install "${ROOTLIBDIR:?}"/system/{blk-availability,lvm2-monitor}.service image_install "${ROOTLIBDIR:?}"/system-generators/lvm2-activation-generator image_install -o "/lib/tmpfiles.d/lvm2.conf" if get_bool "$LOOKS_LIKE_DEBIAN"; then inst_rules 56-lvm.rules 69-lvm-metad.rules else - inst_rules 11-dm-lvm.rules 69-dm-lvm-metad.rules + # Support the new udev autoactivation introduced in lvm 2.03.14 + # https://sourceware.org/git/?p=lvm2.git;a=commit;h=67722b312390cdab29c076c912e14bd739c5c0f6 + if [[ -f /lib/udev/rules.d/69-dm-lvm.rules ]]; then + inst_rules 11-dm-lvm.rules 69-dm-lvm.rules + else + image_install "${ROOTLIBDIR:?}"/system/lvm2-pvscan@.service + inst_rules 11-dm-lvm.rules 69-dm-lvm-metad.rules + fi fi mkdir -p "${initdir:?}/etc/lvm" } diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh index feb52e6ad1..b3c05a2b68 100755 --- a/test/units/testsuite-64.sh +++ b/test/units/testsuite-64.sh @@ -58,6 +58,43 @@ helper_wait_for_dev() { return 1 } +# Wrapper around `helper_wait_for_lvm_activate()` and `helper_wait_for_pvscan()` +# functions to cover differences between pre and post lvm 2.03.14, which introduced +# a new way of vgroup autoactivation +# See: https://sourceware.org/git/?p=lvm2.git;a=commit;h=67722b312390cdab29c076c912e14bd739c5c0f6 +# Arguments: +# $1 - device path (for helper_wait_for_pvscan()) +# $2 - volume group name (for helper_wait_for_lvm_activate()) +# $3 - number of retries (default: 10) +helper_wait_for_vgroup() { + local dev="${1:?}" + local vgroup="${2:?}" + local ntries="${3:-10}" + + if ! systemctl -q list-unit-files lvm2-pvscan@.service >/dev/null; then + helper_wait_for_lvm_activate "$vgroup" "$ntries" + else + helper_wait_for_pvscan "$dev" "$ntries" + fi +} + +# Wait for the lvm-activate-$vgroup.service of a specific $vgroup to finish +# Arguments: +# $1 - volume group name +# $2 - number of retries (default: 10) +helper_wait_for_lvm_activate() { + local vgroup="${1:?}" + local ntries="${2:-10}" + local i + + for ((i = 0; i < ntries; i++)); do + ! systemctl -q is-active "lvm-activate-$vgroup.service" || return 0 + sleep .5 + done + + return 1 +} + # Wait for the lvm2-pvscan@.service of a specific device to finish # Arguments: # $1 - device path @@ -65,7 +102,7 @@ helper_wait_for_dev() { helper_wait_for_pvscan() { local dev="${1:?}" local ntries="${2:-10}" - local MAJOR MINOR pvscan_svc real_dev + local MAJOR MINOR i pvscan_svc real_dev # Sanity check we got a valid block device (or a symlink to it) real_dev="$(readlink -f "$dev")" @@ -576,7 +613,7 @@ testcase_iscsi_lvm() { udevadm settle for link in "${expected_symlinks[@]}"; do helper_wait_for_dev "$link" - helper_wait_for_pvscan "$link" + helper_wait_for_vgroup "$link" "$vgroup" test -e "$link" done udevadm settle