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