From 3cd0bb6968fc3432b7d1641bf0489e4e4b1e809f Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Sat, 21 Jan 2023 01:40:13 +0000 Subject: [PATCH] LU-16502 lutf: fix bugs in bash scripts 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 Change-Id: I501d58d25bfcd6564755485b9a1afa2277848b96 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49728 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin Reviewed-by: Arshad Hussain --- lustre/tests/lutf.sh | 23 +++++++++++++++-------- lustre/tests/lutf/python/config/lutf_start.sh | 3 ++- 2 files changed, 17 insertions(+), 9 deletions(-) mode change 100644 => 100755 lustre/tests/lutf.sh diff --git a/lustre/tests/lutf.sh b/lustre/tests/lutf.sh old mode 100644 new mode 100755 index f512e9e..64f1b9a --- a/lustre/tests/lutf.sh +++ b/lustre/tests/lutf.sh @@ -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 diff --git a/lustre/tests/lutf/python/config/lutf_start.sh b/lustre/tests/lutf/python/config/lutf_start.sh index 55d33e9..5ca7f33 100644 --- a/lustre/tests/lutf/python/config/lutf_start.sh +++ b/lustre/tests/lutf/python/config/lutf_start.sh @@ -1,3 +1,4 @@ +#!/bin/bash # note the cfg/.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" -- 1.8.3.1