pmrep: fix archive end time reporting
[pcp.git] / qa / 430
blob2674b67d42432b6abcf8cf51348a1796abf38018
1 #! /bin/sh
2 # PCP QA Test No. 430
4 # Test out pmlogger_check with duplicate directory names
5 # Test out pmlogger_check with directory names where one is a subname
6 # of the other.
8 # Note:
9 # This test assumes 127.0.0.2 is available ... for some platforms
10 # this may not be the case, e.g. Mac OS X, where it is necessary
11 # to arrange for the command below to be run in the reboot
12 # sequence ...
13 # # ifconfig lo0 alias 127.0.0.2
15 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
18 seq=`basename $0`
19 echo "QA output created by $seq"
21 # get standard filters
22 . ./common.product
23 . ./common.filter
24 . ./common.check
26 rm -f $seq.full
28 realhost=`hostname`
29 LOCALHOST=`echo $realhost | sed -e 's/\..*//'`
30 hostsfile="/etc/hosts"
31 egrep '^[^#].*[ ]'$realhost'([ ]|$)' <$hostsfile >/dev/null || \
32 _notrun "No entry for hostname of local host in $hostsfile"
34 signal="$sudo $PCP_BINADM_DIR/pmsignal"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 _filter()
40 sed \
41 -e 's/\.\.\.*/[dots]/' \
42 -e "s/$realhost/LOCALHOST/g" \
43 -e "s/$LOCALHOST/LOCALHOST/g" \
44 -e "s/local:/LOCALHOST/g" \
45 -e 's/control:[0-9][0-9]*]/control:LINE]/' \
46 -e 's/control.d\/*:[0-9][0-9]*]/control:LINE]/' \
47 -e 's;/usr/var;/var;g' \
48 -e "s;$tmp;TMP;g" \
49 -e '/Duplicate/d' \
50 -e 's/process [0-9][0-9]*/process PID/' \
51 -e '/[0-9] inode=/d' \
52 -e 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]/CHECK/' \
53 | _filter_cron_scripts
56 _stop_loggers()
58 $signal -a -s TERM pmlogger >/dev/null 2>&1
61 _cleanup()
63 echo
64 echo "Cleaning up"
66 if [ -f $tmp.etc.hosts.orig ]
67 then
68 $sudo cp $tmp.etc.hosts.orig $hostsfile
71 _stop_loggers
73 cd # get out of tmp directory so we can delete it
74 $sudo rm -rf $tmp $tmp.*
76 $sudo $PCP_BINADM_DIR/pmlogger_check
79 _setup()
81 _stop_loggers
83 $sudo rm -rf $logdir $logdir2
84 mkdir $logdir $logdir2
85 chmod ugo+w $logdir $logdir2
88 # This relies on 127.0.0.x being an alias for 127.0.0.1
89 # Also, place our real hostname entry first, then the
90 # 127.0.0.x alias so that the reverse hostname lookup in
91 # pmlogger gets the same hostname for the portmap files
92 # as the -h from the command line
94 _update_hostsfile()
96 extra_hostname=$1
98 # save old hosts file
99 $sudo cp $hostsfile $tmp.etc.hosts.orig
101 # update /etc/hosts
102 # add an entry for extra_hostname
103 rm -f $tmp.etc.hosts
104 for i in 2 3 4 5 6 7 8 9
106 if grep "^127.0.0.$i" $hostsfile >/dev/null
107 then
109 else
110 echo "# Hacked for QA/$seq" >$tmp.etc.hosts
111 echo "#" >>$tmp.etc.hosts
112 egrep '^[^#].*[ ]'$realhost'([ ]|$)' <$hostsfile >$tmp.tmp
113 if [ `wc -l <$tmp.tmp | sed -e 's/ *//g'` -ne 1 ]
114 then
115 echo "Updating $hostsfile failed: no single $realhost entry: (see $seq.full):"
116 echo "=== $hostsfile ===" >>$here/$seq.full
117 cat $hostsfile >>$here/$seq.full
118 echo "grep $realhost ..." >>$here/$seq.full
119 cat $tmp.tmp >>$here/$seq.full
120 exit
122 cat $tmp.tmp >>$tmp.etc.hosts
123 echo "127.0.0.$i $extra_hostname" >>$tmp.etc.hosts
124 echo "" >>$tmp.etc.hosts
125 egrep -v '^[^#].*[ ]'$realhost'([ ]|$)' <$hostsfile >>$tmp.etc.hosts
126 break
128 done
130 # extra check
131 # we expect to make a change!
132 if [ -s $tmp.etc.hosts ]
133 then
134 # create new hosts file
135 $sudo cp $tmp.etc.hosts $hostsfile
136 else
137 echo "Updating $hostsfile failed: no 127.0.0.x available: (see $seq.full):"
138 echo "=== $hostsfile ===" >>$here/$seq.full
139 cat $hostsfile >>$here/$seq.full
140 exit
144 _extract_control()
146 id=$1
148 #preamble
149 cat - <<EOF
150 # PCP archive logging configuration/control - for qa/$seq
152 \$version=1.1
156 $PCP_AWK_PROG < $tmp.control -v id=$id '
157 $1 == "#" && $2 == id"." {
158 mode=1;
159 print;
160 next;
162 mode == 1 && $1 == "#" && $2 ~ /[0-9][0-9]*\./ {
163 # found next item so exit
164 exit;
166 mode == 1 {
167 print;
168 next;
173 # real QA test starts here
174 rm -f $here/$seq.full
176 host1=$LOCALHOST
177 host2=$LOCALHOST"super"
178 echo "host1=$host1" >>$here/$seq.full
179 echo "host2=$host2" >>$here/$seq.full
180 _update_hostsfile $host2
181 echo "=== $hostsfile ===" >>$here/$seq.full
182 cat $hostsfile >>$here/$seq.full
183 echo "=== check pcp on $host2 ===" >>$here/$seq.full
184 pcp -h $host2 >>$here/$seq.full
186 logdir=$tmp
187 logdir2="$tmp.subname"
191 # This global file should be extended to do more control
192 # file tests.
193 # Make sure you put the number in the form "# 3. "
195 cat > $tmp.control <<EOF
197 # 1. Test duplicate directory names; non-primary and then primary
199 LOCALHOSTNAME n n $logdir -c $logdir/config
200 LOCALHOSTNAME y n $logdir -c $logdir/config
202 # 2. Test duplicate directory names ; primary and then non-primary
204 LOCALHOSTNAME y n $logdir -c $logdir/config
205 LOCALHOSTNAME n n $logdir -c $logdir/config
207 # 3. Test directory names which are subnames
209 LOCALHOSTNAME y n $logdir2 -c $logdir/config
210 LOCALHOSTNAME n n $logdir -c $logdir/config
212 # 4. Test when have hosts which are subnames
214 $host1 y n $logdir/$host1 -c $logdir/config
215 $host2 n n $logdir/$host2 -c $logdir/config
217 # 5. Putting all the cases together
219 LOCALHOSTNAME y n $logdir.1 -c $logdir/config
220 LOCALHOSTNAME n n $logdir.2 -c $logdir/config
221 $host1 n n $logdir.3 -c $logdir/config
222 $host1 n n $logdir.4 -c $logdir/config
223 $host2 n n $logdir.5 -c $logdir/config
224 $host2 n n $logdir.6 -c $logdir/config
227 # which tests to try out
228 test_set="1 2 3 4 5"
230 for i in $test_set
232 echo >>$here/$seq.full
233 echo "=== test $i ===" >>$here/$seq.full
234 _setup
236 # create the control file from master
237 _extract_control $i > $logdir/control
238 echo "--- control ---" >>$here/$seq.full
239 cat $logdir/control >>$here/$seq.full
241 # let's see what control file we are using
242 echo
243 _filter < $logdir/control
244 echo
246 echo "log mandatory on once pmcd.control.debug" >$logdir/config
247 echo "--- pmlogger_check ---" >> $here/$seq.full
248 $sudo $PCP_BINADM_DIR/pmlogger_check -V -c $logdir/control -l $tmp.log
249 $sudo cat $tmp.log | tee -a $here/$seq.full | _filter
250 done
252 echo | tee -a $here/$seq.full
253 echo "Restart tests while other pmloggers are running ..." | tee -a $here/$seq.full
255 # now for the 5. case, terminate the pmloggers one at a time and
256 # check the pmlogger_check restarts the right one
258 for log in $logdir.1 $logdir.2 $logdir.3 $logdir.4 $logdir.5 $logdir.6
260 echo | tee -a $here/$seq.full
261 echo "Kill off one pmlogger ..." | tee -a $here/$seq.full
262 pid=`grep -l $log $PCP_TMP_DIR/pmlogger/[0-9]* | sed -e 's/.*pmlogger.//'`
263 try=1
264 num_pid=`echo "$pid" | wc -w | sed -e 's/ *//g'`
265 while [ $try -lt 10 -a $num_pid -ne 1 ]
267 echo "try $try num_pid=$num_pid: `echo $pid`" >>$here/$seq.full
268 sleep 1
269 pid=`grep -l $log $PCP_TMP_DIR/pmlogger/[0-9]* | sed -e 's/.*pmlogger.//'`
270 num_pid=`echo "$pid" | wc -w | sed -e 's/ *//g'`
271 try=`expr $try + 1`
272 done
273 if [ $num_pid -ne 1 ]
274 then
275 echo "Arrgh ... failed to find just one pmlogger to kill ... see $seq.full"
276 echo "" >>$here/$seq.full
277 echo "Arrgh ... failed to find just one pmlogger to kill ..." >>$here/$seq.full
278 $PCP_PS_PROG $PCP_PS_ALL_FLAGS | egrep 'PID|[p]mlogger' >>$here/$seq.full
279 echo "$log contents ..." >>$here/$seq.full
280 ls -l $log >>$here/$seq.full
281 for ctl in $PCP_TMP_DIR/pmlogger/[0-9]*
283 echo "+++ $ctl +++" >>$here/$seq.full
284 cat $ctl >>$here/$seq.full
285 done
286 echo "+ grep -l $log"' $PCP_TMP_DIR/pmlogger/[0-9]*' >>$here/$seq.full
287 grep $log $PCP_TMP_DIR/pmlogger/[0-9]* >>$here/$seq.full
288 exit
290 echo "Victim pid=$pid" >>$here/$seq.full
291 $PCP_PS_PROG $PCP_PS_ALL_FLAGS \
292 | $PCP_AWK_PROG >>$here/$seq.full '
293 NR == 1 { print
294 if ($2 != "PID") {
295 print "PID not in field 2 of ps output!"
296 exit(1)
298 next
300 $2 == '"$pid"' { print; exit(0) }'
301 echo "+++ $PCP_TMP_DIR/pmlogger/$pid +++" >>$here/$seq.full
302 cat $PCP_TMP_DIR/pmlogger/$pid >>$here/$seq.full
303 $signal -s TERM $pid
304 echo "Check ..." | tee -a $here/$seq.full
305 $sudo $PCP_BINADM_DIR/pmlogger_check -V -V -c $logdir/control -l $tmp.log
306 $sudo cat $tmp.log \
307 | tee -a $here/$seq.full \
308 | sed -e '/^... try /d' \
309 | _filter
311 done
313 # success, all done
314 status=0
315 exit