Whamcloud - gitweb
LU-13960 tests: correct usage of _var variable
[fs/lustre-release.git] / lustre / tests / ha.sh
index 0c47ed6..d30424a 100755 (executable)
@@ -82,6 +82,9 @@
 #   The number of clients run MPI loads is configured by parameter
 #   ha_mpi_instances. Only one client runs MPI workloads by default.
 #
+#   MPI workloads can be run from several users. The list of users to use is
+#   configured by parameter ha_mpi_users, default is "mpiuser".
+#
 # PROCESS STRUCTURE AND IPC
 #
 #   On the node where this script is run, the processes look like this:
@@ -212,19 +215,27 @@ declare     ha_mpi_instances=${ha_mpi_instances:-1}
 
 declare     ha_mpi_loads=${ha_mpi_loads="ior simul mdtest"}
 declare -a  ha_mpi_load_tags=($ha_mpi_loads)
+declare -a  ha_mpiusers=(${ha_mpi_users="mpiuser"})
 
 declare     ha_ior_params=${IORP:-'" -b $ior_blockSize -t 2m -w -W -T 1"'}
 declare     ha_simul_params=${SIMULP:-'" -n 10"'}
 declare     ha_mdtest_params=${MDTESTP:-'" -i 1 -n 1000"'}
 declare     ha_mpirun_options=${MPIRUN_OPTIONS:-""}
+declare     ha_clients_stripe=${CLIENTSSTRIPE:-'"$STRIPEPARAMS"'}
+declare     ha_nclientsset=${NCLIENTSSET:-1}
+declare     ha_ninstmustfail=${NINSTMUSTFAIL:-0}
+
+declare     ha_racer_params=${RACERP:-"MDSCOUNT=1"}
 
 eval ha_params_ior=($ha_ior_params)
 eval ha_params_simul=($ha_simul_params)
 eval ha_params_mdtest=($ha_mdtest_params)
+eval ha_stripe_clients=($ha_clients_stripe)
 
 declare ha_nparams_ior=${#ha_params_ior[@]}
 declare ha_nparams_simul=${#ha_params_simul[@]}
 declare ha_nparams_mdtest=${#ha_params_mdtest[@]}
+declare ha_nstripe_clients=${#ha_stripe_clients[@]}
 
 declare -A  ha_mpi_load_cmds=(
        [ior]="$IOR -o {}/f.ior {params}"
@@ -232,12 +243,15 @@ declare -A  ha_mpi_load_cmds=(
        [mdtest]="$MDTEST {params} -d {}"
 )
 
+declare racer=${RACER:-"$(dirname $0)/racer/racer.sh"}
+
 declare     ha_nonmpi_loads=${ha_nonmpi_loads="dd tar iozone"}
 declare -a  ha_nonmpi_load_tags=($ha_nonmpi_loads)
-declare -a  ha_nonmpi_load_cmds=(
-       "dd if=/dev/zero of={}/f.dd bs=1M count=256"
-       "tar cf - /etc | tar xf - -C {}"
-       "iozone -a -e -+d -s $iozone_SIZE {}/f.iozone"
+declare -A  ha_nonmpi_load_cmds=(
+       [dd]="dd if=/dev/zero of={}/f.dd bs=1M count=256"
+       [tar]="tar cf - /etc | tar xf - -C {}"
+       [iozone]="iozone -a -e -+d -s $iozone_SIZE {}/f.iozone"
+       [racer]="$ha_racer_params $racer {}"
 )
 
 ha_usage()
@@ -404,6 +418,10 @@ ha_repeat_mpi_load()
        local load=$2
        local status=$3
        local parameter=$4
+       local machines=$5
+       local stripeparams=$6
+       local mpiuser=$7
+       local mustpass=$8
        local tag=${ha_mpi_load_tags[$load]}
        local cmd=${ha_mpi_load_cmds[$tag]}
        local dir=$ha_test_dir/$client-$tag
@@ -416,10 +434,12 @@ ha_repeat_mpi_load()
        cmd=${cmd//"{}"/$dir}
        cmd=${cmd//"{params}"/$parameter}
 
+       [[ -n "$ha_postcmd" ]] && ha_postcmd=${ha_postcmd//"{}"/$dir}
        ha_info "Starting $tag"
 
-       local machines="-machinefile $ha_machine_file"
+       machines="-machinefile $machines"
        while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
+               ha_info "$client Starts: $cmd" 2>&1 |  tee -a $log
                {
                local mdt_index
                if $ha_mdt_index_random && [ $ha_mdt_index -ne 0 ]; then
@@ -429,21 +449,37 @@ ha_repeat_mpi_load()
                fi
                ha_on $client $LFS mkdir -i$mdt_index -c$ha_dir_stripe_count "$dir" &&
                ha_on $client $LFS getdirstripe "$dir" &&
+               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 $ha_mpirun_options \
+               ha_on $client "su $mpiuser sh -c \" $mpirun $ha_mpirun_options \
                        -np $((${#ha_clients[@]} * mpi_threads_per_client )) \
-                       $machines $cmd \" " &&
+                       $machines $cmd \" " || rc=$?
+               [[ -n "$ha_postcmd" ]] && ha_info "$ha_postcmd" &&
+                       ha_on $client $ha_postcmd >>"$log" 2>&1
+               (( ((rc == 0)) && (( mustpass != 0 )) )) ||
+               (( ((rc != 0)) && (( mustpass == 0 )) )) &&
                        ha_on $client rm -rf "$dir";
                } >>"$log" 2>&1 || rc=$?
 
-               ha_info rc=$rc
-
-               if ((rc != 0)); then
+               ha_info rc=$rc mustpass=$mustpass
+
+               # mustpass=0 means that failure is expected
+               if (( rc !=0 )); then
+                       if (( mustpass != 0 )); then
+                               touch "$ha_fail_file"
+                               touch "$ha_stop_file"
+                               ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
+                       else
+                               # Ok to fail
+                               rc=0
+                       fi
+               elif (( mustpass == 0 )); then
                        touch "$ha_fail_file"
                        touch "$ha_stop_file"
                        ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
                fi
-               echo $rc >"$status"
+               echo rc=$rc mustpass=$mustpass >"$status"
 
                nr_loops=$((nr_loops + 1))
        done
@@ -451,7 +487,8 @@ ha_repeat_mpi_load()
        [ $nr_loops -ne 0 ] &&
                avg_loop_time=$((($(date +%s) - start_time) / nr_loops))
 
-       ha_info "$tag stopped: rc $rc avg loop time $avg_loop_time"
+       ha_info "$tag stopped: rc=$rc mustpass=$mustpass \
+               avg loop time $avg_loop_time"
 }
 
 ha_start_mpi_loads()
@@ -462,24 +499,44 @@ ha_start_mpi_loads()
        local status
        local n
        local nparam
+       local machines
+       local m
+       local -a mach
+       local mpiuser
 
-       for client in ${ha_clients[@]}; do
-               ha_info ha_machine_file=$ha_machine_file
-               echo $client >> $ha_machine_file
+       # ha_mpi_instances defines the number of
+       # clients start mpi loads; should be <= ${#ha_clients[@]}
+       # do nothing if
+       #    ha_mpi_instances = 0
+       # or
+       #    ${#ha_mpi_load_tags[@]} =0
+       local inst=$ha_mpi_instances
+       (( inst == 0 )) || (( ${#ha_mpi_load_tags[@]} == 0 )) &&
+               ha_info "no mpi load to start" &&
+               return 0
+
+       (( inst <= ${#ha_clients[@]} )) || inst=${#ha_clients[@]}
+
+       # Define names for machinefiles for each client set
+       for (( n=0; n < $ha_nclientsset; n++ )); do
+               mach[$n]=$ha_machine_file$n
+       done
+
+       for ((n = 0; n < ${#ha_clients[@]}; n++)); do
+               m=$(( n % ha_nclientsset))
+               machines=${mach[m]}
+               ha_info machine_file=$machines
+               echo ${ha_clients[n]} >> $machines
        done
        local dirname=$(dirname $ha_machine_file)
        for client in ${ha_clients[@]}; do
                ha_on $client mkdir -p $dirname
-               scp $ha_machine_file $client:$ha_machine_file
+               scp $ha_machine_file* $client:$dirname
        done
 
-       # ha_mpi_instances defines the number of
-       # clients start mpi loads; should be <= ${#ha_clients[@]}
-       local inst=$ha_mpi_instances
-       (( inst <= ${#ha_clients[@]} )) || inst=${#ha_clients[@]}
-
        for ((n = 0; n < $inst; n++)); do
                client=${ha_clients[n]}
+               mpiuser=${ha_mpiusers[$((n % ${#ha_mpiusers[@]}))]}
                for ((load = 0; load < ${#ha_mpi_load_tags[@]}; load++)); do
                        tag=${ha_mpi_load_tags[$load]}
                        status=$ha_status_file_prefix-$tag-$client
@@ -489,7 +546,16 @@ ha_start_mpi_loads()
                        nparam=$((n % num))
                        local aref=ha_params_$tag[nparam]
                        local parameter=${!aref}
-                       ha_repeat_mpi_load $client $load $status "$parameter" &
+                       local nstripe=$((n % ha_nstripe_clients))
+                       aref=ha_stripe_clients[nstripe]
+                       local stripe=${!aref}
+                       local m=$(( n % ha_nclientsset))
+                       machines=${mach[m]}
+                       local mustpass=1
+                       [[ $ha_ninstmustfail == 0 ]] ||
+                               mustpass=$(( n % ha_ninstmustfail ))
+                       ha_repeat_mpi_load $client $load $status "$parameter" \
+                               $machines "$stripe" "$mpiuser" "$mustpass" &
                                ha_status_files+=("$status")
                done
        done
@@ -501,7 +567,7 @@ ha_repeat_nonmpi_load()
        local load=$2
        local status=$3
        local tag=${ha_nonmpi_load_tags[$load]}
-       local cmd=${ha_nonmpi_load_cmds[$load]}
+       local cmd=${ha_nonmpi_load_cmds[$tag]}
        local dir=$ha_test_dir/$client-$tag
        local log=$ha_tmp_dir/$client-$tag
        local rc=0
@@ -509,11 +575,12 @@ ha_repeat_nonmpi_load()
        local avg_loop_time=0
        local start_time=$(date +%s)
 
-    cmd=${cmd//"{}"/$dir}
+       cmd=${cmd//"{}"/$dir}
 
-    ha_info "Starting $tag on $client"
+       ha_info "Starting $tag on $client"
 
        while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
+               ha_info "$client Starts: $cmd" 2>&1 |  tee -a $log
                ha_on $client "mkdir -p $dir &&                              \
                        $cmd &&                                              \
                        rm -rf $dir" >>"$log" 2>&1 || rc=$?
@@ -664,17 +731,20 @@ ha_lfsck_repaired()
 
 ha_start_loads()
 {
-    trap ha_trap_stop_signals $ha_stop_signals
-    ha_start_nonmpi_loads
-    ha_start_mpi_loads
+       $ha_lfsck_bg && ha_lfsck_bg
+       trap ha_trap_stop_signals $ha_stop_signals
+       ha_start_nonmpi_loads
+       ha_start_mpi_loads
 }
 
 ha_stop_loads()
 {
-    touch $ha_stop_file
-    trap - $ha_stop_signals
-    ha_info "Waiting for workloads to stop"
-    wait
+       touch $ha_stop_file
+       # true because of lfsck_bg could be stopped already
+       $ha_lfsck_bg && wait $LFSCK_BG_PID || true
+       trap - $ha_stop_signals
+       ha_info "Waiting for workloads to stop"
+       wait
 }
 
 ha_wait_loads()
@@ -878,8 +948,6 @@ ha_main()
        ha_on ${ha_clients[0]} " \
                $LFS setstripe $ha_stripe_params $ha_test_dir"
 
-       $ha_lfsck_bg && ha_lfsck_bg
-
        ha_start_loads
        ha_wait_loads
 
@@ -896,9 +964,6 @@ ha_main()
 
        $ha_lfsck_fail_on_repaired && ha_lfsck_repaired
 
-       # true because of lfsck_bg could be stopped already
-       $ha_lfsck_bg && wait $LFSCK_BG_PID || true
-
        if [ -e "$ha_fail_file" ]; then
                exit 1
        else