tests: vdev_zaps: cleanup library

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13259
This commit is contained in:
наб 2022-03-09 23:54:26 +01:00 committed by Brian Behlendorf
parent 25aeffadb2
commit 41ebf40375
4 changed files with 17 additions and 51 deletions

View File

@ -1229,7 +1229,6 @@ function poolexists
fi
zpool get name "$pool" > /dev/null 2>&1
return $?
}
# Return 0 if all the specified datasets exist; $? otherwise
@ -1242,13 +1241,7 @@ function datasetexists
return 1
fi
while (($# > 0)); do
zfs get name $1 > /dev/null 2>&1 || \
return $?
shift
done
return 0
zfs get name "$@" > /dev/null 2>&1
}
# return 0 if none of the specified datasets exists, otherwise return 1.
@ -1776,7 +1769,7 @@ function create_dataset #dataset dataset_options
# $2 - custom arguments for zfs destroy
# Destroy dataset with the given parameters.
function destroy_dataset #dataset #args
function destroy_dataset # dataset [args]
{
typeset dataset=$1
typeset mtpt
@ -1792,8 +1785,7 @@ function destroy_dataset #dataset #args
mtpt=$(get_prop mountpoint "$dataset")
log_must_busy zfs destroy $args $dataset
[[ -d $mtpt ]] && \
log_must rm -rf $mtpt
[ -d $mtpt ] && log_must rm -rf $mtpt
else
log_note "Dataset does not exist. ($dataset)"
return 1

View File

@ -69,18 +69,18 @@ done
log_mustnot zpool import -d $DEVICE_DIR $TESTPOOL1
# error message should not mention "readonly"
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 | grep readonly"
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 | grep -q readonly"
log_mustnot poolexists $TESTPOOL1
for feature in $active_features; do
log_must eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
| grep $feature"
| grep -q $feature"
log_mustnot poolexists $TESTPOOL1
done
for feature in $enabled_features; do
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
| grep $feature"
| grep -q $feature"
log_mustnot poolexists $TESTPOOL1
done

View File

@ -19,45 +19,25 @@
function get_conf_section # regex conf
{
typeset dsk_line next_vd_line conf section
typeset regex="$1"
typeset conf="$2"
dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
if [[ -z "$dsk_line" ]]; then
return
fi
next_vd_line=$(tail -n +$dsk_line "$conf" | \
grep -n "children\[" | awk -F: '{print $1}' | head -n 1)
if [[ -n "$next_vd_line" ]]; then
section=$(cat "$conf" | sed "1,${dsk_line}d" | head -n \
$(($next_vd_line - 2)))
else
section=$(tail -n +$dsk_line "$conf")
fi
echo "$section"
awk -v r="$1" '$0 ~ r, 0 {if($0 ~ r) next; if(/children\[/) exit; print}' "$conf"
}
function get_leaf_vd_zap # dsk conf
{
typeset section=$(get_conf_section "$1" "$2")
echo "$section" | egrep \
"com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_leaf: [0-9]+/ {print $2}'
}
function get_top_vd_zap # dsk conf
{
typeset section=$(get_conf_section "$1" "$2")
echo "$section" | egrep \
"com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_top: [0-9]+/ {print $2}'
}
function assert_has_sentinel # conf
{
res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
[[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
log_must grep -q "com.delphix:has_per_vdev_zaps" "$1"
}
function assert_zap_common # pool vd lvl zapobj
@ -67,9 +47,9 @@ function assert_zap_common # pool vd lvl zapobj
typeset lvl=$3
typeset zapobj=$4
if [[ -z "$zapobj" ]]; then
if [ -z "$zapobj" ]; then
log_fail "$vd on $pool has no $lvl ZAP in config"
elif [[ -z "$(zdb -d $pool $zapobj | grep 'zap')" ]]; then
elif ! zdb -d $pool $zapobj | grep -q 'zap'; then
log_fail "$vd on $pool has no $lvl ZAP in MOS"
fi
}
@ -100,15 +80,9 @@ function assert_leaf_zap # pool vd conf
function cleanup
{
if datasetexists $TESTPOOL ; then
log_must zpool destroy -f $TESTPOOL
fi
if [[ -e $conf ]]; then
log_must rm -f "$conf"
fi
if [[ -e $POOL2 ]]; then
log_must zpool destroy -f $POOL2
fi
datasetexists $TESTPOOL && log_must zpool destroy -f $TESTPOOL
[ -e $conf ] && log_must rm -f "$conf"
poolexists $POOL2 && log_must zpool destroy -f $POOL2
}
log_onexit cleanup