pmrep: fix archive end time reporting
[pcp.git] / qa / common
blob90bd4b99b5df7548f8fa540c79dad17ed17982e7
1 #!/bin/sh
3 # common procedures for PCP QA scripts
5 # Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved.
8 # for _wait_for_pmlogger() and _change_config()
9 . ./common.check
11 # per product QA script customization
13 . ./common.setup
14 [ -z "$DEFAULT_HOST" ] && DEFAULT_HOST=`hostname`
16 _setenvironment()
18 MSGVERB="text:action"
19 export MSGVERB
20 export PCP_BINADM_DIR
21 export PCP_DERIVED_CONFIG=""
24 _log_fyi()
26 echo "FYI ... here are the PMCD logs"
27 for log
29 if [ ! -f $log ]
30 then
31 # try in the other place
33 case $log
35 $PCP_LOG_DIR/pmcd/*)
36 __try=`echo $log | sed -e "s;/pmcd/;/;"`
39 __try=`echo $log | sed -e "s;$PCP_LOG_DIR/;$PCP_LOG_DIR/pmcd/;"`
41 esac
42 [ -f $__try ] && log=$__try
44 if [ -f $log ]
45 then
46 echo "::::::::: start $log ::::::::"
47 cat $log
48 echo ":::::::::: end $log :::::::::"
50 [ $log != $PCP_LOG_DIR/pmcd/pmcd.log ] && $sudo rm -f $log
51 else
52 echo "$log: not found"
54 done
57 _havesudo()
59 if [ -z "$PCP_DIR" ]
60 then
61 setuid=`$sudo id | sed -e 's/(.*//' -e 's/.*=//'`
62 if [ "$setuid" != 0 ]
63 then
64 echo "\"sudo\" is not an executable setuid root. This is fatal."
65 echo "As root, you need to setup your sudoers file for pcpqa."
66 exit 1
71 _haveagents()
73 restart=false
74 _here=`pwd`
76 # PMDAs than need to be here for QA
78 COMMON_PMDAS="sample sampledso simple"
79 if [ -d $PCP_PMDAS_DIR/cisco ]
80 then
81 # cisco PMDA requires that you can reach a router
83 if which ping >/dev/null 2>&1
84 then
85 # Note: PCP_QA_CISCOROUTER needs to be defined in common.rc
86 if ping -c 1 $PCP_QA_CISCOROUTER >/dev/null 2>&1
87 then
88 COMMON_PMDAS="$COMMON_PMDAS cisco"
93 for agent in $COMMON_PMDAS
95 probe=$agent
96 agentlog=$PCP_LOG_DIR/pmcd/$agent.log
98 # make this empty to stop any attempt to reinstall
100 agentdir=$PCP_PMDAS_DIR/$agent
102 case $agent
104 cisco)
105 probe=cisco.bytes_in
107 sample)
108 probe=sample.milliseconds
110 sampledso)
111 probe=sampledso.milliseconds
112 agentdir=$PCP_PMDAS_DIR/sample
114 simple)
115 probe=simple.numfetch
117 esac
118 reinstall=false
119 while true
121 [ $diff = true ] || echo "PMDA probe: pminfo -h $QA_HOST -f $probe"
122 if pminfo -h $QA_HOST -f $probe 2>&1 \
123 | tail -1 \
124 | egrep "^[ ]*((value)|(inst))[ ]" >/dev/null
125 then
126 break
127 else
128 echo "PMDA $agent is not responding"
129 if $restart
130 then
132 else
133 _log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $agentlog
134 echo "Restarting PMCD ..."
135 $sudo $PCP_RC_DIR/pcp restart
136 restart=true
138 if $reinstall
139 then
140 [ -f $_here/$iam.out ] && cat $_here/$iam.out
141 echo "Cannot make PMDA $agent work, ... giving up!"
142 exit 1
143 else
144 if [ -z "$agentdir" ]
145 then
146 echo "Skip PMDA re-install"
147 break
148 elif [ -d "$agentdir" ]
149 then
150 echo "Trying to re-install PMDA $agent from $agentdir ..."
151 _log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $agentlog
152 cd $agentdir
153 unset ROOT TOOLROOT MAKEFLAGS
154 $sudo ./Remove </dev/null >>$_here/$iam.out
155 case $agent
157 cisco)
158 cd $_here
159 ./common.install.cisco $iam $agentdir
162 $sudo ./Install </dev/null >>$_here/$iam.out
164 esac
165 cd $_here
166 reinstall=true
167 else
168 echo "Cannot find PMDA directory ($agentdir)"
169 echo "to re-install, ... giving up!"
170 exit 1
174 done
175 done
178 _havelogger()
180 if [ -z "`_get_pids_by_name 'pmlogger.*-P'`" ]
181 then
182 echo "Primary pmlogger not running ..."
183 echo "chkconfig pmlogger on, and restart PMCD"
184 _change_config pmlogger on
185 if sed -e '/^#/d' "${PCP_PMLOGGERCONTROL_PATH}" \
186 | $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1 } END { exit 1-sts }'
187 then
188 : echo "have primary pmlogger line in main control file"
189 elif sed -e '/^#/d' "${PCP_PMLOGGERCONTROL_PATH}.d/local" \
190 | $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1 } END { exit 1-sts }'
191 then
192 : echo "have primary pmlogger line in local control file"
193 else
194 : echo "no primary pmlogger line in control file"
195 if $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1} END { exit 1-sts }' <$PCP_PMLOGGERCONTROL_PATH
196 then
197 : echo uncomment
198 sed <$PCP_PMLOGGERCONTROL_PATH >$tmp.tmp \
199 -e '/^#[^ ][^ ]*[ ][ ]*y/s/#//'
200 $sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH
201 elif $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1} END { exit 1-sts }' <$PCP_PMLOGGERCONTROL_PATH.d/local
202 then
203 : echo uncomment
204 sed <$PCP_PMLOGGERCONTROL_PATH.d/local >$tmp.tmp \
205 -e '/^#[^ ][^ ]*[ ][ ]*y/s/#//'
206 $sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH.d/local
207 else
208 : echo add
209 cp $PCP_PMLOGGERCONTROL_PATH.d/local $tmp.tmp
210 cat >>$tmp.tmp <<'End-of-File'
212 # added by PCP QA
213 LOCALHOSTNAME y n PCP_LOG_DIR/pmlogger/LOCALHOSTNAME -c config.default
214 End-of-File
215 $sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH.d/local
218 $sudo $PCP_RC_DIR/pcp restart
219 _wait_for_pmlogger
223 _haveremote()
225 # ensure critical daemons allow for remote access
227 if test -f "${PCP_SYSCONFIG_DIR}/pmcd"
228 then
229 sed <$PCP_SYSCONFIG_DIR/pmcd >$tmp.tmp \
230 -e '/^PMCD_LOCAL=1/s/^/#/g'
231 diff $PCP_SYSCONFIG_DIR/pmcd $tmp.tmp >/dev/null || \
232 $sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmcd
235 if test -f "${PCP_SYSCONFIG_DIR}/pmproxy"
236 then
237 sed <$PCP_SYSCONFIG_DIR/pmproxy >$tmp.tmp \
238 -e '/^PMPROXY_LOCAL=1/s/^/#/g'
239 diff $PCP_SYSCONFIG_DIR/pmproxy $tmp.tmp >/dev/null || \
240 $sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmproxy
243 if test -f "${PCP_SYSCONFIG_DIR}/pmlogger"
244 then
245 sed <$PCP_SYSCONFIG_DIR/pmlogger >$tmp.tmp \
246 -e '/^PMLOGGER_LOCAL=1/s/^/#/g'
247 diff $PCP_SYSCONFIG_DIR/pmlogger $tmp.tmp >/dev/null || \
248 $sudo cp $tmp.tmp $PCP_SYSCONFIG_DIR/pmlogger
252 _havepmcdtrace()
254 fix=false
255 for trace in traceconn tracepdu
257 bit=`pminfo -h $QA_HOST -f pmcd.control.$trace | sed -n -e '/value/s/ *value *//p'`
258 if [ "X$bit" != X1 ]
259 then
260 pminfo -h $QA_HOST -f pmcd.control.$trace
261 echo "PMCD event tracing not enabled!"
262 fix=true
264 done
265 if $fix
266 then
267 echo "fix options, and restart PMCD"
268 [ -z "PCP_PMCDOPTIONS_PATH" ] && \
269 PCP_PMCDOPTIONS_PATH="$PCP_SYSCONF_DIR/pmcd/pmcd.options"
270 PCPQA_PMCDOPTIONS="$PCP_PMCDOPTIONS_PATH"
271 sed <$PCPQA_PMCDOPTIONS >$tmp.tmp -e '/^-T/s/^/#/'
272 cat >>$tmp.tmp <<'End-of-File'
274 # added by PCP QA
275 -T 3
276 End-of-File
277 $sudo cp $tmp.tmp $PCPQA_PMCDOPTIONS
278 grp=root
279 case $PCP_PLATFORM
281 freebsd|netbsd|openbsd)
282 grp=wheel
284 esac
285 $sudo chown root:$grp $PCPQA_PMCDOPTIONS
286 $sudo $PCP_RC_DIR/pcp restart
287 _wait_for_pmlogger
292 here=`pwd`
293 rm -f $here/$iam.out
294 _setenvironment
296 check=${check-true}
297 quick=${quick-false}
299 # Try and guess what "make" is called ... configure leaves a comment
300 # like this
301 #NB: don't override $(MAKE); gnumake sets it well, propagating -j etc.
302 #MAKE = /usr/local/bin/gmake
303 # in builddefs, so try there ...
305 if [ -f $PCP_INC_DIR/builddefs ]
306 then
307 make=`sed <$PCP_INC_DIR/builddefs -n -e '/^#NB: don.t override \$(MAKE);/{
309 s/.*MAKE[ ]*=[ ]*//p
311 [ -n "$make" ] && export MAKE=$make
314 if $check
315 then
316 if $quick
317 then
319 else
320 if [ -f GNUmakefile.install ]
321 then
322 # running QA in the tree
323 ${MAKE:-make} -f GNUmakefile.install >/tmp/$$.make 2>&1
324 ( cd qt; ./setup-executables )
325 else
326 ${MAKE:-make} >/tmp/$$.make 2>&1
328 if [ $? != 0 ]
329 then
330 cat /tmp/$$.make
331 echo "Warning: ${MAKE:-make} failed -- some tests may be missing"
332 warn=1
334 rm -f /tmp/$$.make
338 diff=diff
339 if [ ! -z "$DISPLAY" ]
340 then
341 which tkdiff >/dev/null 2>&1 && diff=tkdiff
342 which xdiff >/dev/null 2>&1 && diff=xdiff
343 which xxdiff >/dev/null 2>&1 && diff=xxdiff
344 which gdiff >/dev/null 2>&1 && diff=gdiff
347 color=false
348 verbose=false
349 paranoid=false
350 group=false
351 xgroup=false
352 exclude=false
353 rflag=false
354 selbygroup=false
355 snarf=''
356 showme=false
357 sortme=false
358 have_test_arg=false
359 check_config=false
360 rm -f $tmp.list $tmp.tmp $tmp.sed $tmp.exclude
362 for r
365 if $group
366 then
367 selbygroup=true
369 # arg after -g
370 group_list=`
371 if $rflag
372 then
373 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
374 else
375 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
376 fi \
377 | sed -n -e 's/$/ /' -e "/^[0-9][0-9]*.* $r /"'{
378 s/ .*//p
380 if [ -z "$group_list" ]
381 then
382 echo "Group \"$r\" is empty or not defined; ignored" >&2
383 else
384 [ ! -s $tmp.list ] && touch $tmp.list
385 for t in $group_list
387 if grep -s "^$t\$" $tmp.list >/dev/null
388 then
390 else
391 echo "$t" >>$tmp.list
393 done
395 group=false
396 continue
398 elif $xgroup
399 then
400 selbygroup=true
402 # if no test numbers, do everything from group file
403 [ -s $tmp.list ] || \
404 if $rflag
405 then
406 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
407 else
408 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
409 fi \
410 | sed -n -e '/^[0-9]/s/[ ].*//p' >$tmp.list
412 # arg after -x
413 group_list=`
414 if $rflag
415 then
416 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
417 else
418 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
419 fi \
420 | sed -n \
421 -e "/^[0-9].* $r /s/[ ].*//p" \
422 -e "/^[0-9].* $r\$/s/[ ].*//p"`
423 if [ -z "$group_list" ]
424 then
425 echo "Group \"$r\" is empty or not defined; ignored" >&2
426 else
427 numsed=0
428 rm -f $tmp.sed
429 for t in $group_list
431 if [ $numsed -gt 100 ]
432 then
433 sed -f $tmp.sed <$tmp.list >$tmp.tmp
434 mv $tmp.tmp $tmp.list
435 numsed=0
436 rm -f $tmp.sed
438 echo "/^$t\$/d" >>$tmp.sed
439 numsed=`expr $numsed + 1`
440 done
441 sed -f $tmp.sed <$tmp.list >$tmp.tmp
442 mv $tmp.tmp $tmp.list
444 xgroup=false
445 continue
447 elif $exclude
448 then
449 # if no test numbers, do everything from group file
450 [ -s $tmp.list ] || \
451 if $rflag
452 then
453 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
454 else
455 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
456 fi \
457 | sed -n -e '/^[0-9]/s/[ ].*//p' >$tmp.list
459 for t in `echo "$r" | sed -e 's/,/ /g'`
461 echo "/^0*$t\$/d" >>$tmp.exclude
462 echo "/^0*$t:/d" >>$tmp.exclude
463 done
464 exclude=false
465 continue
467 elif [ ! -z "$snarf" ]
468 then
469 case $snarf
472 QA_DIR=$r
475 QA_HOST=$r
478 QA_USER=$r
480 esac
481 snarf=''
482 continue
485 xpand=true
486 range=false
487 case "$r"
490 -\?) # usage
491 echo "Usage: $0 [options] [testlist]"'
493 common options
494 -v verbose
496 check options
497 -c check configuration files [off]
498 -C color mode output [off]
499 -g group include tests from these groups (multiple flags allowed)
500 -G report groups and number of tests per group
501 -l line mode diff [xdiff]
502 -s sssh mode diff [no diff, regular output]
503 -n show me, do not run tests
504 -q quick, no PMDA checks (you are on your own)
505 -r include reserved and retired tests
506 -t turn on tracing
507 -T output timestamps
508 -x group exclude tests from these groups (multiple flags allowed)
509 -X seq[,seq...]
510 exclude these tests
512 show-me options
513 -d QA_DIR [isms/pcp2.0/qa]
514 -h QA_HOST ['`hostname`']
515 -u QA_USER [pcpqa]
517 exit 0
520 -c) # check config files
521 check_config=true
522 xpand=false
525 -C) # color mode for results and summaries
526 color=true
527 xpand=false
530 -d) # directory for show-me
531 snarf=d
532 xpand=false
535 -G) # -G report groups and number of tests per group
536 sed -n -e '/^[a-z]/{
537 s/[ ].*//
539 }' <group >$tmp.group
540 cat $tmp.group
541 echo ===
542 LC_COLLATE=POSIX sort $tmp.group \
543 | while read group
545 num=`
546 if $rflag
547 then
548 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
549 else
550 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
551 fi \
552 | egrep "^[0-9].*[ ]$group([ ]|$)" \
553 | wc -l \
554 | sed -e 's/ //g'`
555 printf "%-20.20s %3d\n" $group $num
556 done
557 exit 0
560 -g) # -g group ... pick from group file
561 group=true
562 xpand=false
565 -h) # host for show-me
566 snarf=h
567 xpand=false
570 -l) # line mode for diff, not gdiff over modems
571 diff=diff
572 xpand=false
575 -n) # show me, don't do it
576 showme=true
577 quick=true
578 xpand=false
581 -q) # "quick", no PMDA checks (you are on your own)
582 quick=true
583 xpand=false
586 -r) # include reserved and retired tests
587 rflag=true
588 xpand=false
591 -s) # sssh mode for diff, no diff at all
592 diff=true
593 xpand=false
596 -t) # turn on tracing
597 qatrace=true
598 xpand=false
601 -T) # turn on timestamp output
602 timestamp=true
603 xpand=false
606 -u) # user for show-me
607 snarf=u
608 xpand=false
612 verbose=true
613 xpand=false
616 -x) # -x group ... exclude from group file
617 xgroup=true
618 xpand=false
621 -X) # -X seq[,seq...] ... exclude explicit tests
622 exclude=true
623 xpand=false
626 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
627 echo "No tests?" >&2
628 status=1
629 exit $status
632 [0-9]*-[0-9]*)
633 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
634 range=true
637 [0-9]*-)
638 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
639 end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/ *$//' -e 's/.* //'`
640 if [ -z "$end" ]
641 then
642 echo "No tests in range \"$r\"?" >&2
643 status=1
644 exit $status
646 range=true
650 start=$r
651 end=$r
654 esac
656 if $xpand
657 then
658 start=`echo $start | sed -e 's/^0*\(.\)/\1/'`
659 end=`echo $end | sed -e 's/^0*\(.\)/\1/'`
660 have_test_arg=true
661 if $rflag
662 then
663 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
664 else
665 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
666 fi >$tmp.group
667 $PCP_AWK_PROG </dev/null '
668 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
669 | while read id
671 # if test not present, silently forget about it
672 [ -f $id ] || continue
673 if egrep -s "^$id([ ]|$)" $tmp.group >/dev/null
674 then
675 # in group file ... OK
676 echo $id >>$tmp.list
677 elif egrep -s "^$id:retired([ ]|$)" group >/dev/null
678 then
679 # in group file, but retired
680 if $rflag
681 then
682 echo $id >>$tmp.list
683 else
684 echo "$id - retired test, ignored"
686 elif egrep -s "^$id:reserved([ ]|$)" group >/dev/null
687 then
688 # in group file, but reserved
689 if $rflag
690 then
691 echo $id >>$tmp.list
692 else
693 echo "$id - reserved test, ignored"
695 else
696 # oops
697 $range || echo "$id - unknown test, ignored"
699 done
702 done
704 if [ -s $tmp.list ]
705 then
706 # found some valid test numbers ... this is good
708 else
709 if $have_test_arg
710 then
711 # had test numbers, but none in group file ... do nothing
712 touch $tmp.list
713 else
714 if $selbygroup
715 then
716 echo "No tests selected?" >&2
717 exit 1
718 else
719 # no test numbers, do everything from group file
720 touch $tmp.list
721 if $rflag
722 then
723 sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
724 else
725 sed -e '/[0-9]:\(retired\|reserved\) /d' <group
726 fi \
727 | sed -n -e '/^[0-9]/{
728 s/[ ].*//
730 }' \
731 | while read id
733 [ -f $id ] || continue
734 echo $id >>$tmp.list
735 done
740 # handle -X exclusions
742 if [ -s $tmp.exclude ]
743 then
744 sed -f $tmp.exclude <$tmp.list >$tmp.tmp
745 mv $tmp.tmp $tmp.list
748 list=`sort -n $tmp.list`
749 rm -f $tmp.list $tmp.tmp $tmp.sed $tmp.exclude
751 # re-process the product-specific setup in case command line args have
752 # changed things, e.g. -h hostname
754 . ./common.setup
756 [ -z "$QA_HOST" ] && QA_HOST=$DEFAULT_HOST
757 export QA_HOST QA_DIR QA_USER
759 if $check
760 then
761 x=`pminfo -h $QA_HOST -v pmcd.control.timeout 2>&1`
762 if [ ! -z "$x" ]
763 then
764 echo "Is pmcd running on host $QA_HOST? Simple test produces ..."
765 echo "$x"
766 exit 1
770 case $iam
772 show-me)
773 # don't need sudo
777 _havesudo
779 esac
781 case $iam
783 check|remake)
784 # $PCP_RC_DIR/pcp needs this to produce deterministic output now
786 _change_config verbose on
788 esac
790 if $quick
791 then
793 else
794 ./mk.localconfig
796 $OPTION_AGENTS && _haveagents
797 $OPTION_LOGGER && _havelogger
798 $OPTION_REMOTE && _haveremote
799 $OPTION_PMCD_TRACE && _havepmcdtrace
801 if [ -f GNUmakefile.install ]
802 then
803 # running QA in the tree
804 ${MAKE:-make} -f GNUmakefile.install setup
805 cd pmdas
806 if ${MAKE:-make} -f GNUmakefile.install setup >$tmp.tmp 2>&1
807 then
809 else
810 cat $tmp.tmp
811 echo "Warning: pmdas: $MAKE -f GNUmakefile.install setup failed"
813 cd broken
814 if ${MAKE:-make} -f GNUmakefile.install broken_v2.dir >$tmp.tmp 2>&1
815 then
817 else
818 cat $tmp.tmp
819 echo "Warning: pmdas/broken: $MAKE -f GNUmakefile.install broken_v2.dir failed"
821 cd ../..
822 else
823 ${MAKE:-make} setup
825 if [ $? != 0 ]
826 then
827 echo "Error: ${MAKE:-make} setup failed"
828 exit 1
831 # since pmcd no longer runs as root, normal users must be able
832 # to read all dirs on the path to the qa home ...
834 x=`pwd`
835 while [ -n "$x" -a "$x" != / ]
837 prot=`ls -ldL "$x" | sed -e 's/[ ].*//'`
838 case $prot
840 dr?xr?xr?[xt]*)
843 echo "Warning: parent directory $x (mode=$prot) not world readable and searchable"
845 esac
846 x=`dirname $x`
847 done