Whamcloud - gitweb
LU-14707 tests: Bashify scripts for Ubuntu et. al. 86/43786/8
authorShaun Tancheff <shaun.tancheff@hpe.com>
Fri, 10 Dec 2021 17:45:46 +0000 (12:45 -0500)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Jan 2022 22:01:36 +0000 (22:01 +0000)
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 <shaun.tancheff@hpe.com>
Change-Id: I02f742e9787e1811b422b619e00911ee52673262
Reviewed-on: https://review.whamcloud.com/43786
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
18 files changed:
lustre/scripts/statechange-lustre.sh
lustre/scripts/system-profile.sh
lustre/tests/compile.sh
lustre/tests/dne_sanity.sh
lustre/tests/functions.sh
lustre/tests/ha.sh
lustre/tests/lnet-selftest.sh
lustre/tests/lockorder.sh
lustre/tests/lustre-rsync-test.sh
lustre/tests/maloo_upload.sh
lustre/tests/mdsrate-create-small.sh
lustre/tests/obdfilter-survey.sh
lustre/tests/sanity-gss.sh
lustre/tests/sanity-krb5.sh
lustre/tests/sanity-pfl.sh
lustre/tests/sanity.sh
lustre/tests/sanityn.sh
lustre/tests/test-framework.sh

index 43b3389..b06e490 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # CDDL HEADER START
 #
index 23d0de7..72562c3 100755 (executable)
@@ -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
index a3c6b7a..bb4a565 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 set -evx
 
 MOUNT=${MOUNT:-/mnt/lustre}
index adce2e7..7a18b9d 100644 (file)
@@ -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"
index b016732..1807bb8 100644 (file)
@@ -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 () {
index 22ff1cc..352bdaa 100755 (executable)
@@ -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 &&                    \
index 045ff4a..ba5b379 100755 (executable)
@@ -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 () {
index 122df46..0361ba7 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 set -e
 
 export PATH=`dirname $0`:`dirname $0`/../utils:$PATH
index b16979e..aeda8e3 100644 (file)
@@ -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
index e16b45a..1a2bb87 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 set -e
 
index 79e7638..bea656f 100644 (file)
@@ -1,4 +1,4 @@
- #!/bin/bash
+#!/bin/bash
 #
 # This test was used in a set of CMD3 tests (cmd3-3 test).
 
index 890f0e4..23e2156 100644 (file)
@@ -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
index c91af2e..9b0d3ff 100755 (executable)
@@ -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()
index 50f23ed..9725e9a 100755 (executable)
@@ -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
 
index 4a6921a..13a51bb 100644 (file)
@@ -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"
 }
index 44fa276..1ae0337 100755 (executable)
@@ -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
index 351a346..c1ead99 100755 (executable)
@@ -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));
index 6020b10..636a7ca 100755 (executable)
@@ -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]}
 }