]> git.proxmox.com Git - mirror_zfs.git/commitdiff
tests: vdev_zaps: cleanup library
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Wed, 9 Mar 2022 22:54:26 +0000 (23:54 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sat, 2 Apr 2022 00:57:35 +0000 (17:57 -0700)
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

tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh
tests/zfs-tests/tests/functional/vdev_zaps/vdev_zaps.kshlib

index f786f05e8af5e2b9ce76c6053f6e2ada1961d22c..8009299624e0f7a6937e79c60c0d55d86bdbd3a9 100644 (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
index e4664d03b43cc67badb95173d53da5ba6c821945..b370118a7f76d309bfb749280264b5215bf68548 100755 (executable)
@@ -97,9 +97,9 @@ while (( i < ${#dataset_pos[*]} )); do
 done
 
 i=0
-while (( i < ${#dataset_pos[*]} )) ; do
+while (( i < ${#dataset_pos[*]} )); do
        dataset=${dataset_pos[i]}
-       if  ismounted $dataset; then
+       if ismounted $dataset; then
                log_must cd ${old_mnt[i]}
                set_n_check_prop "noauto" "canmount" "$dataset"
                log_must mounted $dataset
index d16ef217a444ad9902f6ed6b01c203abfced2687..88fde66adf04fcb10275785c0800631cbd96abf5 100755 (executable)
@@ -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
 
index aae2ab40ce58d98e0b57e6142038243924ec7545..ad5bd9e7f81bbe9c0be916acb20292800571ce3d 100644 (file)
 
 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