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:
parent
25aeffadb2
commit
41ebf40375
|
@ -1229,7 +1229,6 @@ function poolexists
|
||||||
fi
|
fi
|
||||||
|
|
||||||
zpool get name "$pool" > /dev/null 2>&1
|
zpool get name "$pool" > /dev/null 2>&1
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return 0 if all the specified datasets exist; $? otherwise
|
# Return 0 if all the specified datasets exist; $? otherwise
|
||||||
|
@ -1242,13 +1241,7 @@ function datasetexists
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while (($# > 0)); do
|
zfs get name "$@" > /dev/null 2>&1
|
||||||
zfs get name $1 > /dev/null 2>&1 || \
|
|
||||||
return $?
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# return 0 if none of the specified datasets exists, otherwise return 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
|
# $2 - custom arguments for zfs destroy
|
||||||
# Destroy dataset with the given parameters.
|
# Destroy dataset with the given parameters.
|
||||||
|
|
||||||
function destroy_dataset #dataset #args
|
function destroy_dataset # dataset [args]
|
||||||
{
|
{
|
||||||
typeset dataset=$1
|
typeset dataset=$1
|
||||||
typeset mtpt
|
typeset mtpt
|
||||||
|
@ -1792,8 +1785,7 @@ function destroy_dataset #dataset #args
|
||||||
mtpt=$(get_prop mountpoint "$dataset")
|
mtpt=$(get_prop mountpoint "$dataset")
|
||||||
log_must_busy zfs destroy $args $dataset
|
log_must_busy zfs destroy $args $dataset
|
||||||
|
|
||||||
[[ -d $mtpt ]] && \
|
[ -d $mtpt ] && log_must rm -rf $mtpt
|
||||||
log_must rm -rf $mtpt
|
|
||||||
else
|
else
|
||||||
log_note "Dataset does not exist. ($dataset)"
|
log_note "Dataset does not exist. ($dataset)"
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -97,9 +97,9 @@ while (( i < ${#dataset_pos[*]} )); do
|
||||||
done
|
done
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
while (( i < ${#dataset_pos[*]} )) ; do
|
while (( i < ${#dataset_pos[*]} )); do
|
||||||
dataset=${dataset_pos[i]}
|
dataset=${dataset_pos[i]}
|
||||||
if ismounted $dataset; then
|
if ismounted $dataset; then
|
||||||
log_must cd ${old_mnt[i]}
|
log_must cd ${old_mnt[i]}
|
||||||
set_n_check_prop "noauto" "canmount" "$dataset"
|
set_n_check_prop "noauto" "canmount" "$dataset"
|
||||||
log_must mounted $dataset
|
log_must mounted $dataset
|
||||||
|
|
|
@ -69,18 +69,18 @@ done
|
||||||
log_mustnot zpool import -d $DEVICE_DIR $TESTPOOL1
|
log_mustnot zpool import -d $DEVICE_DIR $TESTPOOL1
|
||||||
|
|
||||||
# error message should not mention "readonly"
|
# 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
|
log_mustnot poolexists $TESTPOOL1
|
||||||
|
|
||||||
for feature in $active_features; do
|
for feature in $active_features; do
|
||||||
log_must eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
|
log_must eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
|
||||||
| grep $feature"
|
| grep -q $feature"
|
||||||
log_mustnot poolexists $TESTPOOL1
|
log_mustnot poolexists $TESTPOOL1
|
||||||
done
|
done
|
||||||
|
|
||||||
for feature in $enabled_features; do
|
for feature in $enabled_features; do
|
||||||
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
|
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
|
||||||
| grep $feature"
|
| grep -q $feature"
|
||||||
log_mustnot poolexists $TESTPOOL1
|
log_mustnot poolexists $TESTPOOL1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -19,45 +19,25 @@
|
||||||
|
|
||||||
function get_conf_section # regex conf
|
function get_conf_section # regex conf
|
||||||
{
|
{
|
||||||
typeset dsk_line next_vd_line conf section
|
|
||||||
typeset regex="$1"
|
typeset regex="$1"
|
||||||
typeset conf="$2"
|
typeset conf="$2"
|
||||||
|
|
||||||
dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
|
awk -v r="$1" '$0 ~ r, 0 {if($0 ~ r) next; if(/children\[/) exit; print}' "$conf"
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_leaf_vd_zap # dsk conf
|
function get_leaf_vd_zap # dsk conf
|
||||||
{
|
{
|
||||||
typeset section=$(get_conf_section "$1" "$2")
|
get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_leaf: [0-9]+/ {print $2}'
|
||||||
echo "$section" | egrep \
|
|
||||||
"com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_top_vd_zap # dsk conf
|
function get_top_vd_zap # dsk conf
|
||||||
{
|
{
|
||||||
typeset section=$(get_conf_section "$1" "$2")
|
get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_top: [0-9]+/ {print $2}'
|
||||||
echo "$section" | egrep \
|
|
||||||
"com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_has_sentinel # conf
|
function assert_has_sentinel # conf
|
||||||
{
|
{
|
||||||
res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
|
log_must grep -q "com.delphix:has_per_vdev_zaps" "$1"
|
||||||
[[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_zap_common # pool vd lvl zapobj
|
function assert_zap_common # pool vd lvl zapobj
|
||||||
|
@ -67,9 +47,9 @@ function assert_zap_common # pool vd lvl zapobj
|
||||||
typeset lvl=$3
|
typeset lvl=$3
|
||||||
typeset zapobj=$4
|
typeset zapobj=$4
|
||||||
|
|
||||||
if [[ -z "$zapobj" ]]; then
|
if [ -z "$zapobj" ]; then
|
||||||
log_fail "$vd on $pool has no $lvl ZAP in config"
|
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"
|
log_fail "$vd on $pool has no $lvl ZAP in MOS"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -100,15 +80,9 @@ function assert_leaf_zap # pool vd conf
|
||||||
|
|
||||||
function cleanup
|
function cleanup
|
||||||
{
|
{
|
||||||
if datasetexists $TESTPOOL ; then
|
datasetexists $TESTPOOL && log_must zpool destroy -f $TESTPOOL
|
||||||
log_must zpool destroy -f $TESTPOOL
|
[ -e $conf ] && log_must rm -f "$conf"
|
||||||
fi
|
poolexists $POOL2 && log_must zpool destroy -f $POOL2
|
||||||
if [[ -e $conf ]]; then
|
|
||||||
log_must rm -f "$conf"
|
|
||||||
fi
|
|
||||||
if [[ -e $POOL2 ]]; then
|
|
||||||
log_must zpool destroy -f $POOL2
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_onexit cleanup
|
log_onexit cleanup
|
||||||
|
|
Loading…
Reference in New Issue