#!/bin/sh
#
#
#    Copyright (c) 1996-2016 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   systemVerification
#    Module name: diag/scripts
#
#    This file performs burnin on all active switch blades.
#
# NAME
#    systemverification - Supports these activities
#    1. Set burnin mode on all active switch blades
#    2. Allows parameter editing for burnin
#
# SYNOPSIS
#    systemverification [ -parameters | -short | -fru type -unit number | -stop ]
#
# AVAILABILITY
#    swt_mfg
#
# DESCRIPTION
#    This command will manage the burnin activity. It contains and
#    manages the parameters needed this activity. It also contains
#    the list of activities to perform during a single burnin run. 
#    It has the processing loop to execute the commands in the list.
#
#    The mode becomes active as soon as this command is executed.
#    It does not require a reboot to take effect.
#
# OPERANDS
#
#    "parameters"      This operand will trigger activity related to 
#                      editing the avialable parameters active during
#                      the burnin activity. The user will be prompted 
#                      to modify each parameter in the order specified 
#                      in the this script. The current value, default 
#                      value, and description of the parameter are 
#                      displayed. If the user does not want to modify 
#                      the value, then a <cr> is recognized as 
#                      "hold current value". Any other value for this
#                      parameter is ignored.
#
#   "short"            This parameter is passed to the diagsetcycle and
#                      uses the configuration associated with short 
#                      testing. The short testing is intended to validate
#                      SW by running all commands with the minimal
#                      amount of loops. The definition of short is in the
#                      per product test lists.
#
#   "fru type"         Identifies a single FRU to focus the testing on.
#                      Choices will include "BLADE, PS, FAN, WWN, PIC".
#                      Only BLADE is supported at this time, and this
#                      parameter is optional.
#
#   "unit id           This is which instance of the fru type to test.
#                      This is the slot number 1-N for BLADES, PS, and
#                      FANS. It is always relative to the first instance
#                      of the same type fru. For PIC fru types this wold be
#                      slot/[ab], or [ab] for non blades systems.
#
#   "stop"             This parameter is used to stop the testing activity. 
#                      It invokes diagstopburnin script to kill the test process
#                      and clears the burnin configuration.
#

# Check RBAC permission on command
/fabos/libexec/rbac_check `/bin/basename $0`

if [ $? -ne 0 ]; then
	exit 127
fi

#set ROLE to root pass remaining RBAC checks. Don't do it before rbac_check
export ROLE_ID=root

##################################
# Signal handler part of script
##################################
systemverification_cleanup()
{
    /bin/echo "systemverification: Stopping activity. This may take a while"
    if [ "$unit_number" != -1 ]
    then
	/fabos/libexec/diagstopburnin -local -slot $unit_number
    else
	/fabos/libexec/diagstopburnin -local
    fi
    /bin/echo "systemverification: Stopped activity."
    /bin/echo "systemverification: Outputting Status"
    if [ "$unit_number" != -1 ]
    then
	/fabos/sbin/burninstatus -slot $unit_number
    else
	/fabos/sbin/burninstatus
    fi

    ################################
    # Reboot the switch
    ################################
    #
    # Reboot switch to initialize FCIP/FCoE ports on Spike/Striker/Elara.
    # This additional step is only required for Newton/Discovery release builds.
    #
    all_slots=""
    if [ "$_reboot_sw" = 1 ]; then
      if [ "$unit_number" = -1 ]
      then
        all_slots="`getAvailSlots -chassis`"
        for f in $all_slots ; do
          _bladeID=`getBladeID $f`
       if { [ "$_bladeID" = "SPIKE" ] || [ "$_bladeID" = "SKYBOLT" ]; }
          then
             /bin/sleep 1
             /bin/echo ""
             /bin/echo "Diagnostics will now reboot the switch ....."
             /bin/sleep 2
             /fabos/link_bin/sync
             /usr/bin/reboot
          elif [ "$_bladeID" = "STRIKER" ];
          then
             /bin/sleep 1
             /bin/echo ""
             /bin/echo "Diagnostics will now power cycle slot $f ....."
             /fabos/sbin/slotpoweroff $f
             /bin/sleep 2
             /fabos/sbin/slotpoweron $f
             /bin/sleep 4
          else
             do_sw_quiescent $f FALSE
          fi
        done
      else
	 _bladeID=`getBladeID $unit_number`
      if { [ "$_bladeID" = "SPIKE" ] || [ "$_bladeID" = "SKYBOLT" ]; }
         then
            /bin/sleep 1
            /bin/echo ""
            /bin/echo "Diagnostics will now reboot the switch ....."
            /bin/sleep 2
            /fabos/link_bin/sync
            /usr/bin/reboot
         elif [ "$_bladeID" = "STRIKER" ];
         then
            /bin/sleep 1
            /bin/echo ""
            /bin/echo "Diagnostics will now power cycle slot $unit_number ....."
    	    /fabos/sbin/slotpoweroff $unit_number
            /bin/sleep 2
    	    /fabos/sbin/slotpoweron $unit_number
            /bin/sleep 4
         else
            do_sw_quiescent $unit_number FALSE            
        fi
      fi
    fi
    exit
}


##################################
# Procedure to Print messages for blades 
#################################
print_blade_type()
{

 /bin/echo ""
 /bin/echo "On Slot $_blade_slot_num a Brocade $_blade_name was detected."

}

##################################
# Procedure to Print messages for boxes
#################################
print_box_type()
{

 /bin/echo ""
 /bin/echo "A Brocade $_blade_name was detected."

}

##################################
# Procedure to Print messages for blades 
#################################
print_blade_reboot()
{
 /bin/echo "--- WARNING ---" 
  /bin/echo "If you want to continue, once testing is complete,"
  /bin/echo "above detected blade[s] will be power cycled."
  /bin/echo "Do you want to continue? [y/n]:"
}

##################################
# Procedure to Print messages for boxes
#################################
print_box_reboot()
{
 /bin/echo "--- WARNING ---" 
  /bin/echo "If you want to continue, once testing is complete,"
  /bin/echo "above detected switch will be power cycled."
  /bin/echo "Do you want to continue? [y/n]:"
}

###############################
# get input from user for reboot
##################################
get_reboot_confirm()
{
  _reboot_sw=0
  while read _line; do
	if [ $_line ]; then
		if [ $_line = "y" -o $_line = "Y" ]; then
			_reboot_sw=1
			break
		elif [ $_line = "n" -o $_line = "N" ]; then
			_reboot_sw=0
			/bin/echo "Quiting systemVerification ..."
			/bin/echo "Note that you can test other blades in a chassis"
			/bin/echo "by using systemverification -unit [slot number]"
			exit 0
		else
		     	/bin/echo "Do you want to continue to run? [y/n]:"
		fi
	fi
 done
}

##################################
# For Elara and Europa we need to 
# make sure chassisdisable executed 
# before systemverification
##################################

check_bladedisable()
{
 if [ "`/fabos/factory/cmsh_debug --eval "show ip in br" | /bin/grep TenGigabitEthernet | /bin/grep  $_blade_slot_num/ | /bin/grep up`" != "" ]
 then
   /bin/echo "systemverification: Can not proceed systemverification on slot $_blade_slot_num a Brocade $_blade_name is Online."
   /bin/echo "systemverification: Please use bladedisable to take the blade offline or chassisdisable to take switch offline."
   /bin/echo "`/fabos/factory/cmsh_debug --eval "show ip in br" | /bin/grep TenGigabitEthernet | /bin/grep  $_blade_slot_num/ | /bin/grep up`"

   exit 1
 fi
}

##################################
# Procedure to check the requirement of
# reboot after the SV.
##################################
chk_reboot_req()
{
  all_slots=""
  _blade_name=0
  _striker_present=0
  _blade_slot_num=0

  all_slots="`getAvailSlots -chassisnofault`"
  if [ "$unit_number" = -1 ]
  then
     for f in $all_slots ; do 
      _bladeID=`getBladeID $f`
      if [ "$_bladeID" = "SPIKE" ]
      then
	_blade_name="7800"
	print_box_type
	print_box_reboot
	get_reboot_confirm
      elif [ "$_bladeID" = "SKYBOLT" ]
      then
    case `getSWBD` in 
    "SWBD148" )
	_blade_name="7840" ;;
    "SWBD171" )
    _blade_name="AMP" ;;
    esac
	print_box_type
	print_box_reboot
	get_reboot_confirm
      elif [ "$_bladeID" = "STRIKER" ]
      then
	 _blade_slot_num=$f
	 _striker_present=1
	 _blade_name="FX8-24"
	 print_blade_type
      fi
   done 
	
  else 
    _bladeID=`getBladeID $unit_number`
    _blade_slot_num=$unit_number
    if [ "$_bladeID" = "SPIKE" ]
      then
	_blade_name="7800"
      	print_box_type
	print_box_reboot
	get_reboot_confirm
    elif [ "$_bladeID" = "SKYBOLT" ]
    then
    case `getSWBD` in 
    "SWBD148" )
	 _blade_name="7840" ;;
    "SWBD171" )
     _blade_name="AMP" ;;
    esac
     print_box_type
     print_box_reboot
     get_reboot_confirm
	elif [ "$_bladeID" = "STRIKER" ];
      then
	_blade_name="FX8-24"
	 _striker_present=1
	print_blade_type
    fi 
  fi
  if [ "$_striker_present" = 1 ];
  then
     print_blade_reboot
     get_reboot_confirm
  fi
}

##################################
# Main body of script
# DIAGSETCYCLE_CAPABLE
##################################
# Load common functions
# Should be first to ensure the library 
# functions are available for use
##################################
home="/fabos/share"
util="diagcommon.sh"
ok=0
for f in "./$util" "$FABOSHOME/share/$util" "$home/$util" ; do
	if [ -r $f ] ; then
		. $f
		ok=1
		break;
	fi
done
if [ $ok -ne 1 ] ; then
	err "Could not locate $util"
	exit 3
fi
################################
# get sys info for multi blade
################################
multiBlade=`isMultiBlade`
export syntax="systemverification [ -parameters | -short | -stop ] [ -unit id ]"

################################
# get list of available scripts
################################
FileName=common_test_list
util=$FileName
ok=0
for f in "./$util" "$FABOSHOME/share/$util" "$home/$util"
do
  if [ -r $f ]
  then
    name_list=`/bin/cat $f | /usr/bin/tr -s "	 " "  " | /bin/grep "N SCRIPTNAME"`
    ok=1
    break;
  fi
done
if [ $ok -ne 1 ]
then
  err "Could not locate $util"
  exit 3
fi
if [ "$name_list" = "" ]
then
  err "Could not locate script name list."
  exit 3
fi


################################
# Set switch to always available and see if there are blades installed
################################
all_slots=""
num_switch=`getNumSwitches`
all_slots="`getAvailSlots -chassisnofault`"
if [ "$all_slots" = "" ]
then
    /bin/echo "systemverification: Could not find any thing to test."
fi
_tmp_slot=`/bin/echo $all_slots | /usr/bin/cut -d" " -f1`
script_name="`burninSetName -show $_tmp_slot -update verify`"
if [ multi_$multiBlade = multi_TRUE ]
then
    script_name=`/bin/echo $script_name | /usr/bin/cut -d" " -f6 | /usr/bin/cut -d"." -f1`
else
    script_name=`/bin/echo $script_name | /usr/bin/cut -d" " -f4 | /usr/bin/cut -d"." -f1`
fi
################################
# Process parameters and do the diagsetcycle if requested
################################
unit_number=-1
while [ "$1" != "" ]
do
  case $1 in
  "-unit" )
    shift
################################
#While Running Mode 11 with -unit option for Gen6 chassis will cause PCI error and reboot 
#Due to Mode 11 limitation, blocking unit parameter from Gen6 platform
################################
    if [ `supportsQuiescent` = TRUE ]
    then
      /bin/echo "systemverification: -unit option is not supported on Gen6 Chassis."
      /bin/echo "Please run systemverification without -unit option"
      exit 3
    fi
    if [ "`isValidSlot $1 -chassis`" = TRUE ]
    then
      unit_number=$1
      shift
    else
      /bin/echo "systemverification: invalid slot specified $1"
      /bin/echo "valid slots are: $all_slots"
      /bin/echo $syntax
      exit 3
    fi
    ;;
  "-short" )
    script_name=verify
    if [ "`/bin/echo $name_list | /bin/grep -w $script_name`" = "" ]
    then
      /bin/echo "Could not find $script_name"
      exit 1
    fi
    /bin/echo "systemverification: Setting parameters for short run."
    /fabos/sbin/diagsetcycle $script_name -short > /dev/null 2>&1
    shift
    ;;
  "-parameters" )
    script_name=verify
    if [ "`/bin/echo $name_list | /bin/grep -w $script_name`" = "" ]
    then
      /bin/echo "Could not find $script_name"
      exit 1
    fi
    /fabos/sbin/diagsetcycle $script_name
    shift
   ;;
  "-stop" )
    /bin/echo "systemverification: Stopping the test process. Please wait..."
    /fabos/libexec/diagstopburnin -local
    exit 0
    ;;
  * )
    /bin/echo "systemverification: invalid parameter $1"
    /bin/echo $syntax
    exit 3
    ;;
  esac
done

################################
# Check reboot requirement (Spike,Striker, Skybolt only)
################################
#chk_reboot_req


/bin/echo "systemverification: burnin parameters."
/fabos/sbin/diagsetcycle $script_name -show

################################
# Make sure switches are in Offline state before proceeding
################################
# Check whether VF is enabled
VFOUTPUT=`lscfg --show 2> /dev/null`

# If VF enabled, get the number of LS else set to 1.
if [ "$VFOUTPUT" != "" ]
then
    /bin/ln -s /fabos/cliexec/lscfg_util /usr/sbin/lscfg_test 2> /dev/null
    num_switches=`lscfg_test --max`
else
    num_switches=1
fi

# Backup current context
_initial_switch=$FABOS_SWITCHNO
_initial_vf=$CURRENT_VF

switch=0
while [ $switch -lt $num_switches ]
do
    if [ "$VFOUTPUT" != "" ]
    then
        fabid=`lscfg_test --fid $switch`
        if [ "$fabid" != "-1" ]
        then
            export CURRENT_VF=$fabid
            export FABOS_SWITCHNO=$switch
        fi
    fi

    index=`/usr/bin/expr $switch + 1`
    slots="`getAvailSlots -switchnofault`"
    if [ "$slots" != "" ]
    then
	if [ "`switchshow | /bin/grep switchState | /bin/grep Online`" != "" ]
	then
	    /bin/echo "systemverification: Cannot proceed on switch $switch, switch is Online."
        /bin/echo "systemverification: Use chassisdisable to take all the switches Offline."
            export FABOS_SWITCHNO=$_initial_switch
            export CURRENT_VF=$_initial_vf
            /bin/rm -rf /usr/sbin/lscfg_test
	    exit 1
	fi
    fi
    switch=`/usr/bin/expr $switch + 1`
done

# Restore current context
export FABOS_SWITCHNO=$_initial_switch
export CURRENT_VF=$_initial_vf
/bin/rm -rf /usr/sbin/lscfg_test

# Set the chassis context
if [ "$VFOUTPUT" != "" ]
then
    eval $(lscfg_util --chassis)
fi

################################
# Make sure EE's are in Offline state before proceeding on Encryption platforms.
################################
encsupported="/fabos/link_bin/cryptocfg"
if [ -e $encsupported ] ; then
	if [ "`cryptocfg --show -local | /bin/grep \"SP state\" | /bin/grep -e Operational -e Online`" != "" ]
	then
		/bin/echo "systemverification: Cannot proceed on switch, Encryption Engine is Enabled."
		/bin/echo "systemverification: Please use cryptocfg to disable Encryption Engines."
		exit 1
	fi
fi

################################
# Warn about burninerrclear
# and diagclearerror
################################
/bin/echo ""
/bin/echo "IMPORTANT 1: Before starting a burnin run:"
/bin/echo "IMPORTANT 1: Please ensure that the burnin error log"
/bin/echo "IMPORTANT 1: is empty by executing \"burninerrclear\""
/bin/echo "IMPORTANT 1: and diagnostics failure status if any"
/bin/echo "IMPORTANT 1: is cleared using \"diagclearerror -all\"."
/bin/echo ""

################################
# Instruct stepwise procedure
################################
/bin/echo "IMPORTANT 2: Use \"diagsetcycle verify -default\""
/bin/echo "IMPORTANT 2: to set parameters to default value"
/bin/echo "IMPORTANT 2: and then \"diagsetcycle verify -current\""
/bin/echo "IMPORTANT 2: if needed to set specific parameters of the test"
/bin/echo "IMPORTANT 2: as per requirement. \"diagsetcycle verify -show\""
/bin/echo "IMPORTANT 2: can be used to verify current value of parameters"
/bin/echo "IMPORTANT 2: that will be used for systemverification."
/bin/echo ""

################################
# Warn about cryptocfg
################################
/bin/echo "IMPORTANT 3: On platforms which include a security processor, you"
/bin/echo "IMPORTANT 3: must disable the security processor by running"
/bin/echo "IMPORTANT 3: (cryptocfg --disableEE <slot>) before running"
/bin/echo "IMPORTANT 3: systemverification. You must re-enable the security"
/bin/echo "IMPORTANT 3: processor (cryptocfg -enableEE <slot>) once"
/bin/echo "IMPORTANT 3: systemverification is complete."
/bin/echo ""

################################
# Check reboot requirement (Spike,Striker, Skybolt only)
################################

#moved this from line 466 to fix the defect TR000280553 
chk_reboot_req
# Set _reboot_sw to let DIAGD be sent for Gen6 platforms during sysV cleanup
if [ `supportsQuiescent` = TRUE ]
then
  _reboot_sw=1
fi


################################
# Set trap to default handler, then my handler before the scripts are started
# The setting to default first is necessary to overcome shell built in
# behavior of wait in case this script is used in the background
################################
trap "" 2
trap systemverification_cleanup INT TERM

################################
# Arm the burnin
################################
/bin/echo "systemverification: Arming the burnin run."
 case `getSWBD` in
  "SWBD148" | "SWBD171" )
  /bin/echo "Adding skipfosd.reset file"
  /bin/touch /tmp/skipfosd.reset ;;
 esac
if [ "$unit_number" != -1 ]
then
  /fabos/sbin/burninerrclear $unit_number > /dev/null
  /fabos/libexec/diagsetburnin -local -slot $unit_number $script_name > /dev/null 2>&1
else
  /fabos/sbin/burninerrclear > /dev/null
  /fabos/libexec/diagsetburnin -local $script_name > /dev/null 2>&1
fi

################################
# Check whether another systemVerification is running
################################
if [ $? -eq 5 ]
then
  /bin/echo "systemverification: Testing already in-progress."
  /bin/echo "systemverification: Please wait till the testing is completed."
  /bin/echo "systemverification: Use \"burninstatus\" to check the current status."
  /bin/echo "systemverification: Or use \"systemverification -stop\" to stop testing."
  exit 1
fi

################################
# Start the $script_name on all active blades
################################
/bin/echo "systemverification: Starting burnin"
burnin_script=`burninSetScript SWITCH BURNIN -show | /usr/bin/cut -d" " -f7 | /usr/bin/cut -d"." -f1`
if [ $unit_number != -1 ]
then
  switch=`getSwitchFromSlot $unit_number`
  export FABOS_SWITCHNO=$switch
  export FABOS_SLOTNO=$slot
  do_sw_quiescent $unit_number TRUE
  /fabos/share/$burnin_script -slot $unit_number &
else
  for slot in $all_slots
  do
    switch=`getSwitchFromSlot $slot`
    export FABOS_SWITCHNO=$switch
    export FABOS_SLOTNO=$slot
    do_sw_quiescent $slot TRUE
    /fabos/share/$burnin_script -slot $slot &
  done
fi
################################
# Wait for all blades to complete
################################
/bin/echo "systemverification: Monitoring progress of the burnin activity."

# wait for burnin script to set burninstatus with the PID

# Inform the user while processing is in progress to ensure that user does 
# not feel the system is hung -- defect TR000248185 
    /bin/sleep 30
    /bin/echo -ne  "\033[5m Systemverification: Please Wait!!! \033[0m \r"
    /bin/sleep 90

more=TRUE

# Monitor all burnin activity found on this switch
export fail_list=""
if [ "$unit_number" != -1 ]
then
	num_slots=1
	/fabos/sbin/burninstatus -slot $unit_number > /tmp/burninstatus.log
else
	num_slots=`/bin/echo "$all_slots" |\
	    /usr/bin/wc -w |\
	    /usr/bin/tr -s " " " " |\
	    /usr/bin/cut -d" " -f2`
	/fabos/sbin/burninstatus > /tmp/burninstatus.log
fi

if [ multi_$multiBlade = multi_TRUE ]
then
    pids=`/bin/cat /tmp/burninstatus.log | /bin/grep -v "PID" | /usr/bin/tr -s "	 " "  " | /usr/bin/cut -d" " -f7 | /usr/bin/xargs /bin/echo`
else
    pids=`/bin/cat /tmp/burninstatus.log | /bin/grep -v "PID" | /usr/bin/tr -s "	 " "  " | /usr/bin/cut -d" " -f6 | /usr/bin/xargs /bin/echo`
fi
while [ more_$more = more_TRUE ]
do
    # Inform the user while processing is in progress to ensure that user does 
    # not feel the system is hung -- defect TR000248185 
    /bin/sleep 30
    /bin/echo -ne  "\033[5m Systemverification: Please Wait!!! \033[0m \r"
    /bin/sleep 90
    
    if [ "$unit_number" != -1 ]
    then
	/fabos/sbin/burninstatus -slot $unit_number > /tmp/burninstatus.log
    else
	/fabos/sbin/burninstatus > /tmp/burninstatus.log
    fi
    if [ "$pids" = "" -o "`/bin/ps -p "$pids" | /bin/grep -v PID`" = "" ]
    then
	more=FALSE
    else
	more=TRUE
	#
	# Since we are not done, report any newly failing slots
	#
	/bin/cat /tmp/burninstatus.log | while read line
	do
	    if [ "`/bin/echo $line | /bin/grep FAIL`" != "" ]
	    then
		if [ multi_$multiBlade = multi_TRUE ]
		then
		    #
		    # There are fails to output, but only new slot information
		    # so fail data is as close to real occurence as possible
		    # with the polling scheme
		    #
		    slot=`/bin/echo $line |\
			/usr/bin/tr -s "	 " " " |\
			/usr/bin/cut -d" " -f1`
		    /bin/echo "systemverification found Slot $slot has failed"
		else
            # During systemvreification for ODIN, if plb mode 2 fails for
            # some reason (Ex running with min_lb_mode 1 without loopbacks)
            # sysv script tries to abort the run and terminate any running
            # test and exit. Almost all pizzabox run only mode 2 but ODIN
            # starts mode 8 after mode 2. Since the script tries to abort
            # mode 8 as soon as it is started, it leaves the switch in 
            # disabled state and does not come online after chassisenable.
            # To fix this, let sysv continue ro run mode 8 and complete
            # normally instead of trying to abort. This fix is specific to 
            # ODIN and does not affect other platforms. Similar check and 
            # skin cleanup change is made a few lines below as well.
            # FOS-805372
            _bladeID=`getBladeID $slot`
            if [ "$_bladeID" != "ODIN" ]
            then
		    # If fail on single bladed system, bail out early
		    /bin/echo "systemverification: Terminating - Unit has failed."
		    systemverification_cleanup
		    more=FALSE
            fi
		fi
	    fi
	done
	fail_list=`/bin/cat /tmp/burninstatus.log |\
		/bin/grep FAIL | \
		/usr/bin/tr -s "	 " " " |\
		/usr/bin/cut -d" " -f1 |\
		/usr/bin/xargs`
	/bin/rm -f /tmp/burninstatus.log

	# If all blades have failed, then terminate activity
	num_fails=`/bin/echo $fail_list |\
	    /usr/bin/wc -w |\
	    /usr/bin/tr -s " " " " |\
	    /usr/bin/cut -d" " -f2`
	if [ $num_fails -gt 0 ]
	then
	    if [ $num_fails -eq $num_slots ]
	    then
		/bin/echo "systemverification: Terminating - All slots have failed."
        _bladeID=`getBladeID $slot`
        if [ "$_bladeID" != "ODIN" ]
        then
		# All failed, bail out early
		systemverification_cleanup
		more=FALSE
        fi
	    else
		/bin/echo "systemverification: $num_fails out of $num_slots slots have failed."
	    fi
	fi
    fi
done

################################
# Output results
################################
/bin/echo "systemverification: Outputting Status"
if [ "$unit_number" != -1 ]
then
    /fabos/sbin/burninstatus -slot $unit_number > /tmp/burninstatus.log
else
    /fabos/sbin/burninstatus > /tmp/burninstatus.log
fi
/bin/cat /tmp/burninstatus.log
/bin/cat /tmp/burninstatus.log | while read line
do
    if [ "`/bin/echo $line | /bin/grep FAIL`" != "" ]
    then
        if [ multi_$multiBlade = multi_TRUE ]
        then
	  slot=`/bin/echo $line | /usr/bin/cut -d " " -f1`
	  /bin/echo "systemverification: burninerrshow for slot $slot:"
	  /fabos/bin/burninerrshow $slot
        else
	  /bin/echo "systemverification: burninerrshow:"
	  /fabos/bin/burninerrshow
        fi
    fi
done
/bin/rm -f /tmp/burninstatus.log
#case `getSWBD` in
#  "SWBD148" )
#  /bin/echo "%WARNING: Please reboot the switch after test completion"
#esac
################################
# Reboot the switch
################################
#
# Reboot switch to initialize FCIP/FCoE ports on Spike/Striker/Elara/Europa/Skybolt.
# This additional step is only required for Newton/Discovery release builds.
#
all_slots=""
if [ "$_reboot_sw" = 1 ]; then
 if [ "$unit_number" = -1 ]
 then
   all_slots="`getAvailSlots -chassis`"
   for f in $all_slots ; do
      _bladeID=`getBladeID $f`
      if { [ "$_bladeID" = "SPIKE" ] || [ "$_bladeID" = "SKYBOLT" ]; }
          then
             /bin/sleep 1
             /bin/echo ""
             /bin/echo "Diagnostics will now reboot the switch ....."
             /bin/sleep 2
             /fabos/link_bin/sync
             /usr/bin/reboot
          elif [ "$_bladeID" = "STRIKER" ];
          then
             /bin/sleep 1
             /bin/echo ""
             /bin/echo "Diagnostics will now power cycle slot $f ....."
        	 /fabos/sbin/slotpoweroff $f
             /bin/sleep 2
    	     /fabos/sbin/slotpoweron $f
             /bin/sleep 4
          else
             do_sw_quiescent $f FALSE
          fi          
   done
  else
   _bladeID=`getBladeID $unit_number`
   if { [ "$_bladeID" = "SPIKE" ] || [ "$_bladeID" = "SKYBOLT" ]; }
      then
         /bin/sleep 1
         /bin/echo ""
         /bin/echo "Diagnostics will now reboot the switch ....."
         /bin/sleep 2
         /fabos/link_bin/sync
         /usr/bin/reboot
      elif [ "$_bladeID" = "STRIKER" ];
      then
         /bin/sleep 1
         /bin/echo ""
         /bin/echo "Diagnostics will now power cycle slot $unit_number ....."
	     /fabos/sbin/slotpoweroff  $unit_number
         /bin/sleep 2
	     /fabos/sbin/slotpoweron $unit_number
         /bin/sleep 4
      else
         do_sw_quiescent $unit_number FALSE
    fi
 fi
fi
if [ -e /var/log/diag_slotshow.log ]
then
  /bin/rm -f /var/log/diag_slotshow.log
fi
exit 0
