Merge branch 'master' of https://github.com/kmcdonell/pcp into kenj-merge
[pcp.git] / qa / 244
blob1059df0edca5a5e0c5f2f7887d1d2038eb7fb6b7
1 #! /bin/sh
2 # PCP QA Test No. 244
3 # PMCD SIGHUP processing tests with $PCP_PMCDCONF_PATH changes
5 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get standard filters
12 . ./common.product
13 . ./common.filter
14 . ./common.check
16 _get_libpcp_config
17 rm -f $seq.out
18 if $ipv6 ; then
19 ln $seq.out.ipv6 $seq.out || exit 1
20 else
21 ln $seq.out.nonipv6 $seq.out || exit 1
24 _filter_log()
26 sleep 3
27 _filter_pmcd_log <./pmcd.log \
28 | sed \
29 -e '/^DATA: from client/d' \
30 -e '/cmd=.*pmdasample/s//cmd=...pmdasample/' \
31 -e 's/ \[(nil)]//' \
32 -e 's/Cannot open 000000660066: No such file or directory//' \
33 -e 's/^$//' \
34 -e '/^00[08]:/d' \
35 -e '/pmGetPDU/{
36 s/\[[0-9][0-9]*]/[PID]/
37 s/from=.*/from=PID/
38 }' \
39 -e '/_pmHaveMoreInput/{
40 s/\[[0-9][0-9]*]/[PID]/
41 s/0x[^ ]*\([^ ][^ ][^ ]\)/ADDR...\1/
42 }' \
43 -e '/Piggy-back/{
44 s/0x[^ ]*\([^ ][^ ][^ ]\)/ADDR...\1/
45 s/from=.*/from=PID/
46 }' \
47 -e '/pmXmitPDU/s/\[[0-9][0-9]*]/[PID]/' \
48 -e '/pmResult/s/ .* numpmid/ ... numpmid/' \
49 -e '/value /{
50 s/value [0-9][0-9]*/value INTEGER/
51 }' \
52 -e 's;pcp/lib/mips_[^.]*\.;pcp/lib/ISA.;' \
53 -e '/access violation from host/d' \
54 -e '/endclient client.* No permission/d' \
55 -e 's/fd=[0-9][0-9]*/fd=FD/g' \
56 -e "/sed: couldn't flush stdout: Broken pipe/d" \
57 -e '/UNIX_DOMAIN_SOCKET/d' \
58 -e '/unix:/d' \
59 | $PCP_AWK_PROG '
60 $3 ~ /^[0-9][0-9]*$/ { $3 = "A_PID" }
61 $1 == "news" { $4 = "fd_in"; $5 = "fd_out" }
62 $1 == "cisco" { $4 = "fd_in"; $5 = "fd_out"
63 for (i = 9; i <= NF; i++) {
64 # cull args like wanfoo:s0 or wanbar:e1
65 if ($i ~ /:[a-z]/) $i = ""
68 /pipe cmd=/ { $4 = "FD"; $5 = "FD" }
69 /Host access list:/ { localHostPrinted = 0 }
70 /localhost/ { if (! localHostPrinted) {
71 localHostPrinted = 1
72 sub(/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/,"MYIPADDR",$5)
73 sub(/^[0-9a-f:][0-9a-f:]*%[0-9a-z]+$/,"MYIPADDR",$5)
74 sub(/^[0-9a-f:][0-9a-f:]*$/,"MYIPADDR",$5)
75 sub(/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/,"MYHOSTMASK",$6)
76 sub(/^[0-9a-f:][0-9a-f:]*$/,"MYHOSTMASK",$6)
78 else next
80 { print }' \
81 | _filter_optional_pmdas \
82 | sed \
83 -e 's/_o32/_SIZE/' \
84 -e 's/_n32/_SIZE/' \
85 -e 's/_64/_SIZE/' \
86 -e "s;$here/src/;;" \
87 -e '/Cleanup "fake_linux" agent (dom 60): unconfigured/q' \
88 #end
91 CONFIG=$PCP_PMCDCONF_PATH
92 NEWCONFIG=$tmp/pmcd.conf
93 CONFIGSAVE=$tmp/pmcd.conf.save
94 [ -z "$PCP_PMLOGGERCONTROL_PATH" ] && \
95 PCP_PMLOGGERCONTROL_PATH="$PCP_SYSCONF_DIR/pmlogger/control"
96 LOGCONTROL=$PCP_PMLOGGERCONTROL_PATH
97 SAVE_LOGCONTROL=$tmp/control.save
98 signal="$sudo $PCP_BINADM_DIR/pmsignal"
99 _needclean=true
100 status=1
102 # for local PMNS to avoid conflict with pmcd tests
104 NAMESPACE="-n $here/src/root_irix"
106 rm -rf $tmp $tmp.*
107 mkdir $tmp
108 chmod ugo+rwx $tmp
109 cd $tmp
111 $sudo chmod u+w $CONFIG
112 cp $CONFIG $CONFIGSAVE
113 [ -f $LOGCONTROL ] && $sudo mv $LOGCONTROL $SAVE_LOGCONTROL
115 _cleanup()
117 cd $here
118 if $_needclean
119 then
120 _needclean=false
121 $signal -s TERM $pmcd
122 sleep 1
123 $sudo rm -f $CONFIG
124 $sudo cp $CONFIGSAVE $CONFIG
125 $sudo chmod u-w $CONFIG
126 [ -f $SAVE_LOGCONTROL ] && $sudo mv $SAVE_LOGCONTROL $LOGCONTROL
127 _restore_loggers
128 echo "Restart and ping pmcd ..."
129 unset PMCD_PORT
130 unset PMCD_SOCKET
131 _service pcp restart | _filter_pcp_start
132 _restore_auto_restart pmcd
133 _wait_for_pmcd
134 _wait_for_pmlogger
135 pmprobe pmcd.control.debug
136 sleepers=`ps $PCP_PS_ALL_FLAGS | grep '[d]umb_pmda' | $PCP_AWK_PROG '$3 == 1 { print $2 }'`
137 [ ! -z "$sleepers" ] && $sudo $signal -s KILL $sleepers
139 $sudo rm -rf $tmp $tmp.*
142 trap "_cleanup; exit \$status" 0 1 2 3 15
144 _stop_auto_restart pmcd
146 # real QA test starts here
148 _service pcp stop | _filter_pcp_stop
149 $sudo $signal -a pmgadgets pmchart pmview >/dev/null 2>&1
150 _disable_loggers
151 $sudo $signal -a -s TERM pmie >/dev/null 2>&1
153 # Make our own version of pmcd.conf with dummy agents that will time out.
154 # Copy the pmcd PMDA from the original pmcd.conf so that we can check pmcd's
155 # timeouts by storing into pmcd.control.timeout
156 # NOTE: none of the domains should clash with the pmcd PMDA (domain 2) or the
157 # sample agent (domain 254). These agents will be appended to the file.
159 echo "fake_irix 1 pipe binary $here/src/dumb_pmda -d 1 fake_irix" >$NEWCONFIG
160 echo "fake_sampledso 30 pipe binary $here/src/dumb_pmda -d 30 fake_sampledso" >>$NEWCONFIG
161 echo "fake_cisco 5 pipe binary $here/src/dumb_pmda -d 5 fake_cisco" >>$NEWCONFIG
162 echo "fake_linux 60 pipe binary $here/src/dumb_pmda -d 60 fake_linux" >>$NEWCONFIG
163 grep pmda_pmcd $CONFIGSAVE | sed -e 's/[ ][ ]*/ /g' -e 's/[ ]*$//' >>$NEWCONFIG
164 echo "[access]" >>$NEWCONFIG
165 echo "allow localhost : all;" >>$NEWCONFIG
166 echo "disallow * : all;" >>$NEWCONFIG
167 $sudo cp $NEWCONFIG $CONFIG
169 echo '$PCP_PMCDCONF_PATH contains:'
170 echo '<BEGIN>'
171 sed <$CONFIG \
172 -e '/^pmcd/s; [^ ]*pmda_pmcd.'$DSO_SUFFIX'; ...pmda_pmcd.$DSO_SUFFIX;' \
173 -e "s;$here/src/;;"
174 echo '<END>'
176 # Use a different port to avoid interference by remote monitors
178 port=`_find_free_port 5432`
179 export PMCD_PORT=$port
180 export PMCD_SOCKET=$tmp/pmcd.socket
182 # Note: start pmcd with -f so that its PID stays the same (no daemon)
183 # Also figure out which user we will run pmcd and its pmdas as
185 username=`id -u -n`
186 sudoopts="-u $username"
187 id pcp >/dev/null 2>&1 && sudoopts="-u pcp"
189 cat >$tmp.sh <<END
190 #!/bin/sh
191 export PATH=$here/src:$PATH
192 $PCP_PMCD_PROG -f -t 2 &
193 echo \$!
195 pmcd=`$sudo $sudoopts sh $tmp.sh`
197 # complete V1 PMDA timeouts, then wait for pmcd
199 sleep 12
200 _wait_for_pmcd
202 # If agent not restarted then both messages will be "no agent for domain..."
204 echo "Expect \"IPC protocol failure\" ..."
205 pminfo $NAMESPACE -d hinv.ncpu
207 # Now remove the fake_sampledso agent and add the sample agent from the
208 # original config file and restart PMCD.
209 # The config file has changed and there is also a dead agent to restart.
211 sed <$NEWCONFIG >$tmp.tmp \
212 -e '1{
214 '"`grep pmdasample $CONFIGSAVE | sed -e 's/[ ][ ]*/ /g' -e 's/[ ]*$//'`"'
215 }' \
216 -e '/fake_sampledso/d'
217 mv $tmp.tmp $NEWCONFIG
218 $sudo cp $NEWCONFIG $CONFIG
220 echo '$PCP_PMCDCONF_PATH now contains:'
221 echo '<BEGIN>'
222 sed <$CONFIG \
223 -e '/^pmcd/s; [^ ]*pmda_pmcd.'$DSO_SUFFIX'; ...pmda_pmcd.$DSO_SUFFIX;' \
224 -e '/^sample/s; [^ ]*pmdasample; ...pmdasample;' \
225 -e "s;$here/src/;;"
226 echo '<END>'
228 $signal -s HUP $pmcd
229 _wait_for_pmcd
231 echo "Expect \"Unknown or illegal metric identifier\" ..."
232 pminfo $NAMESPACE -d sampledso.control
233 echo "Expect \"IPC protocol failure\" ..."
234 pminfo $NAMESPACE -d hinv.ncpu
235 echo "Expect 9 values available ..."
236 pmprobe $NAMESPACE -v sample.bin
238 # Next, get the PID of the sample agent, copy the original config file back,
239 # restart PMCD (the sample agent's config line will be unchanged) and check
240 # that the sample agent has the same PID.
241 # The bogus fake_sampledso agent should have been terminated because it is
242 # no longer in the config file.
243 # That isn't enough to terminate the sleep agent.
245 echo
246 echo "Deleting, adding and keeping agents test"
247 sample=`pminfo $NAMESPACE -f sample.daemon_pid | $PCP_AWK_PROG '
248 $1 == "value" { print $2 }
250 sleep 1
251 ps -edf | grep dumb_pmda | grep fake_cisco >/dev/null || echo "Error: phony fake_cisco agent died prematurely"
253 $sudo cp $CONFIGSAVE $CONFIG
255 $signal -s HUP $pmcd
256 _wait_for_pmcd
258 ps -edf | grep dumb_pmda | grep fake_cisco >/dev/null && echo "Error: phony fake_cisco agent still lives!"
260 # Generate a PDU into the domain where the fake_sampledso agent used to be (#30 is
261 # assumed to be the sampledso PMDA)
263 echo "Getting a desriptor from domain 30 (fake_sampledso agent had this domain)"
264 pminfo $NAMESPACE -md sampledso.control
266 # check pmdasample has same pid (not restarted)
268 sample2=`pminfo $NAMESPACE -f sample.daemon_pid | $PCP_AWK_PROG '
269 $1 == "value" { print $2 }
271 if [ "X$sample" != "X$sample2" ]
272 then
273 echo "Sample agent needlessly restarted (pid changed from $sample to $sample2)"
276 _filter_log
277 echo
278 echo "..."
280 # success, all done
281 status=0
282 exit