#!/bin/bash shopt -s expand_aliases source stressDiagListCommon # include fwdCmd setting source /usr/local/share/diag_env duration=60 soe=true dv=true helpRun=' Syntax: stressDiagListRun "" "" "" "": Run time for all Diagnostic Stress tests "": YES = Stop on Error, NO = No Stop on Error "": YES = Data Validation, NO = No Data Validation Usage: The command wll execute the currently defined list of Diagnostic Stress test items. The global parameters must be provided. The "YES/NO" must be upper case. If the incorrect number of Diag Parameters is entered the command will output a list of required Diag paramertes. Note: Test time must be at least 300 seconds for CPU or memory stress. Test time must be at least 600 seconds for CX5 related stress. Test time must be at least 240 seconds for FC stress.' durationNote=' Incorrect duration setting: Test time must be at least 300 seconds for CPU or memory stress. Test time must be at least 600 seconds for CX5 related stress. Test time must be at least 240 seconds for FC stress.' checkRunParameter() { if [[ "$1" =~ ^[0-9]+$ ]]; then duration=$1 else echo "FAILED - TEST TIME MUST BE INTEGER" printf "%s\n" "$helpRun" exit fi notCpuMemory=0 while read index cmd do if [ $index -ne 07 ] && [ $index -ne 08 ];then notCpuMemory=1 fi done < $stressCmdListTemp while read index cmd do if [ $index -eq 07 ]|| [ $index -eq 08 ];then if [ $duration -lt 300 ] && [ "$notCpuMemory" == "1" ];then printf "%s\n" "$durationNote" exit fi fi if [ $index -eq 02 ]|| [ $index -eq 03 ] || [ $index -eq 04 ];then if [ $duration -lt 240 ];then printf "%s\n" "$durationNote" exit fi fi done < $stressCmdListTemp if [[ "$2" == "YES" ]]; then soe=true elif [[ "$2" == "NO" ]]; then soe=false else echo 'FAIL - STOP ON ERROR, "YES" or "NO"' printf "%s\n" "$helpRun" exit fi if [[ "$3" == "YES" ]]; then dv=true elif [[ "$3" == "NO" ]]; then dv=false else echo 'FAILED - DATA VALIDATATION, "YES" or "NO"' printf "%s\n" "$helpRun" exit fi } scanAndCombine() { # check output file, if not exist, report fail if [[ ! -r $stressCmdListTemp ]]; then echo "FAILED - LIST NOT EXIST" exit fi # special case: if "CNA base" and "CNA HIC" be added, combine them. # special case: if "SAS Local" and "SAS Remote" be added, combine them. # check if both added qlchipStressCount=0 qlchipStressIndex=0 qlchipStressParm1="" qlchipStressParm2="" sasStressCount=0 sasStressIndex=0 sasStressParm1="" sasStressParm2="" sasStressParm3="" sasStressParm4="" sasStressParm5="" sasStressParm10="" sasStressParm11="" while read index scriptName parm1 parm2 parm3 parm4 parm5 parm6 parm7 parm8 parm9 parm10 parm11 do # CNA base if [[ "$index" == "01" || "$index" == "02" ]]; then let "qlchipStressCount = $qlchipStressCount + 1" let "qlchipStressIndex = $index" qlchipStressParm1="$parm1" qlchipStressParm2="$parm2" fi # SAS Local if [[ "$index" == "04" ]]; then sasStressLocal=true let "sasStressCount = $sasStressCount + 1" let "sasStressIndex = $index" sasStressParm1="$parm1" sasStressParm2="$parm2" sasStressParm3="$parm3" sasStressParm4="$parm4" sasStressParm5="$parm5" sasStressParm10="$parm10" sasStressParm11="$parm11" fi # SAS Remote if [[ "$index" == "05" ]]; then sasStressRemote=true let "sasStressCount = $sasStressCount + 1" let "sasStressIndex = $index" sasStressParm1="$parm1" sasStressParm2="$parm2" sasStressParm3="$parm3" sasStressParm4="$parm4" sasStressParm5="$parm5" sasStressParm10="$parm10" sasStressParm11="$parm11" fi # SAS Expansion if [[ "$index" == "06" ]]; then sasStressExpansion=true let "sasStressCount = $sasStressCount + 1" let "sasStressIndex = $index" sasStressParm1="$parm1" sasStressParm2="$parm2" sasStressParm3="$parm3" sasStressParm4="$parm4" sasStressParm5="$parm5" sasStressParm10="$parm10" sasStressParm11="$parm11" fi done < $stressCmdListTemp # if both added, combine them if [[ $qlchipStressCount -eq 2 || $sasStressCount -eq 2 ]]; then cp $stressCmdListTemp $stressCmdListTemp.orig # CNA if [[ $qlchipStressCount -eq 2 ]]; then subtractList "01" subtractList "02" index=$(printf "%02d" "$qlchipStressIndex") add2list "$index" $qlchipStressParm1 0 fi # SAS if [[ $sasStressCount -eq 2 ]]; then if [[ "$sasStressLocal" == "true" && "$sasStressRemote" == "true" ]]; then subtractList "04" subtractList "05" index=$(printf "%02d" "$sasStressIndex") add2list "05" $sasStressParm1 $sasStressParm2 $sasStressParm3 $sasStressParm4 $sasStressParm5 1 1 0 0 $sasStressParm10 $sasStressParm11 fi if [[ "$sasStressLocal" == "true" && "$sasStressExpansion" == "true" ]]; then subtractList "04" subtractList "06" index=$(printf "%02d" "$sasStressIndex") add2list "06" $sasStressParm1 $sasStressParm2 $sasStressParm3 $sasStressParm4 $sasStressParm5 1 0 1 0 $sasStressParm10 $sasStressParm11 fi fi fi } genList() { # gen command list echo "#!/bin/bash" > $stressCmdList echo >> $stressCmdList notCpuMemory=0 # read file, while read index cmd do title=item${index}_title if [ "$index" == "07" ];then run_delay=1 stressCmd_cpu=$(printf "%s&" "$cmd") elif [ "$index" == "08" ];then run_delay=1 stressCmd_mem=$(printf "%s&" "$cmd") else notCpuMemory=1 stressCmd=$(printf "%s&" "$cmd") echo "$stressCmd" >> $stressCmdList fi done < $stressCmdListTemp if [ "$run_delay" == "1" ];then if [ "$notCpuMemory" == "1" ];then echo "echo \"Wait 3 minutes before running cpu and/or memory stress...\"" >> $stressCmdList echo "echo \"Stress will run at least 3 minutes even if touch /tmp/stop_flag\"" >> $stressCmdList echo "sleep 180" >> $stressCmdList echo "echo \"start to run cpu and/or memory stress...\"" >> $stressCmdList fi if [ -n "$stressCmd_cpu" ];then echo "$stressCmd_cpu" >> $stressCmdList fi if [ -n "$stressCmd_mem" ];then echo "$stressCmd_mem" >> $stressCmdList fi fi if [[ -e "$stressCmdListTemp.orig" ]]; then mv "$stressCmdListTemp.orig" $stressCmdListTemp fi } setDuration() { # TODO write a script "stressDiagListDumpError" that dump all Error log duration "$1" "touch $durationFlag" "sleep 15; stressDiagListDumpError; touch $completeFlag 2>/dev/null"& if [[ "$Simplex" == "false" ]]; then fwdCmd "duration \"$1\" \"touch $durationFlag\" \"sleep 15; stressDiagListDumpError; touch $completeFlag 2>/dev/null\""& fi } setSoe() { touch $soeFlag if [[ "$Simplex" == "false" ]]; then fwdCmd "touch $soeFlag" fi } cleanFlag() { rm -rf $durationFlag rm -rf $stopFlag rm -rf $soeFlag rm -rf $completeFlag if [[ "$Simplex" == "false" ]]; then fwdCmd "rm -rf $durationFlag" fwdCmd "rm -rf $stopFlag" fwdCmd "rm -rf $soeFlag" fwdCmd "rm -rf $completeFlag" fi } cleanLog() { rm -rf /tmp/*StressStopOnError.log 2>/dev/null rm -rf /tmp/*stress.log 2> /dev/null if [[ "$Simplex" == "false" ]]; then fwdCmd "rm -rf /tmp/*StressStopOnError.log 2>/dev/null" fwdCmd "rm -rf /tmp/*stress.log 2> /dev/null" fi } # If one's Simplex set to dual, the set Simplex=false scanSimplex() { while read index scriptName parm1 parm2 parm3 parm4 parm5 parm6 parm7 parm8 parm9 parm10 parm11 do #echo "$index $scriptName $parm1 $parm2 $parm3 $parm4 $parm5 $parm6 $parm7 $parm8 $parm9" case "$index" in "01") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "02") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "03") if [[ "$parm2" == "0" ]]; then Simplex=false; fi ;; "04") if [[ "$parm9" == "0" ]]; then Simplex=false; fi ;; "05") if [[ "$parm9" == "0" ]]; then Simplex=false; fi ;; "06") if [[ "$parm9" == "0" ]]; then Simplex=false; fi ;; "07") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "08") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "09") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "10") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "11") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "12") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "13") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "14") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "15") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "16") if [[ "$parm6" == "0" ]]; then Simplex=false; fi ;; "17") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "18") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "19") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "22") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; "23") if [[ "$parm1" == "0" ]]; then Simplex=false; fi ;; esac done < $stressCmdListTemp } run_delay=0 Simplex=true if [[ $# -lt 3 ]]; then printf "%s\n" "$helpRun" else checkRunParameter $@ #scanAndCombine $dv genList $dv scanSimplex cleanFlag cleanLog # setup duration timer setDuration $duration # setup soe flag if [[ $soe == true ]]; then setSoe fi stressStartTime=$(date +%Y/%m/%d\ %T) echo "$stressStartTime"> /tmp/stressStartTime # run chmod a+x $stressCmdList $stressCmdList while [[ 1 ]]; do # if complete, echo for prompt then quit if [ -f $completeFlag ]; then echo "" break; fi # if SOE, dump error log then quit if [[ -f $stopFlag ]]; then killall duration sleep 15; stressDiagListDumpError if [[ "$Simplex" == "false" ]]; then fwdCmd "killall duration"& fwdCmd "touch /tmp/stop_flag"& fwdCmd "sleep 15; stressDiagListDumpError"& fi break; fi sleep 1 done fi