From: Shaun Tancheff Date: Fri, 10 Dec 2021 17:45:46 +0000 (-0500) Subject: LU-14707 tests: Bashify scripts for Ubuntu et. al. X-Git-Tag: 2.14.57~63 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=56f69854dae234fa974ab4f1dff909aea601a592 LU-14707 tests: Bashify scripts for Ubuntu et. al. Some scripts use bash-isms that are not present in bourne (sh) or Ubuntu's default dash shell. Be explicit and prefer bash HPE-bug-id: LUS-8398 Signed-off-by: Shaun Tancheff Change-Id: I02f742e9787e1811b422b619e00911ee52673262 Reviewed-on: https://review.whamcloud.com/43786 Tested-by: jenkins Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- diff --git a/lustre/scripts/statechange-lustre.sh b/lustre/scripts/statechange-lustre.sh index 43b3389..b06e490 100755 --- a/lustre/scripts/statechange-lustre.sh +++ b/lustre/scripts/statechange-lustre.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # CDDL HEADER START # diff --git a/lustre/scripts/system-profile.sh b/lustre/scripts/system-profile.sh index 23d0de7..72562c3 100755 --- a/lustre/scripts/system-profile.sh +++ b/lustre/scripts/system-profile.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # System Profiling Script @@ -54,7 +54,7 @@ vmstat_start() { proc_dump_start() { echo "$(date +%T): proc dump started...." >> $OUTPUTDIR/$HOSTNAME/summary - sh -c ' + bash -c ' CTRFILE=/$OUTPUTDIR/$HOSTNAME/tmp/running.$$.pid; echo $$ > ${CTRFILE}; while [ -f $CTRFILE ]; do diff --git a/lustre/tests/compile.sh b/lustre/tests/compile.sh index a3c6b7a..bb4a565 100644 --- a/lustre/tests/compile.sh +++ b/lustre/tests/compile.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -evx MOUNT=${MOUNT:-/mnt/lustre} diff --git a/lustre/tests/dne_sanity.sh b/lustre/tests/dne_sanity.sh index adce2e7..7a18b9d 100644 --- a/lustre/tests/dne_sanity.sh +++ b/lustre/tests/dne_sanity.sh @@ -75,7 +75,7 @@ test_sanity() for index in $(seq $PARALLEL_RUNS); do DIR=$ORIGIN_DIR/dir${index} PARALLEL=yes \ EXT2_DEV="$TMP/SANITY.LOOP_${index}" \ - LOGDIR="${LOGDIR}_${index}" YAML_LOG="" sh sanity.sh & + LOGDIR="${LOGDIR}_${index}" YAML_LOG="" bash sanity.sh & pid=$! echo start sanity: $pid rpids="$rpids $pid" diff --git a/lustre/tests/functions.sh b/lustre/tests/functions.sh index b016732..1807bb8 100644 --- a/lustre/tests/functions.sh +++ b/lustre/tests/functions.sh @@ -169,26 +169,26 @@ signaled() { } mpi_run () { - local mpirun="$MPIRUN $MPIRUN_OPTIONS" - local command="$mpirun $@" - local mpilog=$TMP/mpi.log - local rc - - if [ -n "$MPI_USER" -a "$MPI_USER" != root -a -n "$mpirun" ]; then - echo "+ chmod 0777 $MOUNT" - chmod 0777 $MOUNT - command="su $MPI_USER sh -c \"$command \"" - fi + local mpirun="$MPIRUN $MPIRUN_OPTIONS" + local command="$mpirun $@" + local mpilog=$TMP/mpi.log + local rc + + if [ -n "$MPI_USER" -a "$MPI_USER" != root -a -n "$mpirun" ]; then + echo "+ chmod 0777 $MOUNT" + chmod 0777 $MOUNT + command="su $MPI_USER bash -c \"$command \"" + fi - ls -ald $MOUNT - echo "+ $command" - eval $command 2>&1 | tee $mpilog || true + ls -ald $MOUNT + echo "+ $command" + eval $command 2>&1 | tee $mpilog || true - rc=${PIPESTATUS[0]} - if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then - rc=1 - fi - return $rc + rc=${PIPESTATUS[0]} + if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then + rc=1 + fi + return $rc } nids_list () { diff --git a/lustre/tests/ha.sh b/lustre/tests/ha.sh index 22ff1cc..352bdaa 100755 --- a/lustre/tests/ha.sh +++ b/lustre/tests/ha.sh @@ -519,7 +519,7 @@ ha_repeat_mpi_load() ha_on $client $LFS setstripe $stripeparams $dir && ha_on $client $LFS getstripe $dir && ha_on $client chmod a+xwr $dir && - ha_on $client "su $mpiuser sh -c \" $mpirun $mpirunoptions \ + ha_on $client "su $mpiuser bash -c \" $mpirun $mpirunoptions \ -np $((${#ha_clients[@]} * mpi_threads_per_client / ha_nclientsset)) \ $machines $cmd \" " || rc=$? ha_on ${ha_clients[0]} "$check_attrs && \ diff --git a/lustre/tests/lnet-selftest.sh b/lustre/tests/lnet-selftest.sh index 045ff4a..ba5b379 100755 --- a/lustre/tests/lnet-selftest.sh +++ b/lustre/tests/lnet-selftest.sh @@ -105,20 +105,20 @@ lst_prepare () { # make batch test_smoke_sub () { - local servers=$1 - local clients=$2 + local servers=$1 + local clients=$2 - local nc=$(echo ${clients//,/ } | wc -w) - local ns=$(echo ${servers//,/ } | wc -w) - echo '#!/bin/bash' - echo 'set -e' + local nc=$(echo ${clients//,/ } | wc -w) + local ns=$(echo ${servers//,/ } | wc -w) + echo '#!/bin/bash' + echo 'set -e' - echo 'cleanup () { trap 0; echo killing $1 ... ; kill -9 $1 || true; }' + echo 'cleanup () { trap 0; echo killing $1 ... ; kill -9 $1 || true; }' - echo "$LST new_session --timeo 100000 hh" - echo "$LST add_group c $(nids_list $clients)" - echo "$LST add_group s $(nids_list $servers)" - echo "$LST add_batch b" + echo "$LST new_session --timeo 100000 hh" + echo "$LST add_group c $(nids_list $clients)" + echo "$LST add_group s $(nids_list $servers)" + echo "$LST add_batch b" declare -a tests @@ -151,23 +151,22 @@ test_smoke_sub () { done done - echo $LST run b - echo sleep 1 - echo "$LST stat --delay 10 --timeout 10 c s &" - echo 'pid=$!' - echo 'trap "cleanup $pid" INT TERM' - echo sleep $smoke_DURATION - echo 'cleanup $pid' - + echo $LST run b + echo sleep 1 + echo "$LST stat --delay 10 --timeout 10 c s &" + echo 'pid=$!' + echo 'trap "cleanup $pid" INT TERM' + echo sleep $smoke_DURATION + echo 'cleanup $pid' } run_lst () { - local file=$1 + local file=$1 - export LST_SESSION=$$ + export LST_SESSION=$$ - # start lst - sh $file + # start lst + bash $file } check_lst_err () { diff --git a/lustre/tests/lockorder.sh b/lustre/tests/lockorder.sh index 122df46..0361ba7 100644 --- a/lustre/tests/lockorder.sh +++ b/lustre/tests/lockorder.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e export PATH=`dirname $0`:`dirname $0`/../utils:$PATH diff --git a/lustre/tests/lustre-rsync-test.sh b/lustre/tests/lustre-rsync-test.sh index b16979e..aeda8e3 100644 --- a/lustre/tests/lustre-rsync-test.sh +++ b/lustre/tests/lustre-rsync-test.sh @@ -273,7 +273,8 @@ test_2a() { init_changelog # Run dbench - sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed" + bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || + error "dbench failed" local LRSYNC_LOG=$(generate_logname "lrsync_log") # Replicate the changes to $TGT @@ -297,7 +298,7 @@ test_2b() { init_changelog # Run dbench - sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME & + bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME & # wait for dbench to start wait_for_function 'child_pid=$(pgrep dbench)' 360 # let dbench run for a bit @@ -347,7 +348,7 @@ test_2c() { init_changelog # Run dbench - sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME & + bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME & local LRSYNC_LOG=$(generate_logname "lrsync_log") # Replicate the changes to $TGT diff --git a/lustre/tests/maloo_upload.sh b/lustre/tests/maloo_upload.sh index e16b45a..1a2bb87 100755 --- a/lustre/tests/maloo_upload.sh +++ b/lustre/tests/maloo_upload.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e diff --git a/lustre/tests/mdsrate-create-small.sh b/lustre/tests/mdsrate-create-small.sh index 79e7638..bea656f 100644 --- a/lustre/tests/mdsrate-create-small.sh +++ b/lustre/tests/mdsrate-create-small.sh @@ -1,4 +1,4 @@ - #!/bin/bash +#!/bin/bash # # This test was used in a set of CMD3 tests (cmd3-3 test). diff --git a/lustre/tests/obdfilter-survey.sh b/lustre/tests/obdfilter-survey.sh index 890f0e4..23e2156 100644 --- a/lustre/tests/obdfilter-survey.sh +++ b/lustre/tests/obdfilter-survey.sh @@ -47,7 +47,7 @@ get_targets () { # case 1 (local disk): # $ nobjhi=2 thrhi=2 size=1024 # targets="$nid:$FSNAME-OST0000 $nid:$FSNAME-OST0001 ..." - # sh obdfilter-survey + # ./obdfilter-survey local_node && [ "$1" == "disk" ] || target=$nid:$target targets="$targets $target" done diff --git a/lustre/tests/sanity-gss.sh b/lustre/tests/sanity-gss.sh index c91af2e..9b0d3ff 100755 --- a/lustre/tests/sanity-gss.sh +++ b/lustre/tests/sanity-gss.sh @@ -50,20 +50,20 @@ check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS start_dbench() { - NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l` - [ $NPROC -gt 2 ] && NPROC=2 - sh rundbench $NPROC 1>/dev/null & - DBENCH_PID=$! - sleep 2 - - num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l` - if [ $num -ne 1 ]; then - error "failed to start dbench $NPROC" - else - echo "started dbench with $NPROC processes at background" - fi - - return 0 + NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l` + [ $NPROC -gt 2 ] && NPROC=2 + bash rundbench $NPROC 1>/dev/null & + DBENCH_PID=$! + sleep 2 + + num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l` + if [ $num -ne 1 ]; then + error "failed to start dbench $NPROC" + else + echo "started dbench with $NPROC processes at background" + fi + + return 0 } check_dbench() diff --git a/lustre/tests/sanity-krb5.sh b/lustre/tests/sanity-krb5.sh index 50f23ed..9725e9a 100755 --- a/lustre/tests/sanity-krb5.sh +++ b/lustre/tests/sanity-krb5.sh @@ -64,7 +64,7 @@ start_dbench() { local NPROC=$(grep -c ^processor /proc/cpuinfo) [ $NPROC -gt 2 ] && NPROC=2 - sh rundbench $NPROC 1>/dev/null & + bash rundbench $NPROC 1>/dev/null & DBENCH_PID=$! sleep 2 diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index 4a6921a..13a51bb 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -534,7 +534,7 @@ test_8() { -E -1 -c 4 -S 4M $parent || error "Set default layout to $parent failed" - sh rundbench -C -D $parent 2 || error "dbench failed" + bash rundbench -C -D $parent 2 || error "dbench failed" rm -fr $parent || error "Delete dir $parent failed" } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 44fa276..1ae0337 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -8594,7 +8594,7 @@ run_test 64a "verify filter grant calculations (in kernel) =====" test_64b () { [ $PARALLEL == "yes" ] && skip "skip parallel run" - sh oos.sh $MOUNT || error "oos.sh failed: $?" + bash oos.sh $MOUNT || error "oos.sh failed: $?" } run_test 64b "check out-of-space detection on client" @@ -9380,7 +9380,7 @@ run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======" test_71() { test_mkdir $DIR/$tdir $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir - sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!" + bash rundbench -C -D $DIR/$tdir 2 || error "dbench failed!" } run_test 71 "Running dbench on lustre (don't segment fault) ====" @@ -25073,7 +25073,7 @@ test_411() { # Should not LBUG, just be killed by oom-killer # dd will return 0 even allocation failure in some environment. # So don't check return value - sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" + bash -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" cleanup_test411_cgroup $cgdir return 0 diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 351a346..c1ead99 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -283,7 +283,7 @@ test_11() { run_test 11 "execution of file opened for write should return error ====" test_12() { - DIR=$DIR DIR2=$DIR2 sh lockorder.sh + DIR=$DIR DIR2=$DIR2 bash lockorder.sh } run_test 12 "test lock ordering (link, stat, unlink)" @@ -361,7 +361,7 @@ run_test 14d "chmod of executing file is still possible ========" test_15() { # bug 974 - ENOSPC echo "PATH=$PATH" - sh oos2.sh $MOUNT1 $MOUNT2 + bash oos2.sh $MOUNT1 $MOUNT2 wait_delete_completed grant_error=$(dmesg | grep "< tot_grant") [ -z "$grant_error" ] || error "$grant_error" @@ -822,7 +822,7 @@ run_test 28 "read/write/truncate file with lost stripes" test_30() { #b=11110, LU-2523 test_mkdir $DIR1/$tdir cp -f /bin/bash $DIR1/$tdir/bash - /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' & + bash -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' & $DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?' wait @@ -1123,9 +1123,9 @@ op_trigger_cos() { # trigger CoS twice in case transaction commit before unlock for i in 1 2; do - sh -c "$1" + bash -c "$1" do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0" - sh -c "$2" + bash -c "$2" commit_nr=$(do_nodes $nodes \ "lctl get_param -n mdt.*.async_commit_count" | calc_sum) total=$((total + commit_nr)); diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 6020b10..636a7ca 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -4132,23 +4132,31 @@ do_node() { eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests; PATH=\$PATH:/sbin:/usr/sbin; cd $RPWD; - LUSTRE=\"$RLUSTRE\" sh -c \"$@\") || + LUSTRE=\"$RLUSTRE\" bash -c \"$@\") || echo command failed >$command_status" [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 || return 0 fi - if [[ -n "$verbose" ]]; then - # print HOSTNAME for myPDSH="no_dsh" - if [[ $myPDSH = no_dsh ]]; then - $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /" - else - $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" - fi - else - $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //" - fi - return ${PIPESTATUS[0]} + if [[ -n "$verbose" ]]; then + # print HOSTNAME for myPDSH="no_dsh" + if [[ $myPDSH = no_dsh ]]; then + $myPDSH $HOST \ + "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\ + cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")" | + sed -e "s/^/${HOSTNAME}: /" + else + $myPDSH $HOST \ + "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\ + cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")" + fi + else + $myPDSH $HOST \ + "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\ + cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")" | + sed "s/^${HOST}: //" + fi + return ${PIPESTATUS[0]} } single_local_node () { @@ -4229,9 +4237,9 @@ do_nodes() { # do not replace anything from pdsh output if -N is used # -N Disable hostname: prefix on lines of output. if [[ -n "$verbose" || $myPDSH = *-N* ]]; then - $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" + $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$@\")" else - $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g" + $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$@\")" | sed -re "s/^[^:]*: //g" fi return ${PIPESTATUS[0]} }