Whamcloud - gitweb
LU-16502 lutf: fix bugs in bash scripts 28/49728/4
authorTimothy Day <timday@amazon.com>
Sat, 21 Jan 2023 01:40:13 +0000 (01:40 +0000)
committerOleg Drokin <green@whamcloud.com>
Tue, 14 Feb 2023 06:05:15 +0000 (06:05 +0000)
Addressed some issues I found when running
LUTF. The "rm" fails without a file to remove.
A Lustre wiki led me to source the script, but this
will log out of the current shell. Adding a warning
against doing this.

Also, fix shellcheck errors and a few warnings in
LUTF related scripts. Added bash shebangs, since
shellcheck requires these to lint the scripts.

Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: I501d58d25bfcd6564755485b9a1afa2277848b96
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49728
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
lustre/tests/lutf.sh [changed mode: 0644->0755]
lustre/tests/lutf/python/config/lutf_start.sh

old mode 100644 (file)
new mode 100755 (executable)
index f512e9e..64f1b9a
@@ -1,7 +1,14 @@
+#!/bin/bash
 # Run select tests by setting ONLY, or as arguments to the script.
 # Skip specific tests by setting EXCEPT.
 #
 
+# Sourcing this script will log you out from your shell
+if [[ -n "${PS1}" ]]; then
+       echo "Do not source this script. Run using ./lutf.sh instead."
+       return 1
+fi
+
 export ONLY=${ONLY:-"$*"}
 export SUITE=${SUITE:-"$*"}
 export PATTERN=${PATTERN:-"$*"}
@@ -9,11 +16,11 @@ export PATTERN=${PATTERN:-"$*"}
 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-LUSTRE=${LUSTRE:-$(dirname $0)/..}
+LUSTRE=${LUSTRE:-$(dirname "$0")/..}
 
-. $LUSTRE/tests/test-framework.sh
-init_test_env $@
-. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
+. "$LUSTRE/tests/test-framework.sh"
+init_test_env "$@"
+. "${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}"
 init_logging
 
 # bug number for skipped test:
@@ -25,7 +32,7 @@ export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
 [[ -z $LNETCTL ]] && skip "Need lnetctl"
 
 restore_mounts=false
-if is_mounted $MOUNT || is_mounted $MOUNT2; then
+if is_mounted "$MOUNT" || is_mounted "$MOUNT2"; then
        cleanupall || error "Failed cleanup prior to test execution"
        restore_mounts=true
 fi
@@ -62,19 +69,19 @@ set_env_vars_on_remote() {
 
 set_env_vars_on_remote
 
-rm /tmp/tf.skip
+rm -f /tmp/tf.skip
 
 # do not exit if LUTF fails
 set +e
 
 echo "+++++++++++STARTING LUTF"
-. $LUSTRE/tests/lutf/python/config/lutf_start.sh $CONFIG
+. "$LUSTRE/tests/lutf/python/config/lutf_start.sh" "$CONFIG"
 rc=$?
 echo "-----------STOPPING LUTF: $rc"
 
 if [ -d /tmp/lutf/ ]; then
        tar -czf /tmp/lutf.tar.gz /tmp/lutf
-       mv /tmp/lutf.tar.gz $LOGDIR
+       mv /tmp/lutf.tar.gz "$LOGDIR"
 fi
 
 
index 55d33e9..5ca7f33 100644 (file)
@@ -1,3 +1,4 @@
+#!/bin/bash
 # note the cfg/<lutf config>.sh should export all environment variables
 # required. EX: export ost4_HOST=lustre01
 
@@ -26,4 +27,4 @@ if [[ -z "${PYTHONBIN}" ]]; then
 fi
 
 export LUTF_ENV_VARS=$1
-$PYTHONBIN $LUSTRE/tests/lutf/python/config/lutf_start.py
+$PYTHONBIN "$LUSTRE/tests/lutf/python/config/lutf_start.py"