ZTS: Remove bashisms from zfs-tests.sh

Bring zfs-tests.sh in to compliance with the other scripts
by converting it /bin/sh for to avoid a dependency on bash.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10640
This commit is contained in:
Ryan Moeller 2020-08-07 17:10:48 -04:00 committed by GitHub
parent 0cab7970f9
commit d4e6e9597d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 80 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/sh
# #
# CDDL HEADER START # CDDL HEADER START
# #
@ -41,7 +41,7 @@ DEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
RUNFILES=${RUNFILES:-$DEFAULT_RUNFILES} RUNFILES=${RUNFILES:-$DEFAULT_RUNFILES}
FILEDIR=${FILEDIR:-/var/tmp} FILEDIR=${FILEDIR:-/var/tmp}
DISKS=${DISKS:-""} DISKS=${DISKS:-""}
SINGLETEST=() SINGLETEST=""
SINGLETESTUSER="root" SINGLETESTUSER="root"
TAGS="" TAGS=""
ITERATIONS=1 ITERATIONS=1
@ -74,7 +74,7 @@ msg() {
# Log a failure message, cleanup, and return an error. # Log a failure message, cleanup, and return an error.
# #
fail() { fail() {
echo -e "$PROG: $1" >&2 echo "$PROG: $1" >&2
cleanup cleanup
exit 1 exit 1
} }
@ -126,7 +126,7 @@ cleanup() {
fi fi
for TEST_FILE in ${FILES}; do for TEST_FILE in ${FILES}; do
rm -f "${TEST_FILE}" &>/dev/null rm -f "${TEST_FILE}" >/dev/null 2>&1
done done
if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
@ -142,15 +142,15 @@ trap cleanup EXIT
# be dangerous and should only be used in a dedicated test environment. # be dangerous and should only be used in a dedicated test environment.
# #
cleanup_all() { cleanup_all() {
local TEST_POOLS TEST_POOLS
TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool) TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool)
local TEST_LOOPBACKS TEST_LOOPBACKS
if [ "$UNAME" = "FreeBSD" ] ; then if [ "$UNAME" = "FreeBSD" ] ; then
TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l) TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l)
else else
TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:) TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:)
fi fi
local TEST_FILES TEST_FILES
TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null) TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
msg msg
@ -191,8 +191,8 @@ cleanup_all() {
# <name>.run # <name>.run
# #
find_runfile() { find_runfile() {
local NAME=$1 NAME=$1
local RESULT="" RESULT=""
if [ -f "$RUNFILE_DIR/$NAME" ]; then if [ -f "$RUNFILE_DIR/$NAME" ]; then
RESULT="$RUNFILE_DIR/$NAME" RESULT="$RUNFILE_DIR/$NAME"
@ -211,8 +211,8 @@ find_runfile() {
# Symlink file if it appears under any of the given paths. # Symlink file if it appears under any of the given paths.
# #
create_links() { create_links() {
local dir_list="$1" dir_list="$1"
local file_list="$2" file_list="$2"
[ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set" [ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set"
@ -227,8 +227,10 @@ create_links() {
fi fi
done done
[ ! -e "$STF_PATH/$i" ] && STF_MISSING_BIN="$STF_MISSING_BIN$i " [ ! -e "$STF_PATH/$i" ] && \
STF_MISSING_BIN="$STF_MISSING_BIN $i"
done done
STF_MISSING_BIN=${STF_MISSING_BIN# }
} }
# #
@ -243,7 +245,7 @@ constrain_path() {
# install to /usr/local/sbin. To avoid testing the wrong utils we # install to /usr/local/sbin. To avoid testing the wrong utils we
# need /usr/local to come before / in the path search order. # need /usr/local to come before / in the path search order.
SYSTEM_DIRS="/usr/local/bin /usr/local/sbin" SYSTEM_DIRS="/usr/local/bin /usr/local/sbin"
SYSTEM_DIRS+=" /usr/bin /usr/sbin /bin /sbin" SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin"
if [ "$INTREE" = "yes" ]; then if [ "$INTREE" = "yes" ]; then
# Constrained path set to ./zfs/bin/ # Constrained path set to ./zfs/bin/
@ -283,9 +285,9 @@ constrain_path() {
# Standard system utilities # Standard system utilities
SYSTEM_FILES="$SYSTEM_FILES_COMMON" SYSTEM_FILES="$SYSTEM_FILES_COMMON"
if [ "$UNAME" = "FreeBSD" ] ; then if [ "$UNAME" = "FreeBSD" ] ; then
SYSTEM_FILES+=" $SYSTEM_FILES_FREEBSD" SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD"
else else
SYSTEM_FILES+=" $SYSTEM_FILES_LINUX" SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX"
fi fi
create_links "$SYSTEM_DIRS" "$SYSTEM_FILES" create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
@ -380,7 +382,7 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do
;; ;;
n) n)
nfsfile=$OPTARG nfsfile=$OPTARG
[[ -f $nfsfile ]] || fail "Cannot read file: $nfsfile" [ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile"
export NFS=1 export NFS=1
. "$nfsfile" . "$nfsfile"
;; ;;
@ -400,10 +402,10 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do
RUNFILES="$OPTARG" RUNFILES="$OPTARG"
;; ;;
t) t)
if [ ${#SINGLETEST[@]} -ne 0 ]; then if [ -n "$SINGLETEST" ]; then
fail "-t can only be provided once." fail "-t can only be provided once."
fi fi
SINGLETEST+=("$OPTARG") SINGLETEST="$OPTARG"
;; ;;
T) T)
TAGS="$OPTARG" TAGS="$OPTARG"
@ -423,7 +425,7 @@ shift $((OPTIND-1))
FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"} FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
LOOPBACKS=${LOOPBACKS:-""} LOOPBACKS=${LOOPBACKS:-""}
if [ ${#SINGLETEST[@]} -ne 0 ]; then if [ -n "$SINGLETEST" ]; then
if [ -n "$TAGS" ]; then if [ -n "$TAGS" ]; then
fail "-t and -T are mutually exclusive." fail "-t and -T are mutually exclusive."
fi fi
@ -446,22 +448,20 @@ post_user = root
post = post =
outputdir = /var/tmp/test_results outputdir = /var/tmp/test_results
EOF EOF
for t in "${SINGLETEST[@]}" SINGLETESTDIR=$(dirname "$SINGLETEST")
do SINGLETESTFILE=$(basename "$SINGLETEST")
SINGLETESTDIR=$(dirname "$t") SETUPSCRIPT=
SINGLETESTFILE=$(basename "$t") CLEANUPSCRIPT=
SETUPSCRIPT=
CLEANUPSCRIPT=
if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then
SETUPSCRIPT="setup" SETUPSCRIPT="setup"
fi fi
if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then
CLEANUPSCRIPT="cleanup" CLEANUPSCRIPT="cleanup"
fi fi
cat >>$RUNFILE_DIR/$RUNFILES << EOF cat >>$RUNFILE_DIR/$RUNFILES << EOF
[$SINGLETESTDIR] [$SINGLETESTDIR]
tests = ['$SINGLETESTFILE'] tests = ['$SINGLETESTFILE']
@ -469,7 +469,6 @@ pre = $SETUPSCRIPT
post = $CLEANUPSCRIPT post = $CLEANUPSCRIPT
tags = ['functional'] tags = ['functional']
EOF EOF
done
fi fi
# #
@ -487,7 +486,7 @@ for RUNFILE in $RUNFILES; do
SAVED_RUNFILE="$RUNFILE" SAVED_RUNFILE="$RUNFILE"
RUNFILE=$(find_runfile "$RUNFILE") RUNFILE=$(find_runfile "$RUNFILE")
[ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE" [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE"
R+="${R:+,}${RUNFILE}" R="$R,$RUNFILE"
fi fi
if [ ! -r "$RUNFILE" ]; then if [ ! -r "$RUNFILE" ]; then
@ -495,7 +494,7 @@ for RUNFILE in $RUNFILES; do
fi fi
done done
unset IFS unset IFS
RUNFILES=$R RUNFILES=${R#,}
# #
# This script should not be run as root. Instead the test user, which may # This script should not be run as root. Instead the test user, which may
@ -529,9 +528,9 @@ fi
# Verify the ZFS module stack is loaded. # Verify the ZFS module stack is loaded.
# #
if [ "$STACK_TRACER" = "yes" ]; then if [ "$STACK_TRACER" = "yes" ]; then
sudo "${ZFS_SH}" -S &>/dev/null sudo "${ZFS_SH}" -S >/dev/null 2>&1
else else
sudo "${ZFS_SH}" &>/dev/null sudo "${ZFS_SH}" >/dev/null 2>&1
fi fi
# #
@ -552,7 +551,7 @@ if [ -z "${KEEP}" ]; then
KEEP="rpool" KEEP="rpool"
fi fi
else else
KEEP="$(echo -e "${KEEP//[[:blank:]]/\n}")" KEEP="$(echo "$KEEP" | tr '[:blank:]' '\n')"
fi fi
# #
@ -592,19 +591,12 @@ if [ -z "${DISKS}" ]; then
[ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
truncate -s "${FILESIZE}" "${TEST_FILE}" || truncate -s "${FILESIZE}" "${TEST_FILE}" ||
fail "Failed creating: ${TEST_FILE} ($?)" fail "Failed creating: ${TEST_FILE} ($?)"
if [[ "$DISKS" ]]; then
DISKS="$DISKS $TEST_FILE"
else
DISKS="$TEST_FILE"
fi
done done
# #
# If requested setup loopback devices backed by the sparse files. # If requested setup loopback devices backed by the sparse files.
# #
if [ "$LOOPBACK" = "yes" ]; then if [ "$LOOPBACK" = "yes" ]; then
DISKS=""
test -x "$LOSETUP" || fail "$LOSETUP utility must be installed" test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
for TEST_FILE in ${FILES}; do for TEST_FILE in ${FILES}; do
@ -613,25 +605,21 @@ if [ -z "${DISKS}" ]; then
if [ -z "$MDDEVICE" ] ; then if [ -z "$MDDEVICE" ] ; then
fail "Failed: ${TEST_FILE} -> loopback" fail "Failed: ${TEST_FILE} -> loopback"
fi fi
LOOPBACKS="${LOOPBACKS}${MDDEVICE} " DISKS="$DISKS $MDDEVICE"
if [[ "$DISKS" ]]; then LOOPBACKS="$LOOPBACKS $MDDEVICE"
DISKS="$DISKS $MDDEVICE"
else
DISKS="$MDDEVICE"
fi
else else
TEST_LOOPBACK=$(sudo "${LOSETUP}" -f) TEST_LOOPBACK=$(sudo "${LOSETUP}" -f)
sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" || sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} " BASELOOPBACK=$(basename "$TEST_LOOPBACK")
BASELOOPBACKS=$(basename "$TEST_LOOPBACK") DISKS="$DISKS $BASELOOPBACK"
if [[ "$DISKS" ]]; then LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK"
DISKS="$DISKS $BASELOOPBACKS"
else
DISKS="$BASELOOPBACKS"
fi
fi fi
done done
DISKS=${DISKS# }
LOOPBACKS=${LOOPBACKS# }
else
DISKS="$FILES"
fi fi
fi fi
@ -642,7 +630,7 @@ NUM_DISKS=$(echo "${DISKS}" | awk '{print NF}')
# Disable SELinux until the ZFS Test Suite has been updated accordingly. # Disable SELinux until the ZFS Test Suite has been updated accordingly.
# #
if [ -x "$STF_PATH/setenforce" ]; then if [ -x "$STF_PATH/setenforce" ]; then
sudo setenforce permissive &>/dev/null sudo setenforce permissive >/dev/null 2>&1
fi fi
# #
@ -703,10 +691,9 @@ ${TEST_RUNNER} ${QUIET:+-q} \
# #
# Analyze the results. # Analyze the results.
# #
set -o pipefail ${ZTS_REPORT} "$RESULTS_FILE" >"$REPORT_FILE"
${ZTS_REPORT} "$RESULTS_FILE" | tee "$REPORT_FILE"
RESULT=$? RESULT=$?
set +o pipefail cat "$REPORT_FILE"
RESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE") RESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE")
if [ -d "$RESULTS_DIR" ]; then if [ -d "$RESULTS_DIR" ]; then
@ -715,8 +702,8 @@ fi
rm -f "$RESULTS_FILE" "$REPORT_FILE" rm -f "$RESULTS_FILE" "$REPORT_FILE"
if [ ${#SINGLETEST[@]} -ne 0 ]; then if [ -n "$SINGLETEST" ]; then
rm -f "$RUNFILES" &>/dev/null rm -f "$RUNFILES" >/dev/null 2>&1
fi fi
exit ${RESULT} exit ${RESULT}

View File

@ -1,3 +1,5 @@
#!/bin/sh
# #
# CDDL HEADER START # CDDL HEADER START
# #
@ -30,7 +32,6 @@
# #
. $STF_SUITE/include/commands.cfg . $STF_SUITE/include/commands.cfg
. $STF_SUITE/include/libtest.shlib
# ZFS Directories # ZFS Directories
export ZEDLET_ETC_DIR=${ZEDLET_ETC_DIR:-@sysconfdir@/zfs/zed.d} export ZEDLET_ETC_DIR=${ZEDLET_ETC_DIR:-@sysconfdir@/zfs/zed.d}
@ -143,17 +144,6 @@ export SPA_MINDEVSIZE=$((64 * 1024 * 1024))
# For iscsi target support # For iscsi target support
export ISCSITGTFILE=/tmp/iscsitgt_file export ISCSITGTFILE=/tmp/iscsitgt_file
export ISCSITGT_FMRI=svc:/system/iscsitgt:default export ISCSITGT_FMRI=svc:/system/iscsitgt:default
if is_illumos; then
export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \
'{print $3}')
fi
#
# finally, if we're running in a local zone
# we take some additional actions
if ! is_global_zone; then
reexport_pool
fi
export ZFS_VERSION=5 export ZFS_VERSION=5
export ZFS_ALL_VERSIONS="1 2 3 4 5" export ZFS_ALL_VERSIONS="1 2 3 4 5"
@ -164,7 +154,8 @@ done
export MAX_PARTITIONS=8 export MAX_PARTITIONS=8
if is_linux; then case $(uname -o) in
GNU/Linux)
unpack_opts="--sparse -xf" unpack_opts="--sparse -xf"
pack_opts="--sparse -cf" pack_opts="--sparse -cf"
verbose=" -v" verbose=" -v"
@ -185,7 +176,8 @@ if is_linux; then
NEWFS_DEFAULT_FS="ext2" NEWFS_DEFAULT_FS="ext2"
SLICE_PREFIX="" SLICE_PREFIX=""
elif is_freebsd; then ;;
FreeBSD)
unpack_opts="xv" unpack_opts="xv"
pack_opts="cf" pack_opts="cf"
verbose="v" verbose="v"
@ -200,7 +192,16 @@ elif is_freebsd; then
NEWFS_DEFAULT_FS="ufs" NEWFS_DEFAULT_FS="ufs"
SLICE_PREFIX="p" SLICE_PREFIX="p"
else ;;
illumos)
export AUTO_SNAP=$(svcs -a | \
awk '/auto-snapshot/ && /online/ { print $3 }')
# finally, if we're running in a local zone
# we take some additional actions
if [ "$(zonename 2>/dev/null)" != "global" ]; then
reexport_pool
fi
unpack_opts="xv" unpack_opts="xv"
pack_opts="cf" pack_opts="cf"
verbose="v" verbose="v"
@ -214,7 +215,8 @@ else
NEWFS_DEFAULT_FS="ufs" NEWFS_DEFAULT_FS="ufs"
SLICE_PREFIX="s" SLICE_PREFIX="s"
fi ;;
esac
export unpack_opts pack_opts verbose unpack_preserve pack_preserve \ export unpack_opts pack_opts verbose unpack_preserve pack_preserve \
ZVOL_DEVDIR ZVOL_RDEVDIR DEV_DSKDIR DEV_RDSKDIR DEV_MPATHDIR \ ZVOL_DEVDIR ZVOL_RDEVDIR DEV_DSKDIR DEV_RDSKDIR DEV_MPATHDIR \
ZEDLET_DIR ZED_LOG ZED_DEBUG_LOG VDEVID_CONF VDEVID_CONF_ETC \ ZEDLET_DIR ZED_LOG ZED_DEBUG_LOG VDEVID_CONF VDEVID_CONF_ETC \