File: common

package info (click to toggle)
pcp 3.9.10
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 81,836 kB
  • ctags: 26,423
  • sloc: ansic: 178,791; sh: 79,349; cpp: 61,042; xml: 28,842; perl: 12,963; yacc: 5,351; python: 4,578; lex: 1,894; makefile: 1,665; fortran: 60; java: 22; awk: 20
file content (761 lines) | stat: -rwxr-xr-x 15,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
#!/bin/sh
#
# common procedures for PCP QA scripts
#
# Copyright (c) 1997-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

# for _wait_for_pmlogger() and _change_config()
. ./common.check 

# per product QA script customization
#
. ./common.setup
[ -z "$DEFAULT_HOST" ] && DEFAULT_HOST=`hostname`

_setenvironment()
{
    MSGVERB="text:action"
    export MSGVERB
    export PCP_BINADM_DIR
}

_log_fyi()
{
    echo "FYI ... here are the PMCD logs"
    for log
    do
	if [ ! -f $log ]
	then
	    # try in the other place
	    #
	    case $log
	    in
		$PCP_LOG_DIR/pmcd/*)
		    __try=`echo $log | sed -e "s;/pmcd/;/;"`
		    ;;
		*)
		    __try=`echo $log | sed -e "s;$PCP_LOG_DIR/;$PCP_LOG_DIR/pmcd/;"`
		    ;;
	    esac
	    [ -f $__try ] && log=$__try
	fi
	if [ -f $log ]
	then
	    echo ":::::::::  start $log  ::::::::"
	    cat $log
	    echo "::::::::::  end $log  :::::::::"
	    
	    [ $log != $PCP_LOG_DIR/pmcd/pmcd.log ] && $sudo rm -f $log
	else
	    echo "$log: not found"
	fi
    done
}

_havesudo()
{
    if [ -z "$PCP_DIR" ]
    then
	setuid=`$sudo id | sed -e 's/(.*//' -e 's/.*=//'`
	if [ "$setuid" != 0 ]
	then
	    echo "\"sudo\" is not an executable setuid root. This is fatal."
	    echo "As root, you need to setup your sudoers file for pcpqa."
	    exit 1
	fi
    fi
}

_haveagents()
{
    restart=false
    here=`pwd`

    # PMDAs than need to be here for QA
    #
    COMMON_PMDAS="sample sampledso simple"
    if [ -d $PCP_PMDAS_DIR/cisco ]
    then
	# cisco PMDA requires that you can reach a router
	#
	if which ping >/dev/null 2>&1
	then
	    #  Note: PCP_QA_CISCOROUTER needs to be defined in common.rc
	    if ping -c 1 $PCP_QA_CISCOROUTER >/dev/null 2>&1
	    then
		COMMON_PMDAS="$COMMON_PMDAS cisco"
	    fi
	fi
    fi

    for agent in $COMMON_PMDAS
    do
	probe=$agent
	agentlog=$PCP_LOG_DIR/pmcd/$agent.log

	# make this empty to stop any attempt to reinstall
	#
	agentdir=$PCP_PMDAS_DIR/$agent

	case $agent
	in
	    cisco)
		probe=cisco.bytes_in
		;;
	    sample)
		probe=sample.milliseconds
		;;
	    sampledso)
		probe=sampledso.milliseconds
		agentdir=$PCP_PMDAS_DIR/sample
		;;
	    simple)
		probe=simple.numfetch
		;;
	    weblog)
		probe=web.allservers.numalive
		;;
	    webping)
		probe=webping.count
		;;
	    oracle)
		eval "probe=oracle.$ORACLE_SID.version"
		eval "agentlog=$PCP_LOG_DIR/pmcd/oracle-$ORACLE_SID.log"
		agentdir=''
		;;
	    oraping)
		probe=oraping.control.count
		;;
	esac
	reinstall=false
	while true
	do
	    [ $diff = true ] || echo "PMDA probe: pminfo -h $QA_HOST -f $probe"
	    if pminfo -h $QA_HOST -f $probe 2>&1 \
	       | tail -1 \
	       | egrep "^[ 	]*((value)|(inst))[ 	]" >/dev/null
	    then
		break
	    else
		echo "PMDA $agent is not responding"
		if $restart
		then
		    :
		else
		    _log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $agentlog
		    echo "Restarting PMCD ..."
		    $sudo $PCP_RC_DIR/pcp restart
		    restart=true
		fi
		if $reinstall
		then
		    [ -f $here/$iam.out ] && cat $here/$iam.out
		    echo "Cannot make PMDA $agent work, ... giving up!"
		    exit 1
		else
		    if [ -z "$agentdir" ]
		    then
			echo "Skip PMDA re-install"
			break
		    elif [ -d "$agentdir" ]
		    then
			echo "Trying to re-install PMDA $agent from $agentdir ..."
			_log_fyi $PCP_LOG_DIR/pmcd/pmcd.log $agentlog
			cd $agentdir
			unset ROOT TOOLROOT MAKEFLAGS
			$sudo ./Remove </dev/null >>$here/$iam.out
			case $agent
			in
			    cisco)
				cd $here
				./common.install.cisco $iam $agentdir
				;;
			    *)
				$sudo ./Install </dev/null >>$here/$iam.out
				;;
			esac
			cd $here
			reinstall=true
		    else
			echo "Cannot find PMDA directory ($agentdir)"
			echo "to re-install, ... giving up!"
			exit 1
		    fi
		fi
	    fi
	done
    done
}

_havelogger()
{
    if [ -z "`_get_pids_by_name 'pmlogger.*-P'`" ]
    then
	echo "Primary pmlogger not running ..."
	echo "chkconfig pmlogger on, and restart PMCD"
	_change_config pmlogger on
	[ -z "$PCP_PMLOGGERCONTROL_PATH" ] && \
		PCP_PMLOGGERCONTROL_PATH="$PCP_SYSCONF_DIR/pmlogger/control"
	if sed -e '/^#/d' "$PCP_PMLOGGERCONTROL_PATH" \
	   | $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1 } END { exit 1-sts }'
	then
	    : echo "have primary pmlogger line in control file"
	else
	    : echo "no primary pmlogger line in control file"
	    if $PCP_AWK_PROG '$2 == "y" && $3 == "n" { sts=1} END { exit 1-sts }' <$PCP_PMLOGGERCONTROL_PATH
	    then
		: echo uncomment
		sed <$PCP_PMLOGGERCONTROL_PATH >$tmp.tmp \
		    -e '/^#[^ 	][^ 	]*[ 	][ 	]*y/s/#//'
		$sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH
	    else
	    	: echo add
		cp $PCP_PMLOGGERCONTROL_PATH $tmp.tmp
		if [ -e $PCP_LOG_DIR/pmlogger ]
		then
		    cat >>$tmp.tmp <<'End-of-File'

# added by PCP QA
LOCALHOSTNAME	y   n	PCP_LOG_DIR/pmlogger/LOCALHOSTNAME	-c config.default
End-of-File
		else
		    cat >>$tmp.tmp <<'End-of-File'

# added by PCP QA
LOCALHOSTNAME	y   n	PCP_LOG_DIR/LOCALHOSTNAME	-c config.default
End-of-File
		fi
		$sudo cp $tmp.tmp $PCP_PMLOGGERCONTROL_PATH
	    fi
	fi
	$sudo $PCP_RC_DIR/pcp restart
	_wait_for_pmlogger
    fi
}

_havepmcdtrace()
{
    fix=false
    for trace in traceconn tracepdu
    do
	bit=`pminfo -h $QA_HOST -f pmcd.control.$trace | sed -n -e '/value/s/ *value *//p'`
	if [ "X$bit" != X1 ]
	then
	    pminfo -h $QA_HOST -f pmcd.control.$trace
	    echo "PMCD event tracing not enabled!"
	    fix=true
	fi
    done
    if $fix
    then
	echo "fix options, and restart PMCD"
	[ -z "PCP_PMCDOPTIONS_PATH" ] && \
	      PCP_PMCDOPTIONS_PATH="$PCP_SYSCONF_DIR/pmcd/pmcd.options"
	PCPQA_PMCDOPTIONS="$PCP_PMCDOPTIONS_PATH"
	sed <$PCPQA_PMCDOPTIONS >$tmp.tmp -e '/^-T/s/^/#/'
	cat >>$tmp.tmp <<'End-of-File'

# added by PCP QA
-T 3
End-of-File
	$sudo cp $tmp.tmp $PCPQA_PMCDOPTIONS
	$sudo $PCP_RC_DIR/pcp restart
	_wait_for_pmlogger
    fi

}

here=`pwd`
rm -f $here/$iam.out
_setenvironment

check=${check-true}
quick=${quick-false}

# Try and guess what "make" is called ... configure leaves a comment
# like this
#NB: don't override $(MAKE); gnumake sets it well, propagating -j etc.
#MAKE	= /usr/local/bin/gmake
# in builddefs, so try there ...
#
if [ -f $PCP_INC_DIR/builddefs ]
then
    make=`sed <$PCP_INC_DIR/builddefs -n -e '/^#NB: don.t override \$(MAKE);/{
N
s/.*MAKE[ 	]*=[ 	]*//p
}'`
    [ -n "$make" ] && export MAKE=$make
fi

if $check
then
    if $quick
    then
	:
    else
	if [ -f GNUmakefile.install ]
	then
	    # running QA in the tree
	    ${MAKE:-make} -f GNUmakefile.install >/tmp/$$.make 2>&1
	    ( cd qt; ./setup-executables )
	else
	    ${MAKE:-make} >/tmp/$$.make 2>&1
	fi
	if [ $? != 0 ]
	then
	    cat /tmp/$$.make
	    echo "Warning: ${MAKE:-make} failed -- some tests may be missing"
	    warn=1
	fi
	rm -f /tmp/$$.make
    fi
fi

diff=diff
if [ ! -z "$DISPLAY" ]
then
    which tkdiff >/dev/null 2>&1 && diff=tkdiff
    which xdiff >/dev/null 2>&1 && diff=xdiff
    which xxdiff >/dev/null 2>&1 && diff=xxdiff
    which gdiff >/dev/null 2>&1 && diff=gdiff
fi

color=false
verbose=false
paranoid=false
group=false
xgroup=false
rflag=false
selbygroup=false
snarf=''
showme=false
sortme=false
have_test_arg=false
check_config=false
rm -f $tmp.list $tmp.tmp $tmp.sed

for r
do

    if $group
    then
    	selbygroup=true

	# arg after -g
	group_list=`
	if $rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n -e 's/$/ /' -e "/^[0-9][0-9]*.* $r /"'{
s/ .*//p
}'`
	if [ -z "$group_list" ]
	then
	    echo "Group \"$r\" is empty or not defined; ignored" >&2
	else
	    [ ! -s $tmp.list ] && touch $tmp.list
	    for t in $group_list
	    do
		if grep -s "^$t\$" $tmp.list >/dev/null
		then
		    :
		else
		    echo "$t" >>$tmp.list
		fi
	    done
    	fi
	group=false
	continue

    elif $xgroup
    then
    	selbygroup=true

	# if no test numbers, do everything from group file
	[ -s $tmp.list ] || \
	if $rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n -e '/^[0-9]/s/[ 	].*//p' >$tmp.list

	# arg after -x
	group_list=`
	if $rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi \
	| sed -n \
	    -e "/^[0-9].* $r /s/[ 	].*//p" \
	    -e "/^[0-9].* $r\$/s/[ 	].*//p"`
	if [ -z "$group_list" ]
	then
	    echo "Group \"$r\" is empty or not defined; ignored" >&2
	else
	    numsed=0
	    rm -f $tmp.sed
	    for t in $group_list
	    do
		if [ $numsed -gt 100 ]
		then
		    sed -f $tmp.sed <$tmp.list >$tmp.tmp
		    mv $tmp.tmp $tmp.list
		    numsed=0
		    rm -f $tmp.sed
		fi
		echo "/^$t\$/d" >>$tmp.sed
		numsed=`expr $numsed + 1`
	    done
	    sed -f $tmp.sed <$tmp.list >$tmp.tmp
	    mv $tmp.tmp $tmp.list
    	fi
	xgroup=false
	continue

    elif [ ! -z "$snarf" ]
    then
	case $snarf
	in
	    d)
		QA_DIR=$r
		;;
	    h)
		QA_HOST=$r
		;;
	    u)
		QA_USER=$r
		;;
	esac
	snarf=''
	continue
    fi

    xpand=true
    range=false
    case "$r"
    in

	-\?)	# usage
	    echo "Usage: $0 [options] [testlist]"'

common options
    -v			verbose

check options
    -c		check configuration files [off]
    -C		color mode output [off]
    -g group	include tests from these groups (multiple flags allowed)
    -G          report groups and number of tests per group
    -l		line mode diff [xdiff]
    -s		sssh mode diff [no diff, regular output]
    -n		show me, do not run tests
    -q		quick, no PMDA checks (you are on your own)
    -r		include reserved and retired tests
    -t		turn on tracing
    -T		output timestamps
    -x group	exclude tests from these groups (multiple flags allowed)

show-me options
    -d QA_DIR		[isms/pcp2.0/qa]
    -h QA_HOST		['`hostname`']
    -u QA_USER		[pcpqa]
'
	    exit 0
	    ;;

	-c)	# check config files
	    check_config=true
	    xpand=false
	    ;;

	-C)	# color mode for results and summaries
	    color=true
	    xpand=false
	    ;;

	-d)	# directory for show-me
	    snarf=d
	    xpand=false
	    ;;

	-G)	# -G report groups and number of tests per group
	    sed -n -e '/^[a-z]/{
s/[ 	].*//
p
}' <group >$tmp.group
	    cat $tmp.group
	    echo ===
	    LC_COLLATE=POSIX sort $tmp.group \
	    | while read group
	    do
		num=`
		    if $rflag
		    then
			sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
		    else
			sed -e '/[0-9]:\(retired\|reserved\) /d' <group
		    fi \
		    | egrep "^[0-9].*[ 	]$group([ 	]|$)" \
		    | wc -l \
		    | sed -e 's/ //g'`
		printf "%-20.20s %3d\n" $group $num
	    done
	    exit 0
	    ;;

	-g)	# -g group ... pick from group file
	    group=true
	    xpand=false
	    ;;

	-h)	# host for show-me
	    snarf=h
	    xpand=false
	    ;;

	-l)	# line mode for diff, not gdiff over modems
	    diff=diff
	    xpand=false
	    ;;

	-n)	# show me, don't do it
	    showme=true
	    quick=true
	    xpand=false
	    ;;

	-q)	# "quick", no PMDA checks (you are on your own)
	    quick=true
	    xpand=false
	    ;;

	-r)	# include reserved and retired tests
	    rflag=true
	    xpand=false
	    ;;

	-s)	# sssh mode for diff, no diff at all 
	    diff=true
	    xpand=false
	    ;;

	-t)	# turn on tracing
	    qatrace=true
	    xpand=false
	    ;;

	-T)	# turn on timestamp output
	    timestamp=true
	    xpand=false
	    ;;

	-u)	# user for show-me
	    snarf=u
	    xpand=false
	    ;;

	-v)
	    verbose=true
	    xpand=false
	    ;;

	-x)	# -x group ... exclude from group file
	    xgroup=true
	    xpand=false
	    ;;

	'[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
	    echo "No tests?" >&2
	    status=1
	    exit $status
	    ;;

	[0-9]*-[0-9]*)
	    eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
	    range=true
	    ;;

	[0-9]*-)
	    eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
	    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/.* //'`
	    if [ -z "$end" ]
	    then
		echo "No tests in range \"$r\"?" >&2
		status=1
		exit $status
	    fi
	    range=true
	    ;;

	*)
	    start=$r
	    end=$r
	    ;;

    esac

    if $xpand
    then
	start=`echo $start | sed -e 's/^0*\(.\)/\1/'`
	end=`echo $end | sed -e 's/^0*\(.\)/\1/'`
	have_test_arg=true
	if $rflag
	then
	    sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	else
	    sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	fi >$tmp.group
	$PCP_AWK_PROG </dev/null '
BEGIN	{ for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
	| while read id
	do
	    # if test not present, silently forget about it
	    [ -f $id ] || continue
	    if egrep -s "^$id([ 	]|$)" $tmp.group >/dev/null
	    then
		# in group file ... OK
		echo $id >>$tmp.list
	    elif egrep -s "^$id:retired([ 	]|$)" group >/dev/null
	    then
		# in group file, but retired
		echo "$id - retired test, ignored"
	    elif egrep -s "^$id:reserved([ 	]|$)" group >/dev/null
	    then
		# in group file, but reserved
		echo "$id - reserved test, ignored"
	    else
		# oops
		$range || echo "$id - unknown test, ignored"
	    fi
	done
    fi

done

if [ -s $tmp.list ]
then
    # found some valid test numbers ... this is good
    :
else
    if $have_test_arg
    then
	# had test numbers, but none in group file ... do nothing
	touch $tmp.list
    else
	if $selbygroup
    	then
    	    echo "No tests selected?" >&2
    	    exit 1
    	else
	    # no test numbers, do everything from group file
	    touch $tmp.list
	    if $rflag
	    then
		sed -e 's/\([0-9]\):\(retired\|reserved\) /\1 /' <group
	    else
		sed -e '/[0-9]:\(retired\|reserved\) /d' <group
	    fi \
	    | sed -n -e '/^[0-9]/{
s/[ 	].*//
p
}' \
	    | while read id
	    do
		[ -f $id ] || continue
		echo $id >>$tmp.list
	    done
    	fi
    fi
fi

list=`sort -n $tmp.list`
rm -f $tmp.list $tmp.tmp $tmp.sed

# re-process the product-specific setup in case command line args have
# changed things, e.g. -h hostname
#
. ./common.setup

[ -z "$QA_HOST" ] && QA_HOST=$DEFAULT_HOST
export QA_HOST QA_DIR QA_USER

if $check
then
    x=`pminfo -h $QA_HOST -v pmcd.control.timeout 2>&1`
    if [ ! -z "$x" ]
    then
	echo "Is pmcd running on host $QA_HOST?  Simple test produces ..."
	echo "$x"
	exit 1
    fi
fi

case $iam
in
    show-me)
	# don't need sudo
	;;
    *)

	_havesudo
	;;
esac

case $iam
in
    check|remake)
	# $PCP_RC_DIR/pcp needs this to produce deterministic output now
	#
	_change_config verbose on
	;;
esac

if $quick
then
    :
else
    ./mk.localconfig

    $OPTION_AGENTS && _haveagents
    $OPTION_LOGGER && _havelogger
    $OPTION_PMCD_TRACE && _havepmcdtrace

    if [ -f GNUmakefile.install ]
    then
	# running QA in the tree
	${MAKE:-make} -f GNUmakefile.install setup
    else
	${MAKE:-make} setup
    fi
    if [ $? != 0 ]
    then
	echo "Error: ${MAKE:-make} setup failed"
	exit 1
    fi

    # since pmcd no longer runs as root, normal users must be able
    # to read all dirs on the path to the qa home ...
    #
    x=`pwd`
    while [ -n "$x" -a "$x" != / ]
    do
	prot=`ls -ld "$x" | sed -e 's/[ 	].*//'`
	case $prot
	in
	    dr?xr?xr?[xt]*)
		;;
	    *)
		echo "Warning: parent directory $x (mode=$prot) not world readable and searchable"
		;;
	esac
	x=`dirname $x`
    done
fi