3 # Output a list of hosts from the "qa_hosts" file which meet certain
4 # criteria specified by the options (see _usage).
5 # The list of QA hosts can be overridden by setting the environment
8 # Allows QA tests to get hostnames of particular configurations
11 # Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved.
19 status
=1 # failure is the default!
20 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
26 echo >&2 'Usage: getpmcdhosts [options]
29 -a {pmda} pmda connected to pmcd
30 -b 32|64 kernel binary format
31 -D debug/trace (see also -V)
32 -e big|little endianess
33 -h hostfile name of host file, default is qa_hosts
34 -L do not consider localhost
35 -m {metric}<op>{value} satisfies metric value predicate
36 -n num match first num hosts
37 -P return host running a primary pmlogger
38 -p multi|single multi or single processor
39 -s system operating system (uname -s)
40 -v {item}<op>{ver} version of item
41 -V verbose diagnostics (see also -D)
44 ipc inter-process protocol (deprecated)
45 libpcp shared library (deprecated)
46 pcp PCP version installed
48 <op> is one of =, >, >=, <, <= or !=
50 Most options may be used together but not repeated.
51 The environment variable QA_STS overrides the default host
58 # _checkpmcdhost moomba _ 64 _ multi 2 _ _ _
63 # binfmt 32 | n32 | 64 | _
64 # primary true | false
65 # proc multi | single | _
67 # msg true | false | _
68 # system irix | linux | _
69 # endian big | small | _
85 # check that host has a running pmcd
87 if pminfo
-h $HOST -f pmcd.agent.status
>/dev
/null
2>&1
91 $MSG && echo "$HOST: No running pmcd" >&2
95 # check for running agent
97 if [ "$AGENT" != "_" ]
99 if pmprobe
-h $HOST -I pmcd.agent.
type 2>/dev
/null |
grep $AGENT >/dev
/null
2>&1
103 $MSG && echo "$HOST: $AGENT not running" >&2
110 if [ "$BINFMT" != "_" ]
112 # only want 32 or 64 (not ia32 or n32 etc...)
113 # if want to be specific then use "-m pmcd.simabi=ia32"
114 objfmt
=`pmprobe -h $HOST -v pmcd.simabi 2>/dev/null \
116 | $PCP_AWK_PROG 'NF > 2 { for (i = 3; i <= NF; i++) printf "%s ",$i }' \
117 | sed -e 's/.*x86-64/64/g' \
118 -e 's/.*x86_64/64/g' \
123 if [ "$objfmt" != $BINFMT ]
125 $MSG && echo "$HOST: binary format $BINFMT != $objfmt" >&2
130 # check operating system name
132 if [ "$SYSTEM" != "_" ]
134 osname
=`ssh -q $SSH_USER@$HOST uname -s`
135 if echo $osname |
grep -i $SYSTEM >/dev
/null
2>&1
139 $MSG && echo "$HOST: system $SYSTEM no match with $osname " >&2
144 # check that host is running primary pmlogger
148 if pminfo
-h $HOST -f pmcd.pmlogger.
host |
grep primary
> /dev
/null
2>&1
152 $MSG && echo "$HOST: is _not_ running primary pmlogger" >&2
157 # check number of processors
159 if [ "$PROC" != "_" ]
161 $VERBOSE && echo "+ pmprobe -h $HOST -v hinv.ncpu | sed ..."
162 ncpu
=`pmprobe -h $HOST -v hinv.ncpu 2>/dev/null \
164 | $PCP_AWK_PROG 'NF == 3 && $3 ~ /^[0-9][0-9]*$/ { print $3 }'`
165 $VERBOSE && echo "-> |$ncpu|"
167 if [ -z "$ncpu" -o "$ncpu" = 0 ]
171 echo "$HOST: Unknown number of processors, pmprobe -> `pmprobe -h $HOST -v hinv.ncpu 2>&1`" >&2
175 if [ "$ncpu" -gt 1 -a "$PROC" = "single" ]
177 $MSG && echo "$HOST: Has $ncpu processors" >&2
179 elif [ "$ncpu" -eq 1 -a "$PROC" = "multi" ]
181 $MSG && echo "$HOST: Has only one processor" >&2
188 if [ "$ENDIAN" != "_" ]
190 $VERBOSE && echo "+ echo a | ssh -q $SSH_USER@$HOST od -x"
191 check
=`echo a | ssh -q $SSH_USER@$HOST "od -x" 2>&1 | sed -e 's/^0[^ ]* *//' -e 's/[ ]*$//' -e '/^$/d'`
192 $VERBOSE && echo "-> |$check|"
196 if [ "$ENDIAN" = big
]
198 $MSG && echo "$HOST: little endian" >&2
203 if [ "$ENDIAN" = little
]
205 $MSG && echo "$HOST: big endian" >&2
210 echo "$0: INTERNAL BOTCH: expecting 0a61 or 610a, got \"$check\"" >&2
216 # check the item value pairs
218 if [ -s "$tmp.items" ]
221 |
while read item op value
226 if pmprobe
-h $HOST -v pmcd.version
>$tmp.probe
2>$tmp.err
234 echo "$0: INTERNAL BOTCH item=\"$item\" not expected here!"
240 satisfies
=`sed -e 's/"//g' $tmp.probe \
242 BEGIN { op = "'"$op"'"; value="'"$value"'" }
243 NF >=3 { if ( $2 < 0 ) {
254 else if (op == "<") {
260 else if (op == "<=") {
266 else if (op == ">") {
272 else if (op == ">=") {
278 else if (op == "!=") {
290 if [ $satisfies -ne 1 ]
292 $MSG && echo "$HOST: does not satisfy predicate $metric $op $value" >&2
296 $MSG && echo "$HOST: pmprobe failed `cat $tmp.errs`" >&2
300 [ $?
-eq 1 ] && return 1
303 # check the metric value pairs
305 if [ -s "$tmp.metrics" ]
308 |
while read metric op value
310 if pmprobe
-h $HOST -v $metric >$tmp.probe
2>$tmp.errs
312 satisfies
=`sed -e 's/"//g' $tmp.probe \
314 BEGIN { op = "'"$op"'"; value="'"$value"'" }
315 NF >=3 { if ( $2 < 0 ) {
326 else if (op == "<") {
332 else if (op == "<=") {
338 else if (op == ">") {
344 else if (op == ">=") {
350 else if (op == "!=") {
362 if [ $satisfies -ne 1 ]
364 $MSG && echo "$HOST: does not satisfy predicate $metric $op $value" >&2
368 $MSG && echo "$HOST: pmprobe failed `cat $tmp.errs`" >&2
372 [ $?
-eq 1 ] && return 1
378 # Go thru table of hosts and see which meet the
379 # given criteria and return either the first one
380 # or a list of them if need be.
398 while getopts "a:b:De:h:Lm:n:Pp:s:v:V" c
417 small
) # synonym for little
421 echo "$0: Illegal endianess $ENDIAN" >&2
431 echo "$0: Cannot open hostfile $OPTARG" >&2
440 metric
=`echo $OPTARG | sed -e 's/[ ]*//' -e 's/[=<>!].*//'`
441 value
=`echo $OPTARG | sed -e 's/[ ]*//' -e 's/.*[=<>!]//'`
442 op
=`echo $OPTARG | sed -e 's/[ ]*//' -e "s/$metric//" -e "s/$value//"`
445 '='|
'<'|
'<='|
'>'|
'>='|
'!=')
448 echo "$0: Illegal metric argument: $OPTARG" >&2
453 echo "$metric $op $value" >> $tmp.metrics
454 $MSG && echo "---tmp.metrics---" >&2
455 $MSG && cat $tmp.metrics
>&2
475 item
=`echo $OPTARG | sed -e 's/[ ]*//' -e 's/[=<>!].*//'`
476 value
=`echo $OPTARG | sed -e 's/[ ]*//' -e 's/.*[=<>!]//'`
477 op
=`echo $OPTARG | sed -e 's/[ ]*//' -e "s/$item//" -e "s/$value//"`
481 echo "$0: Deprecated item \"$item\", ignored" >&2
485 value
=`echo "$value" | sed -e 's/\./ /g' | $PCP_AWK_PROG '
486 NF==1 { print $0 ".0.0" }
487 NF==2 { print $0 ".0" }
488 NF>2 { print $0 }' | sed -e 's/ /./g'`
491 echo "$0: Illegal item $item" >&2
497 '='|
'<'|
'<='|
'>'|
'>='|
'!=')
500 echo "$0: Illegal metric argument: $OPTARG" >&2
505 echo "$item $op $value" >> $tmp.items
506 $MSG && echo "---tmp.items---" >&2
507 $MSG && cat $tmp.items
>&2
520 if [ $# -ne `expr $OPTIND - 1` ]
531 if [ "$BINFMT" != "_" -a "$BINFMT" != 32 -a "$BINFMT" != 64 ]
533 echo "$0: -b option takes 32 or 64" >&2
537 if [ "$PROC" != "_" -a "$PROC" != "multi" -a "$PROC" != "single" ]
539 echo "$0: -p options takes multi or single" >&2
549 # Use qa_hosts file if environment variable $QA_HOSTS is not set (or null)
551 if [ -z "$QA_HOSTS" ]
555 if [ -f GNUmakefile.
install ]
557 # running QA in the tree
558 ${MAKE:-make} -f GNUmakefile.
install $HOSTS >$tmp.
make.out
2>&1
560 ${MAKE:-make} $HOSTS >$tmp.
make.out
2>&1
566 cat $tmp.
make.out
>&2
567 echo "$0: Unable to make \"$HOSTS\"" >&2
571 QA_HOSTS
=`cat $HOSTS`
574 # Remove the localhost if requested
578 localhost
=`hostname | sed -e 's/\..*//'`
579 QA_HOSTS
=`echo $QA_HOSTS | sed \
581 -e "s/$localhost\.[^ ]* //g" \
582 -e "s/$localhost //g"`
585 $MSG && ( echo "Checking hosts:"; echo "$QA_HOSTS"; echo ) >&2
587 # Iterate through hosts
591 for HOST
in $QA_HOSTS
593 if _checkpmcdhost
$HOST $AGENT $BINFMT $PRIMARY $PROC $PCP $MSG $SYSTEM $ENDIAN
601 $PCP_ECHO_PROG $PCP_ECHO_N "$HOST ""$PCP_ECHO_C"
609 if [ $COUNT -gt 0 -a $i -ge $COUNT ]
615 # if been using \c then do final \n
622 echo "$0: unable to get $COUNT host(s) with options: \"$@\"" >&2