components/ipmitool/test_ipmievd
branchs11-update
changeset 2526 a7c3342cac79
parent 2525 5e4049097207
child 2527 0935492f14d7
equal deleted inserted replaced
2525:5e4049097207 2526:a7c3342cac79
     1 #!/bin/sh
       
     2 
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
       
    23 #
       
    24 
       
    25 # ----------------------------------------------------------------------------
       
    26 # test_ipmievd		confirm basic ipmievd functionality works
       
    27 #
       
    28 # exercise syslog event reporting via event injection via ipmitool
       
    29 # ----------------------------------------------------------------------------
       
    30 
       
    31 cmd_name="`basename $0`"		# the name of this command
       
    32 
       
    33 cmd_err="${cmd_name}: error:"		# the (fatal) error header
       
    34 cmd_warn="${cmd_name}: warning:"	# the warning header
       
    35 cmd_info="${cmd_name}: info:"		# the informational header
       
    36 cmd_query="${cmd_name}: query:"		# the interrogative header
       
    37 
       
    38 bin_path="/usr/sbin:/usr/lib"	# path(s) to needed binary executable(s)
       
    39 proto_root=""			# path to proto root from build
       
    40 state_fn="/tmp/$cnd_name.$$.db"	# state file for cleanup
       
    41 
       
    42 # Design_Note: typically it takes about 4 seconds for an event to be syslogged,
       
    43 #              let's allow at least 12 seconds for it to be syslogged.
       
    44 
       
    45 SYSLOG_DELAY_SEC=12	# max wait in sec for event to be syslogged
       
    46 
       
    47 # ----------------------------------------------------------------------------
       
    48 
       
    49 usage()
       
    50 {
       
    51     echo "usage: $cmd_name [-r <proto_root>]"
       
    52     echo "       -r  path to proto root of recent build of tool+daemon"
       
    53     echo "purpose: confirm basic ipmievd functionality works;"
       
    54     echo "         this is NOT a comprehensive test"
       
    55     echo "examples:"
       
    56     echo "	$cmd_name -r \$CODEMGR_WS/proto/root_\`uname -p\`"
       
    57     echo "caveats: installs and leaves installed new tool+daemon on error"
       
    58 } # usage()
       
    59 
       
    60 # ----------------------------------------------------------------------------
       
    61 
       
    62 show_env()
       
    63 {
       
    64     echo "$cmd_info general environment:"
       
    65     date ; id ; uname -a ; pwd ; echo "$PATH"
       
    66     [ -r /etc/release ] && cat /etc/release
       
    67     [ -r /etc/motd ] && grep bfu /etc/motd
       
    68     ipmievd -V
       
    69     ipmitool -V
       
    70 } # usage()
       
    71 
       
    72 # ----------------------------------------------------------------------------
       
    73 
       
    74 enforce_i386()
       
    75 {
       
    76     proctype=`uname -p`
       
    77     [ "$proctype" != "i386" ] && {
       
    78 	echo "$cmd_err processor type $proctype != i386"
       
    79 	exit 1
       
    80     }
       
    81 } # enforce_i386()
       
    82 
       
    83 # ----------------------------------------------------------------------------
       
    84 
       
    85 install_proto()
       
    86 {
       
    87     [ "$proto_root" = "" ] && {
       
    88 	echo "$cmd_info skipping install of unset proto_root" ; return 0
       
    89     }
       
    90     [ ! -r /usr/sbin/ipmitool.orig ] && {
       
    91 	cp -p /usr/sbin/ipmitool /usr/sbin/ipmitool.orig
       
    92     }
       
    93     [ ! -r /usr/lib/ipmievd.orig ] && {
       
    94 	cp -p /usr/lib/ipmievd /usr/lib/ipmievd.orig
       
    95     }
       
    96 
       
    97     # disable/kill ipmievd before overwriting binary
       
    98 
       
    99     sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'`
       
   100     echo "ipmievd_svc_state: $sstate" > $state_fn
       
   101     [ "$sstate" = "online" ] && {
       
   102 	echo "$cmd_info disabling ipmievd service per proto_root"
       
   103 	svcadm disable -ts ipmievd
       
   104     }
       
   105     pkill -x ipmievd	# may or may not have been running as a service
       
   106 
       
   107     echo "$cmd_info installing proto_root tool+daemon"
       
   108     cp $proto_root/usr/sbin/ipmitool /usr/sbin/ipmitool
       
   109     cp $proto_root/usr/lib/ipmievd   /usr/lib/ipmievd
       
   110 
       
   111 } # install_proto()
       
   112 
       
   113 # ----------------------------------------------------------------------------
       
   114 
       
   115 uninstall_proto()
       
   116 {
       
   117     [ "$proto_root" = "" ] && {
       
   118 	echo "$cmd_info skipping uninstall of unset proto_root" ; return 0
       
   119     }
       
   120 
       
   121     # disable/kill ipmievd before overwriting binary
       
   122 
       
   123     sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'`
       
   124     [ "$sstate" = "online" ] && {
       
   125 	echo "$cmd_info disabling ipmievd service per proto_root"
       
   126 	svcadm disable -ts ipmievd
       
   127     }
       
   128     pkill -x ipmievd	# may or may not have been running as a service
       
   129 
       
   130     echo "$cmd_info uninstalling proto_root tool+daemon"
       
   131     [ -r /usr/sbin/ipmitool.orig ] && {
       
   132 	cp -p /usr/sbin/ipmitool.orig /usr/sbin/ipmitool
       
   133     }
       
   134     [ -r /usr/lib/ipmievd.orig ] && {
       
   135 	cp -p /usr/lib/ipmievd.orig /usr/lib/ipmievd
       
   136     }
       
   137 
       
   138     # restore initial state of ipmievd svc if known
       
   139 
       
   140     [ ! -r $state_fn ] && return 0
       
   141 
       
   142     was_online=`grep -c "ipmievd_svc_state.*online" $state_fn`
       
   143     [ $was_online -ne 0 ] && {
       
   144 	echo "$cmd_info enabling ipmievd service per initial state"
       
   145 	svcadm enable -s ipmievd
       
   146     }
       
   147 } # uninstall_proto()
       
   148 
       
   149 # ----------------------------------------------------------------------------
       
   150 
       
   151 test_opt_version()
       
   152 {
       
   153     tnm="version option"
       
   154     ipmievd -V > ipmievd_V.out
       
   155     rc=$?
       
   156     [ $rc -ne 0 ] && {
       
   157 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   158     }
       
   159     cnt=`grep -i -c 'version.*[0-9][0-9]*\.[0-9]' ipmievd_V.out`
       
   160     [ $cnt -le 0 ] && {
       
   161 	echo "$cmd_err $tnm output missing version" ; exit 1
       
   162     }
       
   163     echo "$cmd_info $tnm passed"
       
   164 } # test_opt_version()
       
   165 
       
   166 # ----------------------------------------------------------------------------
       
   167 
       
   168 test_opt_help()
       
   169 {
       
   170     tnm="help option"
       
   171     ipmievd -h > ipmievd_h.out 2>&1
       
   172     rc=$?
       
   173     [ $rc -ne 0 ] && {
       
   174 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   175     }
       
   176     cnt=`grep -i 'interface' ipmievd_h.out | grep -i -c 'bmc'`
       
   177     [ $cnt -le 0 ] && {
       
   178 	echo "$cmd_err $tnm output missing bmc interface" ; exit 1
       
   179     }
       
   180     echo "$cmd_info $tnm passed"
       
   181 } # test_opt_help()
       
   182 
       
   183 # ----------------------------------------------------------------------------
       
   184 
       
   185 test_svc_online()
       
   186 {
       
   187     tnm="service online check"
       
   188     sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'`
       
   189     [ "$sstate" = "online" ] && {
       
   190 	echo "$cmd_info disabling ipmievd service"
       
   191 	svcadm disable -ts ipmievd
       
   192     }
       
   193 
       
   194     echo "$cmd_info enabling ipmievd service"
       
   195     svcadm enable -ts ipmievd
       
   196     sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'`
       
   197     [ "$sstate" != "online" ] && {
       
   198 	echo "$cmd_err $tnm ipmievd service state $sstate != online" ; exit 1
       
   199     }
       
   200     echo "$cmd_info $tnm passed"
       
   201 } # test_svc_online()
       
   202 
       
   203 # ----------------------------------------------------------------------------
       
   204 
       
   205 test_syslog_init()
       
   206 {
       
   207     tnm="syslog initial entries"
       
   208     # Reading|Waiting events below are generated by bringing svc online;
       
   209     # wait some for them to be syslogged.
       
   210     echo "$cmd_info may wait $SYSLOG_DELAY_SEC sec per expected syslog entry"
       
   211     sleep $SYSLOG_DELAY_SEC
       
   212     cnt1=`grep -i -c 'ipmievd.*Reading' /var/adm/messages`
       
   213     cnt2=`grep -i -c 'ipmievd.*Waiting' /var/adm/messages`
       
   214     grep ipmievd /var/adm/messages > ipmievd.syslog_init.out
       
   215     [ $cnt1 -lt 1 ] || [ $cnt2 -lt 1 ] && {
       
   216 	echo "$cmd_err $tnm ipmievd too few initial syslog entries" ; exit 1
       
   217     }
       
   218     echo "$cmd_info $tnm passed"
       
   219 } # test_syslog_init()
       
   220 
       
   221 # ----------------------------------------------------------------------------
       
   222 
       
   223 test_syslog_event()
       
   224 {
       
   225     num="$1"	# event number being tested
       
   226 
       
   227     tnm="syslog event $num entry"
       
   228     now=`date | awk '{print $2 " " $3}'`
       
   229     cnt1=`grep -i -c "$now.*ipmievd" /var/adm/messages`
       
   230     ipmitool event $num > ipmitool.syslog_event_$num.out
       
   231     rc=$?
       
   232     [ $rc -ne 0 ] && {
       
   233 	echo "$cmd_warn $tnm ipmitool exit code $rc"
       
   234     }
       
   235     sleep $SYSLOG_DELAY_SEC
       
   236     cnt2=`grep -i -c "$now.*ipmievd" /var/adm/messages`
       
   237     cnt3=`expr $cnt1 + 1` # expected val
       
   238     [ $cnt2 -lt $cnt3 ] && {
       
   239 	echo "$cmd_err $tnm not syslogged in $SYSLOG_DELAY_SEC sec" ; exit 1
       
   240     }
       
   241     [ $cnt2 -gt $cnt3 ] && {
       
   242 	echo "$cmd_warn $tnm more syslog entries seen than expected"
       
   243     }
       
   244     echo "$cmd_info $tnm passed"
       
   245 } # test_syslog_event()
       
   246 
       
   247 # ----------------------------------------------------------------------------
       
   248 
       
   249 # main()
       
   250 
       
   251 while getopts r: opt; do # {
       
   252     case $opt in
       
   253 	r)  proto_root="$OPTARG";;
       
   254 	-)  break;;
       
   255 	\?) echo "$cmd_err bad option(s)" ; usage ; exit 22;;
       
   256     esac
       
   257 done # } while grabbing cmd line args
       
   258 
       
   259 shift `expr $OPTIND - 1`
       
   260 
       
   261 too_much="$1"
       
   262 [ "$too_much" != "" ] && {
       
   263     echo "$cmd_err too few/many args" ; usage ; exit 7
       
   264 }
       
   265 [ "$proto_root" != "" ] && [ ! -d $proto_root ] && {
       
   266     echo "$cmd_err proto_root $proto_root not a dir" ; usage ; exit 20
       
   267 }
       
   268 
       
   269 PATH="${bin_path}:$PATH"
       
   270 export PATH
       
   271 
       
   272 # ----------------------------------------------------------------------------
       
   273 
       
   274 enforce_i386
       
   275 install_proto
       
   276 show_env
       
   277 
       
   278 test_opt_version
       
   279 test_opt_help
       
   280 test_svc_online
       
   281 test_syslog_init
       
   282 # Design_Note: not all platforms appear to support event 3 (ECC);
       
   283 #              so skip it and just do events 1 and 2.
       
   284 for n in 1 2; do
       
   285     test_syslog_event $n
       
   286 done
       
   287 
       
   288 uninstall_proto
       
   289 
       
   290 echo "$cmd_info all tests passed"	# if reach here then aok