Whamcloud - gitweb
LU-16502 lutf: fix bugs in bash scripts 19/54519/3
authorTimothy Day <timday@amazon.com>
Thu, 21 Mar 2024 19:06:51 +0000 (12:06 -0700)
committerOleg Drokin <green@whamcloud.com>
Sat, 4 May 2024 03:01:51 +0000 (03:01 +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.

Lustre-change: https://review.whamcloud.com/49728
Lustre-commit: 3cd0bb6968fc3432b7d1641bf0489e4e4b1e809f

Test-Parameters: trivial env=SANITY_EXCEPT="101j" testlist=sanity
Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: I501d58d25bfcd6564755485b9a1afa2277848b96
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54519
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/lutf.sh
lustre/tests/lutf/python/config/lutf_start.sh

index f512e9e..64f1b9a 100644 (file)
@@ -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 88a6c4a..391cb40 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"