From 5ceccda5cb78a4786e088368aa0fafb0ae281715 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Thu, 13 Feb 2020 15:05:32 -0500 Subject: [PATCH] ZTS: Cleanup some cleanup functions Cleanup functions should make a best effort to clean up as much as possible. Do a consistency pass in a bunch of tests to make the cleanup functions less prone to failure and fix a few typos here and there. Reviewed-by: John Kennedy Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #9993 --- .../cli_root/zpool_add/add-o_ashift.ksh | 2 +- .../cli_root/zpool_attach/attach-o_ashift.ksh | 3 +-- .../cli_root/zpool_create/create-o_ashift.ksh | 4 ++-- .../zpool_create/zpool_create_003_pos.ksh | 3 ++- .../zpool_create/zpool_create_004_pos.ksh | 4 +--- .../zpool_create/zpool_create_005_pos.ksh | 16 +++++----------- .../zpool_create/zpool_create_006_pos.ksh | 4 ++-- .../zpool_create/zpool_create_010_neg.ksh | 9 +++++---- .../zpool_create/zpool_create_012_neg.ksh | 4 +--- .../zpool_create/zpool_create_014_neg.ksh | 4 +--- .../zpool_create/zpool_create_015_neg.ksh | 4 +--- .../zpool_create/zpool_create_016_pos.ksh | 4 +--- .../zpool_create/zpool_create_017_neg.ksh | 9 ++------- .../zpool_create/zpool_create_018_pos.ksh | 2 +- .../zpool_create/zpool_create_019_pos.ksh | 4 +--- .../zpool_create/zpool_create_020_pos.ksh | 15 +++++---------- .../zpool_create/zpool_create_022_pos.ksh | 2 +- .../zpool_create/zpool_create_023_neg.ksh | 2 +- .../zpool_create/zpool_create_tempname.ksh | 6 ++++-- .../cli_root/zpool_replace/replace-o_ashift.ksh | 3 +-- .../zpool_replace/replace_prop_ashift.ksh | 2 +- .../tests/functional/no_space/enospc_003_pos.ksh | 2 +- 22 files changed, 41 insertions(+), 67 deletions(-) diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh index 8556f298e7..da3d162273 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh @@ -43,7 +43,7 @@ verify_runnable "global" function cleanup { poolexists $TESTPOOL && destroy_pool $TESTPOOL - log_must rm -f $disk1 $disk2 + rm -f $disk1 $disk2 } log_assert "zpool add -o ashift=' works with different ashift values" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh index 3c3706ff39..43ae05d0a8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh @@ -42,8 +42,7 @@ verify_runnable "global" function cleanup { poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - log_must rm -f $disk1 - log_must rm -f $disk2 + rm -f $disk1 $disk2 } log_assert "zpool attach -o ashift=' works with different ashift values" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh index 6a9c3e28c3..09ae787637 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh @@ -44,8 +44,8 @@ verify_runnable "global" function cleanup { - destroy_pool $TESTPOOL - log_must rm -f $disk + poolexists $TESTPOOL && destroy_pool $TESTPOOL + rm -f $disk } # diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh index 100a24c500..09740617af 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh @@ -47,7 +47,8 @@ verify_runnable "global" function cleanup { - [[ -e $tmpfile ]] && log_must rm -f $tmpfile + poolexists $TESTPOOL && destroy_pool $TESTPOOL + rm -f $tmpfile } tmpfile="$TEST_BASE_DIR/zpool_create_003.tmp$$" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh index 2697562742..e9f0f83e17 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh @@ -45,12 +45,10 @@ verify_runnable "global" function cleanup { - typeset pool="" - poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 poolexists $TESTPOOL && destroy_pool $TESTPOOL - [[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR + rm -rf $TESTDIR partition_disk $SIZE $disk 6 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh index de5e9d8e79..165453e8bb 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh @@ -46,12 +46,8 @@ verify_runnable "global" function cleanup { - poolexists $TESTPOOL && \ - log_must zpool destroy -f $TESTPOOL - - for dir in $TESTDIR $TESTDIR1; do - [[ -d $dir ]] && rm -rf $dir - done + poolexists $TESTPOOL && destroy_pool $TESTPOOL + rm -rf $TESTDIR $TESTDIR1 } log_assert "'zpool create [-R root][-m mountpoint] ...' can create" \ @@ -64,13 +60,11 @@ set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2" # cleanup the pools created in previous case if zpool_create_004_pos timedout # for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do - if poolexists $pool; then - destroy_pool $pool - fi + poolexists $pool && destroy_pool $pool done #prepare raw file for file disk -[[ -d $TESTDIR ]] && rm -rf $TESTDIR +rm -rf $TESTDIR log_must mkdir -p $TESTDIR typeset -i i=1 while (( i < 4 )); do @@ -80,7 +74,7 @@ while (( i < 4 )); do done #Remove the directory with name as pool name if it exists -[[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL +rm -rf /$TESTPOOL file=$TESTDIR/file for opt in "-R $TESTDIR1" "-m $TESTDIR1" \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh index 79a0060c9b..15cd23e445 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh @@ -46,8 +46,8 @@ verify_runnable "global" function cleanup { - datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - datasetexists $TESTPOOL && destroy_pool $TESTPOOL + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + poolexists $TESTPOOL && destroy_pool $TESTPOOL } diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh index 165939786d..ee1b2c9787 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh @@ -48,12 +48,13 @@ verify_runnable "global" function cleanup { - poolexists $TOOSMALL && destroy_pool $TOOSMALL - poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + typeset pool - poolexists $TESTPOOL && destroy_pool $TESTPOOL + for pool in $TOOSMALL $TESTPOOL1 $TESTPOOL; do + poolexists $pool && destroy_pool $pool + done - [[ -d $TESTDIR ]] && rm -rf $TESTDIR + rm -rf $TESTDIR partition_disk $SIZE $disk 6 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh index 347fdfea49..f90186d94e 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh @@ -47,9 +47,7 @@ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + poolexists $TESTPOOL && destroy_pool $TESTPOOL } if is_linux; then diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh index 64ffed5ec5..5a28b0f891 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh @@ -54,9 +54,7 @@ function cleanup zfs destroy $vol_name fi - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + poolexists $TESTPOOL && destroy_pool $TESTPOOL } log_assert "'zpool create' should fail with regular file in swap." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh index 4f605d3ba8..34e85e092f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh @@ -56,9 +56,7 @@ function cleanup fi for pool in $TESTPOOL1 $TESTPOOL; do - if poolexists $pool; then - destroy_pool $pool - fi + poolexists $pool && destroy_pool $pool done } diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh index 1c0d3e2d48..e4577609d4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh @@ -48,9 +48,7 @@ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + poolexists $TESTPOOL && destroy_pool $TESTPOOL #recover swap devices FSTAB=$TEST_BASE_DIR/fstab_$$ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh index 7e75e74c29..0e7736da57 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh @@ -47,13 +47,8 @@ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi - - if [[ -d $TESTDIR ]]; then - log_must rm -rf $TESTDIR - fi + poolexists $TESTPOOL && destroy_pool $TESTPOOL + rm -rf $TESTDIR } if [[ -n $DISK ]]; then diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh index 1de51e0414..43bc88bf6f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh @@ -47,7 +47,7 @@ function cleanup { poolexists $TESTPOOL && destroy_pool $TESTPOOL - [[ -f $CPATH ]] && log_must rm $CPATH + rm -f $CPATH } log_onexit cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh index 9cf6081ff7..6de884d998 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh @@ -43,9 +43,7 @@ function cleanup { - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + poolexists $TESTPOOL && destroy_pool $TESTPOOL } log_onexit cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh index ae069606ea..0a53b1a70f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh @@ -46,14 +46,9 @@ function cleanup { - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi - if [ -d /${TESTPOOL}.root ] - then - log_must rmdir /${TESTPOOL}.root - fi - [[ -e $values ]] && log_must rm -f $values + poolexists $TESTPOOL && destroy_pool $TESTPOOL + rm -rf /${TESTPOOL}.root + rm -f $values } log_onexit cleanup @@ -69,11 +64,11 @@ else fi log_must rm -f /etc/zfs/zpool.cache -log_must mkdir /${TESTPOOL}.root +log_must rm -rf /${TESTPOOL}.root log_must zpool create -R /${TESTPOOL}.root $TESTPOOL $disk if [ ! -d /${TESTPOOL}.root ] then - log_fail "Mountpoint was not create when using zpool with -R flag!" + log_fail "Mountpoint was not created when using zpool with -R flag!" fi FS=$(zfs list $TESTPOOL) diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh index 4e6d255129..349f73fecc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh @@ -48,7 +48,7 @@ verify_runnable "global" function cleanup { - datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL + poolexists $TESTPOOL && destroy_pool $TESTPOOL } log_onexit cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh index 6bda38d46c..48117555af 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh @@ -45,7 +45,7 @@ verify_runnable "global" function cleanup { - datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL + poolexists $TESTPOOL && destroy_pool $TESTPOOL } log_onexit cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh index 1e6fcea03b..b864901871 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh @@ -30,9 +30,11 @@ verify_runnable "global" function cleanup { - destroy_pool $TESTPOOL - destroy_pool $TEMPPOOL + typeset pool + for pool in $TESTPOOL $TEMPPOOL; do + poolexists $pool && destroy_pool $pool + done } log_assert "'zpool create -t ' can create a pool with the specified" \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh index ae415487c7..e58b4cd86b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh @@ -42,8 +42,7 @@ verify_runnable "global" function cleanup { poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - log_must rm -f $disk1 - log_must rm -f $disk2 + rm -f $disk1 $disk2 } log_assert "zpool replace -o ashift=' works with different ashift values" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh index e740de133a..6acf25528c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh @@ -44,7 +44,7 @@ verify_runnable "global" function cleanup { poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - log_must rm -f $disk1 $disk2 + rm -f $disk1 $disk2 } log_assert "'zpool replace' uses the ashift pool property value as default." diff --git a/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh b/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh index a5643a0cb7..b19df80e03 100755 --- a/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh @@ -44,7 +44,7 @@ verify_runnable "both" function cleanup { - log_must zpool destroy $TESTPOOL1 + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 } log_onexit cleanup