Skip to content

Commit

Permalink
zpool_export: make test suite more usable
Browse files Browse the repository at this point in the history
- refactor cleanup routines into common kshlib zpool_export_cleanup func
- don't require physical disks to test, just use files
  • Loading branch information
wca authored and behlendorf committed Jan 12, 2021
1 parent 380e181 commit 5da9ecf
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dist_pkgdata_SCRIPTS = \
zpool_export_004_pos.ksh

dist_pkgdata_DATA = \
zpool_export.cfg
zpool_export.cfg \
zpool_export.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 5da9ecf

Please sign in to comment.