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 <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #9993
This commit is contained in:
Ryan Moeller 2020-02-13 15:05:32 -05:00 committed by GitHub
parent 523bc0d548
commit 5ceccda5cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 41 additions and 67 deletions

View File

@ -43,7 +43,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TESTPOOL && destroy_pool $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
log_must rm -f $disk1 $disk2 rm -f $disk1 $disk2
} }
log_assert "zpool add -o ashift=<n>' works with different ashift values" log_assert "zpool add -o ashift=<n>' works with different ashift values"

View File

@ -42,8 +42,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
log_must rm -f $disk1 rm -f $disk1 $disk2
log_must rm -f $disk2
} }
log_assert "zpool attach -o ashift=<n>' works with different ashift values" log_assert "zpool attach -o ashift=<n>' works with different ashift values"

View File

@ -44,8 +44,8 @@ verify_runnable "global"
function cleanup function cleanup
{ {
destroy_pool $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
log_must rm -f $disk rm -f $disk
} }
# #

View File

@ -47,7 +47,8 @@ verify_runnable "global"
function cleanup 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$$" tmpfile="$TEST_BASE_DIR/zpool_create_003.tmp$$"

View File

@ -45,12 +45,10 @@ verify_runnable "global"
function cleanup function cleanup
{ {
typeset pool=""
poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
poolexists $TESTPOOL && destroy_pool $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
[[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR rm -rf $TESTDIR
partition_disk $SIZE $disk 6 partition_disk $SIZE $disk 6
} }

View File

@ -46,12 +46,8 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TESTPOOL && \ poolexists $TESTPOOL && destroy_pool $TESTPOOL
log_must zpool destroy -f $TESTPOOL rm -rf $TESTDIR $TESTDIR1
for dir in $TESTDIR $TESTDIR1; do
[[ -d $dir ]] && rm -rf $dir
done
} }
log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create" \ log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' 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 # cleanup the pools created in previous case if zpool_create_004_pos timedout
# #
for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do
if poolexists $pool; then poolexists $pool && destroy_pool $pool
destroy_pool $pool
fi
done done
#prepare raw file for file disk #prepare raw file for file disk
[[ -d $TESTDIR ]] && rm -rf $TESTDIR rm -rf $TESTDIR
log_must mkdir -p $TESTDIR log_must mkdir -p $TESTDIR
typeset -i i=1 typeset -i i=1
while (( i < 4 )); do while (( i < 4 )); do
@ -80,7 +74,7 @@ while (( i < 4 )); do
done done
#Remove the directory with name as pool name if it exists #Remove the directory with name as pool name if it exists
[[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL rm -rf /$TESTPOOL
file=$TESTDIR/file file=$TESTDIR/file
for opt in "-R $TESTDIR1" "-m $TESTDIR1" \ for opt in "-R $TESTDIR1" "-m $TESTDIR1" \

View File

@ -46,8 +46,8 @@ verify_runnable "global"
function cleanup function cleanup
{ {
datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
datasetexists $TESTPOOL && destroy_pool $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
} }

View File

@ -48,12 +48,13 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TOOSMALL && destroy_pool $TOOSMALL typeset pool
poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
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 partition_disk $SIZE $disk 6
} }

View File

@ -47,9 +47,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
if poolexists $TESTPOOL; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL
fi
} }
if is_linux; then if is_linux; then

View File

@ -54,9 +54,7 @@ function cleanup
zfs destroy $vol_name zfs destroy $vol_name
fi fi
if poolexists $TESTPOOL; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL
fi
} }
log_assert "'zpool create' should fail with regular file in swap." log_assert "'zpool create' should fail with regular file in swap."

View File

@ -56,9 +56,7 @@ function cleanup
fi fi
for pool in $TESTPOOL1 $TESTPOOL; do for pool in $TESTPOOL1 $TESTPOOL; do
if poolexists $pool; then poolexists $pool && destroy_pool $pool
destroy_pool $pool
fi
done done
} }

View File

@ -48,9 +48,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
if poolexists $TESTPOOL; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL
fi
#recover swap devices #recover swap devices
FSTAB=$TEST_BASE_DIR/fstab_$$ FSTAB=$TEST_BASE_DIR/fstab_$$

View File

@ -47,13 +47,8 @@ verify_runnable "global"
function cleanup function cleanup
{ {
if poolexists $TESTPOOL; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL rm -rf $TESTDIR
fi
if [[ -d $TESTDIR ]]; then
log_must rm -rf $TESTDIR
fi
} }
if [[ -n $DISK ]]; then if [[ -n $DISK ]]; then

View File

@ -47,7 +47,7 @@
function cleanup function cleanup
{ {
poolexists $TESTPOOL && destroy_pool $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
[[ -f $CPATH ]] && log_must rm $CPATH rm -f $CPATH
} }
log_onexit cleanup log_onexit cleanup

View File

@ -43,9 +43,7 @@
function cleanup function cleanup
{ {
if poolexists $TESTPOOL ; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL
fi
} }
log_onexit cleanup log_onexit cleanup

View File

@ -46,14 +46,9 @@
function cleanup function cleanup
{ {
if poolexists $TESTPOOL ; then poolexists $TESTPOOL && destroy_pool $TESTPOOL
destroy_pool $TESTPOOL rm -rf /${TESTPOOL}.root
fi rm -f $values
if [ -d /${TESTPOOL}.root ]
then
log_must rmdir /${TESTPOOL}.root
fi
[[ -e $values ]] && log_must rm -f $values
} }
log_onexit cleanup log_onexit cleanup
@ -69,11 +64,11 @@ else
fi fi
log_must rm -f /etc/zfs/zpool.cache 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 log_must zpool create -R /${TESTPOOL}.root $TESTPOOL $disk
if [ ! -d /${TESTPOOL}.root ] if [ ! -d /${TESTPOOL}.root ]
then 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 fi
FS=$(zfs list $TESTPOOL) FS=$(zfs list $TESTPOOL)

View File

@ -48,7 +48,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
} }
log_onexit cleanup log_onexit cleanup

View File

@ -45,7 +45,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL poolexists $TESTPOOL && destroy_pool $TESTPOOL
} }
log_onexit cleanup log_onexit cleanup

View File

@ -30,9 +30,11 @@ verify_runnable "global"
function cleanup function cleanup
{ {
destroy_pool $TESTPOOL typeset pool
destroy_pool $TEMPPOOL
for pool in $TESTPOOL $TEMPPOOL; do
poolexists $pool && destroy_pool $pool
done
} }
log_assert "'zpool create -t <tempname>' can create a pool with the specified" \ log_assert "'zpool create -t <tempname>' can create a pool with the specified" \

View File

@ -42,8 +42,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
log_must rm -f $disk1 rm -f $disk1 $disk2
log_must rm -f $disk2
} }
log_assert "zpool replace -o ashift=<n>' works with different ashift values" log_assert "zpool replace -o ashift=<n>' works with different ashift values"

View File

@ -44,7 +44,7 @@ verify_runnable "global"
function cleanup function cleanup
{ {
poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 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." log_assert "'zpool replace' uses the ashift pool property value as default."

View File

@ -44,7 +44,7 @@ verify_runnable "both"
function cleanup function cleanup
{ {
log_must zpool destroy $TESTPOOL1 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
} }
log_onexit cleanup log_onexit cleanup