From d7265b330954fe844958642c5f61e790c58442d5 Mon Sep 17 00:00:00 2001 From: Will Andrews Date: Tue, 26 Jan 2021 15:14:04 -0600 Subject: [PATCH] ZTS: zpool_export test improvements - refactor cleanup routines into common kshlib zpool_export_cleanup func - don't require physical disks to test, just use files Reviewed-by: Brian Behlendorf Signed-off-by: Will Andrews Closes #11518 --- .../cli_root/zpool_export/Makefile.am | 3 +- .../cli_root/zpool_export/setup.ksh | 4 -- .../cli_root/zpool_export/zpool_export.cfg | 37 ++++++------------- .../cli_root/zpool_export/zpool_export.kshlib | 32 ++++++++++++++++ .../zpool_export/zpool_export_001_pos.ksh | 17 +-------- .../zpool_export/zpool_export_002_pos.ksh | 13 +------ .../zpool_export/zpool_export_003_neg.ksh | 15 +------- .../zpool_export/zpool_export_004_pos.ksh | 21 +---------- 8 files changed, 53 insertions(+), 89 deletions(-) create mode 100644 tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.kshlib diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am index 86452e8acc..1c06d5b59e 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am @@ -8,4 +8,5 @@ dist_pkgdata_SCRIPTS = \ zpool_export_004_pos.ksh dist_pkgdata_DATA = \ - zpool_export.cfg + zpool_export.cfg \ + zpool_export.kshlib diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh index 664fb2ddd8..023920dae1 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh @@ -30,8 +30,4 @@ DISK=${DISKS%% *} -if ! is_physical_device $DISK; then - log_unsupported "Only partitionable physical disks can be used" -fi - default_setup $DISK diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.cfg index 1501c04630..8bfb067c7a 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.cfg @@ -30,30 +30,15 @@ . $STF_SUITE/include/libtest.shlib -export DISK_ARRAY_NUM=0 -export DISK_ARRAY_LIMIT=4 -export DISKSARRAY="" -export VDEVS_NUM=32 +export DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}') +export DISK1=$(echo $DISKS | awk '{print $1}') +export DISK2=$(echo $DISKS | awk '{print $3}') -function set_disks -{ - typeset -a disk_array=($(find_disks $DISKS)) - - if (( ${#disk_array[*]} <= 1 )); then - export DISK=${DISKS%% *} - else - export DISK="" - typeset -i i=0 - while (( i < ${#disk_array[*]} )); do - export DISK${i}="${disk_array[$i]}" - DISKSARRAY="$DISKSARRAY ${disk_array[$i]}" - (( i = i + 1 )) - (( i>$DISK_ARRAY_LIMIT )) && break - done - export DISK_ARRAY_NUM=$i - export DISKSARRAY - fi -} - -set_disks -set_device_dir +if is_linux; then + set_slice_prefix + set_device_dir + devs_id[0]=$(get_persistent_disk_name $DISK1) + devs_id[1]=$(get_persistent_disk_name $DISK2) +else + DEV_DSKDIR="/dev" +fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.kshlib new file mode 100644 index 0000000000..5484f20674 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export.kshlib @@ -0,0 +1,32 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2020, Klara Systems, Inc. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.cfg + +function zpool_export_cleanup +{ + [[ -d $TESTDIR0 ]] && log_must rm -rf $TESTDIR0 + default_cleanup +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh index b6823553d7..111453c7a1 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh @@ -29,8 +29,7 @@ # Copyright (c) 2016 by Delphix. All rights reserved. # -. $STF_SUITE/include/libtest.shlib -. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.cfg +. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.kshlib # # DESCRIPTION: @@ -46,19 +45,7 @@ verify_runnable "global" -function cleanup -{ - typeset dir=$(get_device_dir $DISKS) - - datasetexists "$TESTPOOL/$TESTFS" || \ - log_must zpool import -d $dir $TESTPOOL - - ismounted "$TESTPOOL/$TESTFS" - (( $? != 0 )) && \ - log_must zfs mount $TESTPOOL/$TESTFS -} - -log_onexit cleanup +log_onexit zpool_export_cleanup log_assert "Verify a pool can be exported." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh index 81473d903a..8040d12b92 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh @@ -29,7 +29,7 @@ # Copyright (c) 2016 by Delphix. All rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.kshlib # # DESCRIPTION: @@ -45,19 +45,10 @@ verify_runnable "global" function cleanup { - typeset dir=$(get_device_dir $DISKS) cd $olddir || \ log_fail "Couldn't cd back to $olddir" - datasetexists "$TESTPOOL/$TESTFS" || \ - log_must zpool import -d $dir $TESTPOOL - - ismounted "$TESTPOOL/$TESTFS" - (( $? != 0 )) && \ - log_must zfs mount $TESTPOOL/$TESTFS - - [[ -e $TESTDIR/$TESTFILE0 ]] && \ - log_must rm -rf $TESTDIR/$TESTFILE0 + zpool_export_cleanup } olddir=$PWD diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh index b188f9c330..a2ee7fbdf9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh @@ -29,7 +29,7 @@ # Copyright (c) 2016 by Delphix. All rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.kshlib # # DESCRIPTION: @@ -43,18 +43,7 @@ verify_runnable "global" -function cleanup -{ - typeset dir=$(get_device_dir $DISKS) - datasetexists "$TESTPOOL/$TESTFS" || \ - log_must zpool import -d $dir $TESTPOOL - - ismounted "$TESTPOOL/$TESTFS" - (( $? != 0 )) && \ - log_must zfs mount $TESTPOOL/$TESTFS -} - -log_onexit cleanup +log_onexit zpool_export_cleanup set -A args "" "-f" "-? $TESTPOOL" "-QWERTYUIO $TESTPOOL" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh index 0f1a7c624d..9be3f23c4f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh @@ -29,7 +29,7 @@ # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_export/zpool_export.kshlib # # DESCRIPTION: @@ -50,25 +50,8 @@ verify_runnable "global" -function cleanup -{ - mntpnt=$TESTDIR0 - datasetexists $TESTPOOL1 || log_must zpool import -d $mntpnt $TESTPOOL1 - datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2 - typeset -i i=0 - while ((i < 5)); do - if [[ -e $mntpnt/vdev$i ]]; then - log_must rm -f $mntpnt/vdev$i - fi - ((i += 1)) - done - log_must rmdir $mntpnt -} - - log_assert "Verify zpool export succeed or fail with spare." -log_onexit cleanup +log_onexit zpool_export_cleanup mntpnt=$TESTDIR0 log_must mkdir -p $mntpnt