#!/bin/bash
################################################################################
#
#  Name: bug_295 regression for bug #295, http://devel.opensaf.org/ticket/295
#		 Bad hpl_resource_reset() error handling
#
# 
#  Notes:
# 		This test verifies that hpl_resource_reset() returns an error if an
#       invalid reset value is passed to it.
#
#      -*- OpenSAF  -*-
#
# (C) Copyright 2008 The OpenSAF Foundation
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
# under the GNU Lesser General Public License Version 2.1, February 1999.
# The complete license can be accessed from the following location:
# http://opensource.org/licenses/lgpl-license.php
# See the Copying file included with the OpenSAF distribution for full
# licensing terms.
#
# Author(s):
#           Hewlett-Packard Company
#
################################################################################

#*******************************************************************************
#                             Common Environment
#*******************************************************************************
shopt -s extglob 		# POSIX regular expression matches
[[ $DEBUG = 1 ]] && set -o xtrace

#*******************************************************************************
#                                  Libraries
#*******************************************************************************
 # Figure out where the libraries are located and source them
declare MyPath=$(which ${0##*/} | sed -e "s:/[^/]*$::")
[[ -z $LIB_PATH ]] && export LIB_PATH=${MyPath}/../lib
if [[ -s $LIB_PATH/libTestUtils ]]
then
   . $LIB_PATH/libTestUtils
else
   echo -e "\n**>ERROR: Couldn't find libTestUtils"
   exit 1
fi
if [[ -s $LIB_PATH/libHisvApi ]]
then
   . $LIB_PATH/libHisvApi
else
   echo -e "\n**>ERROR: Couldn't find libHisvApi"
   exit 1
fi

#*******************************************************************************
#                          Global and Default Variables
#*******************************************************************************
 # Test-related Global variables
export APItest=hisv_reset_ctrl
export WaitTime=20

#*******************************************************************************
#                              Local Subroutines
#*******************************************************************************

function fCheckInput
{
  local inputError=0
  [[ -z $ConfigFile ]] && \
    fError  "You must specify a configuration file with test parameters" && \
      inputError=1

  [[ -z $ControllerEntityPath ]] && \
    fError "You must specify the controller entity path in the configuration file" && \
      inputError=1

  [[ -z $PayloadEntityPath ]] && \
    fError "You must specify the payload entity path in the configuration file" && \
      inputError=1

  [[ -z $OA ]] && \
    fError "You must specify the OA host name or IP in the configuration file" && \
      inputError=1

	# Fill in some info on the cluster
  [[ -z $ControllerBlade ]] && \
    export ControllerBlade=$(echo $ControllerEntityPath | sed -e "s:[{A-Z_]\{1,\},::" | sed -e "s:},.*::")

  [[ -z $PayloadBlade ]] && \
    export PayloadBlade=$(echo $PayloadEntityPath | sed -e "s:[{A-Z_]\{1,\},::" | sed -e "s:},.*::")

  [[ -z $Chassis ]] && \
     export Chassis=$(echo $ControllerEntityPath | sed -e "s:[{A-Z_]\{1,\},::" | sed -e "s:},.*::")

  if (( inputError ))
  then
     exit $NORESULT
  else
     return
  fi
}

#*******************************************************************************
#                                    MAIN
#*******************************************************************************
 # Insure cleanup on exit
trap 'fCleanup' EXIT

 # Get the user's data
fParseCmdline $*

if [[ -z $ConfigFile ]]
then
	ConfigFile=$DefaultConfigFile
	fWarn "User didn't input config file, using default, $ConfigFile"
fi

 # Verify whether or not the test should be run
fCheckRunTest

 # Print the system configuration
fShowConfig

 # Read the data from the configuration file
if ! fReadCfgFile $ConfigFile
then
    fErrorExit $SKIPPED "Failed to read $ConfigFile"
fi

 # Verify that the user set up the required parameters
fCheckInput

 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 #                                 Run Tests
 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  # Print the test header
fInitTest "Bug 295 Regression Test"

declare TestType="API error handling for invalid reset type"
fPrintHeader "$TestType" 1
declare resetType=1024

fBeginTest "Apply $resetType reset to Payload using entity path"
fRunApiTest -t Payload -p $PayloadEntityPath -r $resetType -c $Chassis -f
fEndTest

exit $EXIT_VAL

#
# vim: tabstop=4
# -*- tab-width:4 -*-
#
