2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
7 # ha.sh - test Lustre HA (aka failover) configurations
15 # ha.sh tests Lustre HA (aka failover) configurations with a CRM.
23 # Specify client nodes.
26 # Specify server nodes.
29 # Specify victim nodes to be rebooted.
32 # Choose a parent of the test directory. "/mnt/lustre" if not specified.
35 # Define a duration for the test. 86400 seconds if not specified.
38 # Define a max failover period. 10 minutes if not set.
41 # Only run the workloads; no failure will be introduced.
42 # -v, -s are ignored in this case.
44 # Workloads dry run for several seconds; no failures will be introduced.
45 # This option is useful to verify the loads.
46 # -u is ignored in this case
48 # Reboot victim nodes simultaneously.
53 # A Lustre file system is up and mounted on all client nodes. This script
54 # does not mount or unmount any Lustre targets or clients, let alone format
57 # Each target has a failnode, so that workloads can continue after a power
60 # CRM could be configured by 2 ways:
62 # Targets are automatically failed back when their primary node is back. This
63 # assumption avoids calling CRM-specific commands to trigger failbacks, making
64 # this script more CRM-neural.
66 # Targets are not automatically failed back when their primary node is back.
67 # CRM-specific command is executed to trigger failbacks.
69 # A crash dump mechanism is configured to catch LBUGs, panics, etc.
73 # Each client runs set of MPI and non-MPI workloads. These
74 # applications are run in short loops so that their exit status can be waited
75 # for and checked within reasonable time by ha_wait_loads.
76 # The set of MPI and non-MPI workloads are configurable by parameters:
78 # default set: dd, tar, iozone
80 # default set: ior, simul, mdtest
82 # The number of clients run MPI loads is configured by parameter
83 # ha_mpi_instances. Only one client runs MPI workloads by default.
85 # MPI workloads can be run from several users. The list of users to use is
86 # configured by parameter ha_mpi_users, default is "mpiuser".
88 # PROCESS STRUCTURE AND IPC
90 # On the node where this script is run, the processes look like this:
94 # ~ ha.sh (ha_repeat_mpi_load ior)
96 # ~ ha.sh (ha_repeat_mpi_load simul)
98 # ~ ha.sh (ha_repeat_mpi_load mdtest)
100 # ~ ... (one for each MPI load)
102 # ~ ha.sh (ha_repeat_nonmpi_load client2 dbench)
103 # ~ pdsh client2 dbench
104 # ~ ha.sh (ha_repeat_nonmpi_load client2 iozone)
105 # ~ pdsh client2 iozone
106 # ~ ha.sh (ha_repeat_nonmpi_load client5 iozone)
107 # ~ pdsh client5 iozone
108 # ~ ... (one for each non-MPI load on each client)
110 # Each tilde represents a process. Indentations imply parent-children
113 # IPC is done by files in the temporary directory.
118 SIMUL=${SIMUL:-$(which simul 2> /dev/null || true)}
119 IOR=${IOR:-$(which IOR 2> /dev/null || true)}
120 MDTEST=${MDTEST:-$(which mdtest 2> /dev/null || true)}
122 ior_blockSize=${ior_blockSize:-6g}
123 mpi_threads_per_client=${mpi_threads_per_client:-2}
125 iozone_SIZE=${iozone_SIZE:-262144} # 256m
127 mpirun=${MPIRUN:-$(which mpirun)}
128 LFS=${LFS:-$(which lfs)}
132 for ((load = 0; load < ${#ha_mpi_load_tags[@]}; load++)); do
133 local tag=${ha_mpi_load_tags[$load]}
134 local bin=$(echo $tag | tr '[:lower:]' '[:upper:]')
135 if [ x${!bin} = x ]; then
136 ha_error ha_mpi_loads: ${ha_mpi_loads}, $bin is not set
144 echo "$0: $(date +%H:%M:%S' '%s):" "$@"
149 local nodes=${1// /,}
151 ha_on $nodes "lctl mark $*"
163 ha_error "Trap ERR triggered by:"
164 ha_error " $BASH_COMMAND"
165 ha_error "Call trace:"
166 for ((i = 0; i < ${#FUNCNAME[@]}; i++)); do
167 ha_error " ${FUNCNAME[$i]} [${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}]"
174 declare ha_tmp_dir=/tmp/$(basename $0)-$$
175 declare ha_stop_file=$ha_tmp_dir/stop
176 declare ha_fail_file=$ha_tmp_dir/fail
177 declare ha_pm_states=$ha_tmp_dir/ha_pm_states
178 declare ha_status_file_prefix=$ha_tmp_dir/status
179 declare -a ha_status_files
180 declare ha_machine_file=$ha_tmp_dir/machine_file
181 declare ha_lfsck_log=$ha_tmp_dir/lfsck.log
182 declare ha_lfsck_lock=$ha_tmp_dir/lfsck.lock
183 declare ha_lfsck_stop=$ha_tmp_dir/lfsck.stop
184 declare ha_lfsck_bg=${LFSCK_BG:-false}
185 declare ha_lfsck_after=${LFSCK_AFTER:-false}
186 declare ha_lfsck_node=${LFSCK_NODE:-""}
187 declare ha_lfsck_device=${LFSCK_DEV:-""}
188 declare ha_lfsck_types=${LFSCK_TYPES:-"namespace layout"}
189 declare ha_lfsck_custom_params=${LFSCK_CUSTOM_PARAMS:-""}
190 declare ha_lfsck_wait=${LFSCK_WAIT:-1200}
191 declare ha_lfsck_fail_on_repaired=${LFSCK_FAIL_ON_REPAIRED:-false}
192 declare ha_power_down_cmd=${POWER_DOWN:-"pm -0"}
193 declare ha_power_up_cmd=${POWER_UP:-"pm -1"}
194 declare ha_power_delay=${POWER_DELAY:-60}
195 declare ha_node_up_delay=${NODE_UP_DELAY:-10}
196 declare ha_pm_host=${PM_HOST:-$(hostname)}
197 declare ha_failback_delay=${DELAY:-5}
198 declare ha_failback_cmd=${FAILBACK:-""}
199 declare ha_stripe_params=${STRIPEPARAMS:-"-c 0"}
200 declare ha_dir_stripe_count=${DSTRIPECOUNT:-"1"}
201 declare ha_mdt_index=${MDTINDEX:-"0"}
202 declare ha_mdt_index_random=${MDTINDEXRAND:-false}
203 declare -a ha_clients
204 declare -a ha_servers
205 declare -a ha_victims
206 declare -a ha_victims_pair
207 declare ha_test_dir=/mnt/lustre/$(basename $0)-$$
208 declare ha_start_time=$(date +%s)
209 declare ha_expected_duration=$((60 * 60 * 24))
210 declare ha_max_failover_period=10
211 declare ha_nr_loops=0
212 declare ha_stop_signals="SIGINT SIGTERM SIGHUP"
213 declare ha_load_timeout=${LOAD_TIMEOUT:-$((60 * 10))}
214 declare ha_workloads_only=false
215 declare ha_workloads_dry_run=false
216 declare ha_simultaneous=false
218 declare ha_mpi_instances=${ha_mpi_instances:-1}
220 declare ha_mpi_loads=${ha_mpi_loads="ior simul mdtest"}
221 declare -a ha_mpi_load_tags=($ha_mpi_loads)
222 declare -a ha_mpiusers=(${ha_mpi_users="mpiuser"})
224 declare -A ha_mpiopts
226 for ((i=0; i<${#ha_mpiusers[@]}; i++)); do
227 u=${ha_mpiusers[i]%%:*}
229 # user gets empty option if ha_mpi_users does not specify it explicitly
230 [[ ${ha_mpiusers[i]} =~ : ]] && o=${ha_mpiusers[i]##*:}
232 ha_mpiopts[$u]+=" $o"
234 ha_users=(${!ha_mpiopts[@]})
236 declare ha_ior_params=${IORP:-'" -b $ior_blockSize -t 2m -w -W -T 1"'}
237 declare ha_simul_params=${SIMULP:-'" -n 10"'}
238 declare ha_mdtest_params=${MDTESTP:-'" -i 1 -n 1000"'}
239 declare ha_mpirun_options=${MPIRUN_OPTIONS:-""}
240 declare ha_clients_stripe=${CLIENTSSTRIPE:-'"$STRIPEPARAMS"'}
241 declare ha_nclientsset=${NCLIENTSSET:-1}
242 declare ha_ninstmustfail=${NINSTMUSTFAIL:-0}
244 declare ha_racer_params=${RACERP:-"MDSCOUNT=1"}
246 eval ha_params_ior=($ha_ior_params)
247 eval ha_params_simul=($ha_simul_params)
248 eval ha_params_mdtest=($ha_mdtest_params)
249 eval ha_stripe_clients=($ha_clients_stripe)
251 declare ha_nparams_ior=${#ha_params_ior[@]}
252 declare ha_nparams_simul=${#ha_params_simul[@]}
253 declare ha_nparams_mdtest=${#ha_params_mdtest[@]}
254 declare ha_nstripe_clients=${#ha_stripe_clients[@]}
256 declare -A ha_mpi_load_cmds=(
257 [ior]="$IOR -o {}/f.ior {params}"
258 [simul]="$SIMUL {params} -d {}"
259 [mdtest]="$MDTEST {params} -d {}"
262 declare racer=${RACER:-"$(dirname $0)/racer/racer.sh"}
264 declare ha_nonmpi_loads=${ha_nonmpi_loads="dd tar iozone"}
265 declare -a ha_nonmpi_load_tags=($ha_nonmpi_loads)
266 declare -A ha_nonmpi_load_cmds=(
267 [dd]="dd if=/dev/zero of={}/f.dd bs=1M count=256"
268 [tar]="tar cf - /etc | tar xf - -C {}"
269 [iozone]="iozone -a -e -+d -s $iozone_SIZE {}/f.iozone"
270 [racer]="$ha_racer_params $racer {}"
275 ha_info "Usage: $0 -c HOST[,...] -s HOST[,...]" \
276 "-v HOST[,...] -f HOST[,...] [-d DIRECTORY] [-u SECONDS]"
279 ha_process_arguments()
283 while getopts hc:s:v:d:p:u:wrmf: opt; do
290 ha_clients=(${OPTARG//,/ })
293 ha_servers=(${OPTARG//,/ })
296 ha_victims=(${OPTARG//,/ })
299 ha_test_dir=$OPTARG/$(basename $0)-$$
302 ha_expected_duration=$OPTARG
305 ha_max_failover_period=$OPTARG
308 ha_workloads_only=true
311 ha_workloads_dry_run=true
317 ha_victims_pair=(${OPTARG//,/ })
326 if [ -z "${ha_clients[*]}" ]; then
327 ha_error "-c is mandatory"
331 if ! ($ha_workloads_dry_run ||
332 $ha_workloads_only) &&
333 ([ -z "${ha_servers[*]}" ] ||
334 [ -z "${ha_victims[*]}" ]); then
335 ha_error "-s, and -v are all mandatory"
349 # -S is to be used here to track the
350 # remote command return values
352 pdsh -S -w $nodes "PATH=/usr/local/sbin:/usr/local/bin:/sbin:\
353 /bin:/usr/sbin:/usr/bin; $@" ||
360 touch "$ha_stop_file"
362 if [ -e "$ha_fail_file" ]; then
363 ha_info "Test directory $ha_test_dir not removed"
364 ha_info "Temporary directory $ha_tmp_dir not removed"
366 ha_on ${ha_clients[0]} rm -rf "$ha_test_dir"
367 ha_info "Please find the results in the directory $ha_tmp_dir"
371 ha_trap_stop_signals()
373 ha_info "${ha_stop_signals// /,} received"
374 touch "$ha_stop_file"
381 ha_info "Sleeping for ${n}s"
383 # sleep(1) could interrupted.
392 while [ -e $lock ]; do
401 until mkdir "$lock" >/dev/null 2>&1; do
402 ha_sleep 1 >/dev/null
415 local nodes=${1// /,}
416 local file=/tmp/$(basename $0)-$$-$(date +%s).dk
417 local lock=$ha_tmp_dir/lock-dump-logs
421 ha_info "Dumping lctl log to $file"
424 # some nodes could crash, so
425 # do not exit with error if not all logs are dumped
427 ha_on $nodes "lctl dk >>$file" || rc=$?
430 ha_error "not all logs are dumped! Some nodes are unreachable."
441 local stripeparams=$6
444 local mpirunoptions=$9
445 local tag=${ha_mpi_load_tags[$load]}
446 local cmd=${ha_mpi_load_cmds[$tag]}
447 local dir=$ha_test_dir/$client-$tag
448 local log=$ha_tmp_dir/$client-$tag
451 local avg_loop_time=0
452 local start_time=$(date +%s)
454 cmd=${cmd//"{}"/$dir}
455 cmd=${cmd//"{params}"/$parameter}
457 [[ -n "$ha_postcmd" ]] && ha_postcmd=${ha_postcmd//"{}"/$dir}
458 [[ -n "$ha_precmd" ]] && ha_precmd=${ha_precmd//"{}"/$dir}
459 ha_info "Starting $tag"
461 machines="-machinefile $machines"
462 while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
463 ha_info "$client Starts: $mpiuser: $cmd" 2>&1 | tee -a $log
466 if $ha_mdt_index_random && [ $ha_mdt_index -ne 0 ]; then
467 mdt_index=$(ha_rand $ha_mdt_index)
469 mdt_index=$ha_mdt_index
471 [[ -n "$ha_precmd" ]] && ha_info "$ha_precmd" &&
472 ha_on $client "$ha_precmd" >>"$log" 2>&1
473 ha_on $client $LFS mkdir -i$mdt_index -c$ha_dir_stripe_count "$dir" &&
474 ha_on $client $LFS getdirstripe "$dir" &&
475 ha_on $client $LFS setstripe $stripeparams $dir &&
476 ha_on $client $LFS getstripe $dir &&
477 ha_on $client chmod a+xwr $dir &&
478 ha_on $client "su $mpiuser sh -c \" $mpirun $mpirunoptions \
479 -np $((${#ha_clients[@]} * mpi_threads_per_client )) \
480 $machines $cmd \" " || rc=$?
481 [[ -n "$ha_postcmd" ]] && ha_info "$ha_postcmd" &&
482 ha_on $client "$ha_postcmd" >>"$log" 2>&1
483 (( ((rc == 0)) && (( mustpass != 0 )) )) ||
484 (( ((rc != 0)) && (( mustpass == 0 )) )) &&
485 ha_on $client rm -rf "$dir";
486 } >>"$log" 2>&1 || rc=$?
488 ha_info $client: rc=$rc mustpass=$mustpass
490 # mustpass=0 means that failure is expected
491 if (( rc !=0 )); then
492 if (( mustpass != 0 )); then
493 touch "$ha_fail_file"
494 touch "$ha_stop_file"
495 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
500 elif (( mustpass == 0 )); then
501 touch "$ha_fail_file"
502 touch "$ha_stop_file"
503 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
505 echo rc=$rc mustpass=$mustpass >"$status"
507 nr_loops=$((nr_loops + 1))
510 [ $nr_loops -ne 0 ] &&
511 avg_loop_time=$((($(date +%s) - start_time) / nr_loops))
513 ha_info "$tag stopped: rc=$rc mustpass=$mustpass \
514 avg loop time $avg_loop_time"
531 # ha_mpi_instances defines the number of
532 # clients start mpi loads; should be <= ${#ha_clients[@]}
534 # ha_mpi_instances = 0
536 # ${#ha_mpi_load_tags[@]} =0
537 local inst=$ha_mpi_instances
538 (( inst == 0 )) || (( ${#ha_mpi_load_tags[@]} == 0 )) &&
539 ha_info "no mpi load to start" &&
542 (( inst <= ${#ha_clients[@]} )) || inst=${#ha_clients[@]}
544 # Define names for machinefiles for each client set
545 for (( n=0; n < $ha_nclientsset; n++ )); do
546 mach[$n]=$ha_machine_file$n
549 for ((n = 0; n < ${#ha_clients[@]}; n++)); do
550 m=$(( n % ha_nclientsset))
552 ha_info machine_file=$machines
553 echo ${ha_clients[n]} >> $machines
555 local dirname=$(dirname $ha_machine_file)
556 for client in ${ha_clients[@]}; do
557 ha_on $client mkdir -p $dirname
558 scp $ha_machine_file* $client:$dirname
561 for ((n = 0; n < $inst; n++)); do
562 client=${ha_clients[n]}
563 nmpi=$((n % ${#ha_users[@]}))
564 mpiuser=${ha_users[nmpi]}
565 for ((load = 0; load < ${#ha_mpi_load_tags[@]}; load++)); do
566 tag=${ha_mpi_load_tags[$load]}
567 status=$ha_status_file_prefix-$tag-$client
570 local num=ha_nparams_$tag
572 local aref=ha_params_$tag[nparam]
573 local parameter=${!aref}
574 local nstripe=$((n % ha_nstripe_clients))
575 aref=ha_stripe_clients[nstripe]
576 local stripe=${!aref}
577 local m=$(( n % ha_nclientsset))
580 [[ $ha_ninstmustfail == 0 ]] ||
581 mustpass=$(( n % ha_ninstmustfail ))
582 ha_repeat_mpi_load $client $load $status "$parameter" \
583 $machines "$stripe" "$mpiuser" "$mustpass" \
584 "${ha_mpiopts[$mpiuser]} $ha_mpirun_options" &
585 ha_status_files+=("$status")
590 ha_repeat_nonmpi_load()
595 local tag=${ha_nonmpi_load_tags[$load]}
596 local cmd=${ha_nonmpi_load_cmds[$tag]}
597 local dir=$ha_test_dir/$client-$tag
598 local log=$ha_tmp_dir/$client-$tag
601 local avg_loop_time=0
602 local start_time=$(date +%s)
604 cmd=${cmd//"{}"/$dir}
606 ha_info "Starting $tag on $client"
608 while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
609 ha_info "$client Starts: $cmd" 2>&1 | tee -a $log
610 ha_on $client "mkdir -p $dir && \
612 rm -rf $dir" >>"$log" 2>&1 || rc=$?
615 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
616 touch "$ha_fail_file"
617 touch "$ha_stop_file"
621 nr_loops=$((nr_loops + 1))
624 [ $nr_loops -ne 0 ] &&
625 avg_loop_time=$((($(date +%s) - start_time) / nr_loops))
627 ha_info "$tag on $client stopped: rc $rc avg loop time ${avg_loop_time}s"
630 ha_start_nonmpi_loads()
637 for client in ${ha_clients[@]}; do
638 for ((load = 0; load < ${#ha_nonmpi_load_tags[@]}; load++)); do
639 tag=${ha_nonmpi_load_tags[$load]}
640 status=$ha_status_file_prefix-$tag-$client
641 ha_repeat_nonmpi_load $client $load $status &
642 ha_status_files+=("$status")
653 [ -f $ha_lfsck_stop ] && ha_info "LFSCK stopped" && break
654 [ -f $ha_stop_file ] &&
655 ha_info "$ha_stop_file found! LFSCK not started" &&
657 ha_start_lfsck 2>&1 | tee -a $ha_lfsck_log
661 ha_info LFSCK BG PID: $LFSCK_BG_PID
664 ha_wait_lfsck_completed () {
666 local -a types=($ha_lfsck_types)
670 local nodes="${ha_servers[@]}"
673 # -A start LFSCK on all nodes
675 [ ${#types[@]} -eq 0 ] && types=(namespace layout)
676 ha_info "Waiting LFSCK completed in $ha_lfsck_wait sec: types ${types[@]}"
677 for type in ${types[@]}; do
679 for (( i=0; i<=ha_lfsck_wait; i++)); do
680 status=($(ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null | \
681 awk '/status/ { print $3 }'))
682 for (( s=0; s<${#status[@]}; s++ )); do
683 # "partial" is expected after HARD failover
684 [[ "${status[s]}" = "completed" ]] ||
685 [[ "${status[s]}" = "partial" ]] || break
687 [[ $s -eq ${#status[@]} ]] && eval var_$type=1 && break
690 ha_info "LFSCK $type status in $i sec:"
691 ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null | grep status
695 for type in ${types[@]}; do
697 ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null
698 [[ ${!var} -eq 1 ]] ||
699 { ha_info "lfsck not completed in $ha_lfsck_wait sec";
707 local -a types=($ha_lfsck_types)
710 # -A: start LFSCK on all nodes via the specified MDT device
711 # (see "-M" option) by single LFSCK command
712 local params=" -A -r $ha_lfsck_custom_params"
714 # use specified device if set
715 [ -n "$ha_lfsck_device" ] && params="-M $ha_lfsck_device $params"
717 # -t: check type(s) to be performed (default all)
718 # check only specified types if set
719 if [ ${#types[@]} -ne 0 ]; then
720 local type="${types[@]}"
721 params="$params -t ${type// /,}"
724 ha_info "LFSCK start $params"
725 ha_on $ha_lfsck_node "lctl lfsck_start $params" || rc=1
726 if [ $rc -ne 0 ]; then
727 if [ -e $ha_lfsck_lock ]; then
729 ha_wait_unlock $ha_lfsck_lock
731 ha_on $ha_lfsck_node "lctl lfsck_start $params" || rc=1
736 { touch "$ha_fail_file"; touch "$ha_stop_file";
737 touch $ha_lfsck_stop; return 1; }
739 ha_wait_lfsck_completed ||
740 { touch "$ha_fail_file"; touch "$ha_stop_file";
741 touch $ha_lfsck_stop; return 1; }
750 n=$(cat $ha_lfsck_log | awk '/repaired/ {print $3}' |\
751 awk '{sum += $1} END { print sum }')
753 { ha_info "Total repaired: $n";
754 touch "$ha_fail_file"; return 1; }
760 $ha_lfsck_bg && ha_lfsck_bg
761 trap ha_trap_stop_signals $ha_stop_signals
762 ha_start_nonmpi_loads
769 # true because of lfsck_bg could be stopped already
770 $ha_lfsck_bg && wait $LFSCK_BG_PID || true
771 trap - $ha_stop_signals
772 ha_info "Waiting for workloads to stop"
779 local end=$(($(date +%s) + ha_load_timeout))
781 ha_info "Waiting $ha_load_timeout sec for workload status..."
782 rm -f "${ha_status_files[@]}"
785 # return immediately if ha_stop_file exists,
786 # all status_files not needed to be checked
788 for file in "${ha_status_files[@]}"; do
789 if [ -e "$ha_stop_file" ]; then
790 ha_info "$ha_stop_file found! Stop."
794 # Wait status file created during ha_load_timeout.
795 # Existing file guarantees that some application
796 # is completed. If no status file was created
797 # this function guarantees that we allow
798 # applications to continue after/before
799 # failover/failback during ha_load_timeout time.
801 until [ -e "$file" ] || (($(date +%s) >= end)); do
803 # check ha_stop_file again, it could appear
804 # during ha_load_timeout
806 if [ -e "$ha_stop_file" ]; then
807 ha_info "$ha_stop_file found! Stop."
810 ha_sleep 1 >/dev/null
818 local expected_state=$2
824 # store pm -x -q $nodes results in a file to have
825 # more information about nodes statuses
826 ha_on $ha_pm_host pm -x -q $nodes | awk '{print $2 $3}' > $ha_pm_states
830 while IFS=": " read node state; do
831 [[ "$state" = "$expected_state" ]] && {
832 nodes=${nodes/$node/}
839 if [ -n "$nodes" ]; then
846 ha_power_down_cmd_fn()
851 case $ha_power_down_cmd in
852 # format is: POWER_DOWN=sysrqcrash
853 sysrqcrash) cmd="pdsh -S -w $nodes 'echo c > /proc/sysrq-trigger' &" ;;
854 *) cmd="$ha_power_down_cmd $nodes" ;;
867 case $ha_power_down_cmd in
869 sysrqcrash) state=off ;;
873 if $ha_lfsck_bg && [[ ${nodes//,/ /} =~ $ha_lfsck_node ]]; then
874 ha_info "$ha_lfsck_node down, delay start LFSCK"
875 ha_lock $ha_lfsck_lock
878 ha_info "Powering down $nodes : cmd: $ha_power_down_cmd"
879 for (( i=0; i<10; i++ )) {
880 ha_info "attempt: $i"
881 ha_power_down_cmd_fn $nodes &&
882 ha_powermanage $nodes $state && rc=0 && break
883 sleep $ha_power_delay
887 ha_info "Failed Powering down in $i attempts:" \
899 for ((i=0; i<${#ha_victims[@]}; i++)) {
900 [[ ${ha_victims[i]} == $node ]] && echo ${ha_victims_pair[i]} &&
903 [[ $i -ne ${#ha_victims[@]} ]] ||
904 ha_error "No pair found!"
910 local end=$(($(date +%s) + ha_node_up_delay))
913 if [[ ${#ha_victims_pair[@]} -eq 0 ]]; then
914 ha_sleep $ha_node_up_delay
918 # Check CRM status on failover pair
919 while (($(date +%s) <= end)); do
921 for n in ${nodes//,/ }; do
922 local pair=$(ha_get_pair $n)
923 local status=$(ha_on $pair crm_mon -1rQ | \
924 grep -w $n | head -1)
926 ha_info "$n pair: $pair status: $status"
927 [[ "$status" == *OFFLINE* ]] ||
932 if [[ $rc -eq 0 ]]; then
933 ha_info "CRM: Got all victims status OFFLINE"
939 ha_info "$nodes CRM status not OFFLINE"
940 for n in ${nodes//,/ }; do
941 local pair=$(ha_get_pair $n)
944 ha_on $pair crm_mon -1rQ
946 ha_error "CRM: some of $nodes are not OFFLINE in $ha_node_up_delay sec"
956 ha_power_up_delay $nodes
957 ha_info "Powering up $nodes : cmd: $ha_power_up_cmd"
958 for (( i=0; i<10; i++ )) {
959 ha_info "attempt: $i"
960 $ha_power_up_cmd $nodes &&
961 ha_powermanage $nodes on && rc=0 && break
962 sleep $ha_power_delay
966 ha_info "Failed Powering up in $i attempts: $ha_power_up_cmd"
975 # Print a random integer within [0, MAX).
982 # See "5.2 Bash Variables" from "info bash".
984 echo -n $((RANDOM * max / 32768))
992 if $ha_simultaneous ; then
993 nodes=$(echo ${ha_victims[@]})
996 i=$(ha_rand ${#ha_victims[@]})
997 nodes=${ha_victims[$i]}
1006 local end=$(($(date +%s) + 10 * 60))
1008 ha_info "Waiting for $nodes to boot up"
1009 until ha_on $nodes hostname >/dev/null 2>&1 ||
1010 [ -e "$ha_stop_file" ] ||
1011 (($(date +%s) >= end)); do
1012 ha_sleep 1 >/dev/null
1019 ha_info "Failback resources on $nodes in $ha_failback_delay sec"
1021 ha_sleep $ha_failback_delay
1022 [ "$ha_failback_cmd" ] ||
1024 ha_info "No failback command set, skiping"
1028 $ha_failback_cmd $nodes
1029 [ -e $ha_lfsck_lock ] && ha_unlock $ha_lfsck_lock || true
1034 ha_info "---------------8<---------------"
1036 ha_info " Duration: $(($(date +%s) - $ha_start_time))s"
1037 ha_info " Loops: $ha_nr_loops"
1044 while (($(date +%s) < ha_start_time + ha_expected_duration)) &&
1045 [ ! -e "$ha_stop_file" ]; do
1046 ha_info "---------------8<---------------"
1048 $ha_workloads_only || nodes=$(ha_aim)
1050 ha_info "Failing $nodes"
1051 $ha_workloads_only && ha_info " is skipped: workload only..."
1053 ha_sleep $(ha_rand $ha_max_failover_period)
1054 $ha_workloads_only || ha_power_down $nodes
1056 ha_wait_loads || return
1058 if [ -e $ha_stop_file ]; then
1059 $ha_workloads_only || ha_power_up $nodes
1063 ha_info "Bringing $nodes back"
1064 ha_sleep $(ha_rand 10)
1065 $ha_workloads_only ||
1068 ha_wait_nodes $nodes
1073 # Wait for the failback to start.
1076 ha_wait_loads || return
1078 ha_sleep $(ha_rand 20)
1080 ha_nr_loops=$((ha_nr_loops + 1))
1081 ha_info "Loop $ha_nr_loops done"
1088 ha_process_arguments "$@"
1091 ha_log "${ha_clients[*]} ${ha_servers[*]}" \
1092 "START: $0: $(date +%H:%M:%S' '%s)"
1093 trap ha_trap_exit EXIT
1095 ha_on ${ha_clients[0]} mkdir "$ha_test_dir"
1096 ha_on ${ha_clients[0]} " \
1097 $LFS setstripe $ha_stripe_params $ha_test_dir"
1102 if $ha_workloads_dry_run; then
1106 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
1111 $ha_lfsck_after && ha_start_lfsck | tee -a $ha_lfsck_log
1113 $ha_lfsck_fail_on_repaired && ha_lfsck_repaired
1115 if [ -e "$ha_fail_file" ]; then
1118 ha_log "${ha_clients[*]} ${ha_servers[*]}" \
1119 "END: $0: $(date +%H:%M:%S' '%s)"