components/ipmitool/test_ipmitool
changeset 1137 5f35de46aa92
parent 1136 226e8d9d2ff0
child 1138 6e1f85fa0151
equal deleted inserted replaced
1136:226e8d9d2ff0 1137:5f35de46aa92
     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_ipmitool		confirm basic ipmitool functionality works
       
    27 #
       
    28 # exercise a commonly used subset of all ipmitool commands,
       
    29 # for each such command:
       
    30 #	save its output to a *.out file
       
    31 #	confirm ipmitool exit status is 0 (good)
       
    32 #	confirm *.out contains some piece of expected data
       
    33 # ----------------------------------------------------------------------------
       
    34 
       
    35 cmd_name="`basename $0`"		# the name of this command
       
    36 
       
    37 cmd_err="${cmd_name}: error:"		# the (fatal) error header
       
    38 cmd_warn="${cmd_name}: warning:"	# the warning header
       
    39 cmd_info="${cmd_name}: info:"		# the informational header
       
    40 cmd_query="${cmd_name}: query:"		# the interrogative header
       
    41 
       
    42 bin_path="/usr/sbin"	# path(s) to ipmitool binary executable(s)
       
    43 
       
    44 # ----------------------------------------------------------------------------
       
    45 
       
    46 usage()
       
    47 {
       
    48     echo "usage: $cmd_name [-p <bin_path>]"
       
    49     echo "       -p  path to ipmitool binary"
       
    50     echo "purpose: confirm basic ipmitool functionality works;"
       
    51     echo "         this is NOT a comprehensive test"
       
    52     echo "examples:"
       
    53     echo "	$cmd_name -p \$CODEMGR_WS/proto/root_\`uname -p\`/usr/sbin"
       
    54 } # usage()
       
    55 
       
    56 # ----------------------------------------------------------------------------
       
    57 
       
    58 show_env()
       
    59 {
       
    60     echo "$cmd_info general environment:"
       
    61     date ; id ; uname -a ; pwd ; echo "$PATH"
       
    62     [ -r /etc/release ] && cat /etc/release
       
    63     [ -r /etc/motd ] && grep bfu /etc/motd
       
    64     ipmitool -V
       
    65 } # show_env()
       
    66 
       
    67 # ----------------------------------------------------------------------------
       
    68 
       
    69 enforce_i386()
       
    70 {
       
    71     proctype=`uname -p`
       
    72     [ "$proctype" != "i386" ] && {
       
    73 	echo "$cmd_err processor type $proctype != i386"
       
    74 	echo "$cmd_info future versions of this test tool may use"
       
    75 	echo "    ipmitool -I lan -H <i386_host>"
       
    76 	echo "when run on $proctype but that is a future enhancement (TBD)"
       
    77 	exit 1
       
    78     }
       
    79 } # enforce_i386()
       
    80 
       
    81 # ----------------------------------------------------------------------------
       
    82 
       
    83 test_opt_version()
       
    84 {
       
    85     tnm="version option"
       
    86     ipmitool -V > ipmitool_V.out
       
    87     rc=$?
       
    88     [ $rc -ne 0 ] && {
       
    89 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
    90     }
       
    91     cnt=`grep -i -c 'version.*[0-9][0-9]*\.[0-9]' ipmitool_V.out`
       
    92     [ $cnt -le 0 ] && {
       
    93 	echo "$cmd_err $tnm output missing version" ; exit 1
       
    94     }
       
    95     echo "$cmd_info $tnm passed"
       
    96 } # test_opt_version()
       
    97 
       
    98 # ----------------------------------------------------------------------------
       
    99 
       
   100 test_cmd_help()
       
   101 {
       
   102     tnm="help command"
       
   103     ipmitool help > ipmitool_help.out 2>&1
       
   104     rc=$?
       
   105     [ $rc -ne 0 ] && {
       
   106 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   107     }
       
   108     cnt=`grep -i -c 'chassis.*status' ipmitool_help.out`
       
   109     [ $cnt -le 0 ] && {
       
   110 	echo "$cmd_err $tnm output missing chassis" ; exit 1
       
   111     }
       
   112     echo "$cmd_info $tnm passed"
       
   113 } # test_cmd_help()
       
   114 
       
   115 # ----------------------------------------------------------------------------
       
   116 
       
   117 test_cmd_bmc()
       
   118 {
       
   119     tnm="bmc info command"
       
   120     ipmitool bmc info > ipmitool_bmc_info.out
       
   121     rc=$?
       
   122     [ $rc -ne 0 ] && {
       
   123 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   124     }
       
   125     cnt=`grep -c 'IPMI Version' ipmitool_bmc_info.out`
       
   126     [ $cnt -lt 1 ] && {
       
   127 	echo "$cmd_err $tnm output missing IPMI Version" ; exit 1
       
   128     }
       
   129     echo "$cmd_info $tnm passed"
       
   130     tnm="bmc getenables command"
       
   131     ipmitool bmc getenables > ipmitool_bmc_getenables.out
       
   132     rc=$?
       
   133     [ $rc -ne 0 ] && {
       
   134 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   135     }
       
   136     cnt=`grep -c 'OEM' ipmitool_bmc_getenables.out`
       
   137     [ $cnt -lt 3 ] && {
       
   138 	echo "$cmd_err $tnm output too few OEM" ; exit 1
       
   139     }
       
   140     echo "$cmd_info $tnm passed"
       
   141 } # test_cmd_bmc()
       
   142 
       
   143 # ----------------------------------------------------------------------------
       
   144 
       
   145 test_cmd_sel()
       
   146 {
       
   147     tnm="sel info command"
       
   148     ipmitool sel info > ipmitool_sel_info.out
       
   149     rc=$?
       
   150     [ $rc -ne 0 ] && {
       
   151 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   152     }
       
   153     cnt=`egrep -c 'Version|Entries' ipmitool_sel_info.out`
       
   154     [ $cnt -lt 2 ] && {
       
   155 	echo "$cmd_err $tnm output missing Version or Entries" ; exit 1
       
   156     }
       
   157     echo "$cmd_info $tnm passed"
       
   158     tnm="sel time get command"
       
   159     ipmitool sel time get > ipmitool_sel_time_get.out
       
   160     rc=$?
       
   161     [ $rc -ne 0 ] && {
       
   162 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   163     }
       
   164     nowyr=`date '+%Y'`
       
   165     cnt=`grep -c "$nowyr" ipmitool_sel_time_get.out`
       
   166     [ $cnt -lt 1 ] && {
       
   167 	echo "$cmd_err $tnm missing $nowyr" ; exit 1
       
   168     }
       
   169     echo "$cmd_info $tnm passed"
       
   170     tnm="sel list command"
       
   171     cnt=`grep 'Entries' ipmitool_sel_info.out | awk '{print $NF}'`
       
   172     [ $cnt -eq 0 ] && {
       
   173 	echo "$cmd_info $tnm passed" ; return 0
       
   174     }
       
   175     ipmitool sel list $cnt > ipmitool_sel_list.out
       
   176     rc=$?
       
   177     [ $rc -ne 0 ] && {
       
   178 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   179     }
       
   180     cnt2=`wc ipmitool_sel_list.out | awk '{print $1}'`
       
   181     [ $cnt2 -ne $cnt ] && {
       
   182 	echo "$cmd_err $tnm output lines $cnt2 != $cnt" ; exit 1
       
   183     }
       
   184     echo "$cmd_info $tnm passed"
       
   185 } # test_cmd_sel()
       
   186 
       
   187 # ----------------------------------------------------------------------------
       
   188 
       
   189 test_cmd_chassis()
       
   190 {
       
   191     tnm="chassis status command"
       
   192     ipmitool chassis status > ipmitool_chassis_status.out
       
   193     rc=$?
       
   194     [ $rc -ne 0 ] && {
       
   195 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   196     }
       
   197     cnt=`grep -c 'System Power' ipmitool_chassis_status.out`
       
   198     [ $cnt -eq 0 ] && {
       
   199 	echo "$cmd_err $tnm output missing System Power" ; exit 1
       
   200     }
       
   201     echo "$cmd_info $tnm passed"
       
   202 } # test_cmd_chassis()
       
   203 
       
   204 # ----------------------------------------------------------------------------
       
   205 
       
   206 test_cmd_fru()
       
   207 {
       
   208     tnm="fru print command"
       
   209     ipmitool fru print > ipmitool_fru_print.out
       
   210     rc=$?
       
   211     [ $rc -ne 0 ] && {
       
   212 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   213     }
       
   214     cnt=`grep -i -c 'Manufacturer.*Sun Microsystems' ipmitool_fru_print.out`
       
   215     [ $cnt -lt 1 ] && {
       
   216 	echo "$cmd_err $tnm output too few Sun Microsystems" ; exit 1
       
   217     }
       
   218     echo "$cmd_info $tnm passed"
       
   219 } # test_cmd_fru()
       
   220 
       
   221 # ----------------------------------------------------------------------------
       
   222 
       
   223 test_cmd_lan()
       
   224 {
       
   225     tnm="lan print command"
       
   226     ipmitool lan print > ipmitool_lan_print.out
       
   227     rc=$?
       
   228     [ $rc -ne 0 ] && {
       
   229 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   230     }
       
   231     cnt=`egrep -c 'ARP|MAC|IP' ipmitool_lan_print.out`
       
   232     [ $cnt -lt 3 ] && {
       
   233 	echo "$cmd_err $tnm output too few ARP|MAC|IP" ; exit 1
       
   234     }
       
   235     echo "$cmd_info $tnm passed"
       
   236     tnm="lan alert print command"
       
   237     ipmitool lan alert print > ipmitool_lan_alert_print.out
       
   238     rc=$?
       
   239     [ $rc -ne 0 ] && {
       
   240 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   241     }
       
   242     cnt=`grep -c 'Destination' ipmitool_lan_alert_print.out`
       
   243     [ $cnt -lt 1 ] && {
       
   244 	echo "$cmd_err $tnm output missing Destination" ; exit 1
       
   245     }
       
   246     echo "$cmd_info $tnm passed"
       
   247 } # test_cmd_lan()
       
   248 
       
   249 # ----------------------------------------------------------------------------
       
   250 
       
   251 test_cmd_channel()
       
   252 {
       
   253     tnm="channel info command"
       
   254     ipmitool channel info > ipmitool_channel_info.out
       
   255     rc=$?
       
   256     [ $rc -ne 0 ] && {
       
   257 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   258     }
       
   259     cnt=`grep -i -c 'Channel 0x.*info' ipmitool_channel_info.out`
       
   260     [ $cnt -lt 1 ] && {
       
   261 	echo "$cmd_err $tnm output missing Channel number" ; exit 1
       
   262     }
       
   263     echo "$cmd_info $tnm passed"
       
   264 } # test_cmd_channel()
       
   265 
       
   266 # ----------------------------------------------------------------------------
       
   267 
       
   268 test_cmd_sensor()
       
   269 {
       
   270     tnm="sensor list command"
       
   271     ipmitool sensor list > ipmitool_sensor_list.out
       
   272     rc=$?
       
   273     [ $rc -ne 0 ] && {
       
   274 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   275     }
       
   276     cnt=`egrep -i -c 'degrees|RPM|volts' ipmitool_sensor_list.out`
       
   277     [ $cnt -lt 10 ] && {
       
   278 	echo "$cmd_err $tnm output too few degrees|RPM|volts" ; exit 1
       
   279     }
       
   280     echo "$cmd_info $tnm passed"
       
   281     tnm="sensor get command"
       
   282     cnt=`expr $cnt % 10`
       
   283     # note: sensor names might have whitespace in them
       
   284     snm=`egrep -i 'degrees|RPM|volts' ipmitool_sensor_list.out | \
       
   285 	head -$cnt | tail -1 | cut -d'|' -f1`
       
   286     snm=`echo $snm`	# drop any leading or trailing whitespace
       
   287     ipmitool sensor get "$snm" > ipmitool_sensor_get.out
       
   288     rc=$?
       
   289     [ $rc -ne 0 ] && {
       
   290 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   291     }
       
   292     cnt=`egrep -i 'degrees|RPM|volts' ipmitool_sensor_get.out | \
       
   293 	grep -c 'Sensor Reading'`
       
   294     [ $cnt -ne 1 ] && {
       
   295 	echo "$cmd_err $tnm wrong Sensor Reading for $snm" ; exit 1
       
   296     }
       
   297     echo "$cmd_info $tnm passed"
       
   298 } # test_cmd_sensor()
       
   299 
       
   300 # ----------------------------------------------------------------------------
       
   301 
       
   302 test_cmd_sdr()
       
   303 {
       
   304     tnm="sdr list command"
       
   305     ipmitool sdr list all > ipmitool_sdr_list_all.out
       
   306     rc=$?
       
   307     [ $rc -ne 0 ] && {
       
   308 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   309     }
       
   310     cnt=`egrep -i -c 'degrees|RPM|volts' ipmitool_sdr_list_all.out`
       
   311     [ $cnt -lt 10 ] && {
       
   312 	echo "$cmd_err $tnm output too few degrees|RPM|volts" ; exit 1
       
   313     }
       
   314     echo "$cmd_info $tnm passed"
       
   315     tnm="sdr get command"
       
   316     cnt=`expr $cnt / 2`
       
   317     # note: sensor names might have whitespace in them
       
   318     snm=`egrep -i 'degrees|RPM|volts' ipmitool_sdr_list_all.out | \
       
   319 	head -$cnt | tail -1 | cut -d'|' -f1`
       
   320     snm=`echo $snm`	# drop any leading or trailing whitespace
       
   321     ipmitool sdr get "$snm" > ipmitool_sdr_get.out
       
   322     rc=$?
       
   323     [ $rc -ne 0 ] && {
       
   324 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   325     }
       
   326     cnt=`egrep -i 'degrees|RPM|volts' ipmitool_sdr_get.out | \
       
   327 	grep -c 'Sensor Reading'`
       
   328     [ $cnt -ne 1 ] && {
       
   329 	echo "$cmd_err $tnm wrong Sensor Reading for $snm" ; exit 1
       
   330     }
       
   331     echo "$cmd_info $tnm passed"
       
   332 } # test_cmd_sdr()
       
   333 
       
   334 # ----------------------------------------------------------------------------
       
   335 
       
   336 test_cmd_power()
       
   337 {
       
   338     tnm="power status command"
       
   339     ipmitool power status > ipmitool_power_status.out
       
   340     rc=$?
       
   341     [ $rc -ne 0 ] && {
       
   342 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   343     }
       
   344     cnt=`grep -i -c 'power.*on' ipmitool_power_status.out`
       
   345     [ $cnt -lt 1 ] && {
       
   346 	echo "$cmd_err $tnm output missing power on" ; exit 1
       
   347     }
       
   348     echo "$cmd_info $tnm passed"
       
   349 } # test_cmd_power()
       
   350 
       
   351 # ----------------------------------------------------------------------------
       
   352 
       
   353 test_cmd_echo()
       
   354 {
       
   355     tnm="echo command"
       
   356     ipmitool echo "hello world from pid $$" > ipmitool_echo.out
       
   357     rc=$?
       
   358     [ $rc -ne 0 ] && {
       
   359 	echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc
       
   360     }
       
   361     cnt=`grep -c "pid $$" ipmitool_echo.out`
       
   362     [ $cnt -ne 1 ] && {
       
   363 	echo "$cmd_err $tnm output missing my pid" ; exit 1
       
   364     }
       
   365     echo "$cmd_info $tnm passed"
       
   366 } # test_cmd_echo()
       
   367 
       
   368 # ----------------------------------------------------------------------------
       
   369 
       
   370 # main()
       
   371 
       
   372 while getopts p: opt; do # {
       
   373     case $opt in
       
   374 	p)  bin_path="$OPTARG";;
       
   375 	-)  break;;
       
   376 	\?) echo "$cmd_err bad option(s)" ; usage ; exit 22;;
       
   377     esac
       
   378 done # } while grabbing cmd line args
       
   379 
       
   380 shift `expr $OPTIND - 1`
       
   381 
       
   382 too_much="$1"
       
   383 [ "$too_much" != "" ] && {
       
   384     echo "$cmd_err too few/many args" ; usage ; exit 7
       
   385 }
       
   386 
       
   387 PATH="${bin_path}:$PATH"
       
   388 export PATH
       
   389 
       
   390 # ----------------------------------------------------------------------------
       
   391 
       
   392 enforce_i386
       
   393 show_env
       
   394 
       
   395 # version 1.8.8 and later
       
   396 
       
   397 test_opt_version
       
   398 test_cmd_help
       
   399 test_cmd_bmc
       
   400 test_cmd_sel
       
   401 test_cmd_chassis
       
   402 test_cmd_fru
       
   403 test_cmd_lan
       
   404 test_cmd_channel
       
   405 test_cmd_sensor
       
   406 test_cmd_sdr
       
   407 
       
   408 # version 1.8.10 and later
       
   409 
       
   410 test_cmd_power
       
   411 test_cmd_echo
       
   412 
       
   413 echo "$cmd_info all tests passed"	# if reach here then aok