Merge branch 'master' of git://git.pcp.io/pcp into qt
[pcp.git] / qa / 255
blob151283e82428a325e7af07e3862502007a257310
1 #! /bin/sh
2 # PCP QA Test No. 255
3 # exercise pmcd <-> pmda version exchange
4 # Bug #508731
6 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
9 seq=`basename $0`
10 echo "QA output created by $seq"
12 # get standard filters
13 . ./common.product
14 . ./common.filter
15 . ./common.check
17 [ -d $PCP_PMDAS_DIR/simple ] || _notrun "simple PMDA directory is not installed"
19 rm -f $seq.out
20 _get_libpcp_config
21 if $ipv6 ; then
22 ln $seq.out.ipv6 $seq.out || exit 1
23 else
24 ln $seq.out.nonipv6 $seq.out || exit 1
27 signal=$PCP_BINADM_DIR/pmsignal
28 status=1 # failure is the default!
29 errlist=''
30 trap "_cleanup; exit \$status" 0 1 2 3 15
32 $sudo rm -f $seq.full $tmp.*
33 echo "=== I am PID $$" >>$seq.full
34 echo "=== /tmp files" >>$seq.full
35 $sudo ls -l /tmp/[0-9][0-9]*.* >>$seq.full 2>&1
36 echo "=== config files" >>$seq.full
37 ls -l $PCP_PMCDCONF_PATH $PCP_PMCDOPTIONS_PATH >>$seq.full
39 unset ROOT MAKEFLAGS
41 simple_domain=253
42 broken_domain=249
43 num_warn=0
45 # pmcd may be quite some distance away
47 PMCD_CONNECT_TIMEOUT=30
48 PMCD_REQUEST_TIMEOUT=30
49 export PMCD_CONNECT_TIMEOUT PMCD_REQUEST_TIMEOUT
51 _filter_ins()
53 sed \
54 -e '/^Installing .mchart view*/d' \
55 -e 's/.* \(hash table entries\)/ NNN \1/' \
56 -e 's/.* \(non-leaf nodes\)/ NNN \1/' \
57 -e 's/.* \(leaf nodes\)/ NNN \1/' \
58 -e 's/.* \(bytes of symbol table\)/ NNN \1/'
61 _filter_pmcd()
63 _filter_pmcd_log \
64 | sed \
65 -e "/^simple.*bin/s/$simple_domain[ ]*[0-9]*[ ]*[0-9]*[ ]*[0-9]*/SIMPLE PID FD FD/" \
66 -e "/^simple.*dso/s/$simple_domain/SIMPLE/" \
67 -e "/^broken.*bin/s/$broken_domain[ ]*[0-9]*[ ]*[0-9]*[ ]*[0-9]*/BROKEN PID FD FD/" \
68 -e "s/[1-2][ ]dso.*linux_init/LINUX DSO/" \
69 -e "s;$PCP_PMDAS_DIR;PCP_PMDAS_DIR;g" \
70 -e "s/ISA\.//g" \
71 -e "s/ \[(nil)]//g" \
72 -e "s/cmd=.*pmdas\/broken./cmd=/" \
73 -e "s/ fd=[0-9]*/ fd=FD/" \
74 -e "s/\.$DSO_SUFFIX/.\$DSO_SUFFIX/g" \
75 -e '/UNIX_DOMAIN_SOCKET/d' \
76 | $PCP_AWK_PROG '
77 BEGIN { skip = 0 }
78 /client connection from/ { print; print "..."; skip=1; next }
79 skip == 1 && NF == 0 { skip = 0 }
80 skip == 1 { next }
81 { print }'
84 _filter_init()
86 sed \
87 -e "s/$$/PID/g" \
88 | _filter_pcp_start
91 # Remove the PMDA and restore pmcd.conf
93 _cleanup()
95 echo ""
96 echo "=== Removing broken_pmda namespace ==="
97 cd $here/pmdas/broken
98 $sudo ./broken_Remove -N
99 cd $here
100 sleep 4
101 _wait_for_pmcd
103 if [ -f $tmp.conf ]
104 then
105 echo "=== Resetting pmcd.conf back to original state ==="
106 $sudo cp $tmp.conf $PCP_PMCDCONF_PATH
108 if [ -f $tmp.options ]
109 then
110 echo "=== Resetting pmcd.options back to original state ==="
111 echo '=== $PCP_PMCDOPTIONS_PATH before cp' >>$seq.full
112 cat $PCP_PMCDOPTIONS_PATH >>$seq.full
113 echo '=== $tmp.options before cp' >>$seq.full
114 cat $tmp.options >>$seq.full
115 $sudo cp $tmp.options $PCP_PMCDOPTIONS_PATH
117 if [ -f $tmp.conf -o -f $tmp.options ]
118 then
119 echo "=== Restart PMCD ==="
120 echo '=== $PCP_PMCDCONF_PATH before init.d/pcp/start' >>$seq.full
121 cat $PCP_PMCDCONF_PATH >>$seq.full
122 echo '=== $PCP_PMCDOPTIONS_PATH before init.d/pcp/start' >>$seq.full
123 cat $PCP_PMCDOPTIONS_PATH >>$seq.full
124 $sudo $PCP_RC_DIR/pcp restart | _filter_pcp_start
125 _wait_for_pmcd
127 if [ -f $tmp.log ]
128 then
129 echo "=== Filter pmcd.log ==="
130 cat $tmp.log | _filter_pmcd
131 echo '=== pmcd log' >>$seq.full
132 cat $tmp.log >>$seq.full
134 if [ -f $tmp.cron ]
135 then
136 echo "=== Restoring crontab ==="
137 _restore_cron $tmp.cron $sudo
139 [ -f $PCP_PMDAS_DIR/simple/simple.conf.$seq ] && $sudo mv $PCP_PMDAS_DIR/simple/simple.conf.$seq $PCP_PMDAS_DIR/simple/simple.conf
141 echo "=== /tmp files" >>$seq.full
142 $sudo ls -l /tmp/[0-9][0-9]*.* >>$seq.full 2>&1
143 echo "=== config files" >>$seq.full
144 ls -l $PCP_PMCDCONF_PATH $PCP_PMCDOPTIONS_PATH >>$seq.full
146 $sudo rm -rf $tmp.*
147 _wait_for_pmlogger
150 # Removing cron entries that may collide
152 echo "=== Removing potential cron conflicts ==="
153 _remove_cron $tmp.cron $sudo
155 # Install broken pmda namespace
157 echo "=== Install broken namespace ==="
158 cd $here/pmdas/broken
159 $sudo ./broken_Install -N < /dev/null | _filter_ins 2>&1
160 # ensure help text built (-N above skips this)
161 $sudo $PCP_MAKE_PROG broken_v2.dir > /dev/null 2>&1
162 cd $here
163 echo "=== Broken PMNS ==="
164 if pminfo broken
165 then
167 else
168 echo "Unable to install broken namespace, exiting"
169 exit
172 # Build simple agent
174 echo "=== Building simple agent ==="
175 cd $PCP_PMDAS_DIR/simple
177 # get rid of warnings from simple if no config exists
179 [ -f simple.conf ] && $sudo mv simple.conf simple.conf.$seq
180 echo "sec,min,hour" >$tmp.simple.conf
181 $sudo cp $tmp.simple.conf simple.conf
183 # Install the simple namespace, I don't bother to remove it again
185 $sudo ./Install -N < /dev/null | _filter_ins 2>&1
186 echo "Namespace installed"
188 if $sudo $PCP_MAKE_PROG > $tmp.make 2>&1
189 then
190 echo "PMDA built"
191 else
192 echo "Unable to build the simple PMDA:"
193 cat $tmp.make
194 exit
196 sed -e "/^@ SIMPLE/s/SIMPLE/$simple_domain/" < help \
197 | $sudo $PCP_BINADM_DIR/newhelp -v 2 -o help
198 echo "Help generated"
199 cd $here
201 # Replace pmcd.options
203 echo "=== Replacing pmcd.options ==="
204 $sudo cp $PCP_PMCDOPTIONS_PATH $tmp.options
205 cat << end-of-file > $tmp.newoptions
206 # New pmcd.options file created by QA 255
208 -t 10
209 -l $tmp.log
210 -T 0
211 end-of-file
213 $sudo cp $tmp.newoptions $PCP_PMCDOPTIONS_PATH
214 # Do not restart pmcd here, do it after changing pmcd.conf later
216 _renew_pmcd()
218 echo "=== Restarting PMCD with minimal PMDAs ==="
219 if [ -f $tmp.newconf ]
220 then
221 $sudo cp $tmp.newconf $PCP_PMCDCONF_PATH
222 $sudo $signal -a -s HUP pmcd >/dev/null 2>&1
223 sleep 4
224 _wait_for_pmcd
225 else
226 echo caller - $1 - has not created $tmp.newconf !!!
230 # Install a standard pmda, but do not mess with the namespace
232 _agent_install()
234 agent=$1
235 domain=$2
236 daemon=$3
237 path=$PCP_PMDAS_DIR/$agent
239 echo "=== Installing $agent ==="
240 cp $tmp.newconf $tmp.latest
241 if $daemon
242 then
243 cat << end-of-file >> $tmp.latest
244 $agent $domain pipe binary $path/pmda$agent -d $domain
245 end-of-file
246 else
247 cat << end-of-file >> $tmp.latest
248 $agent $domain dso ${agent}_init $path/pmda_$agent.$DSO_SUFFIX
249 end-of-file
252 $sudo cp $tmp.latest $PCP_PMCDCONF_PATH
253 # after non-root pmcd changes, the log files may be owned by
254 # root.root or pcp.pcp depending on the pattern of installs and
255 # pmcd restarts ... to be sure we can write the log files, remove
256 # any old ones before signalling pmcd
258 $sudo rm -f $PCP_LOG_DIR/pmcd/simple.log* $PCP_LOG_DIR/pmcd/broken.log*
259 $sudo $signal -a -s HUP pmcd >/dev/null 2>&1
260 sleep 4
261 _wait_for_pmcd
263 if _check_agent $agent
264 then
265 echo "$agent is alive and well"
266 else
267 echo "Failed to install $agent"
268 exit
272 # Remove a pmda
274 _agent_remove()
276 agent=$1
278 echo "=== Removing $agent ==="
279 _renew_pmcd _agent_remove
281 if _check_agent $agent
282 then
283 echo "Failed to remove $agent"
284 exit
285 else
286 echo "$agent was removed"
290 # Install broken pmda
292 _broken_install()
294 agent=$1
295 ver=$2
297 echo "=== Installing $agent ==="
298 cp $tmp.newconf $tmp.latest
299 cat << end-of-file >> $tmp.latest
300 broken $broken_domain pipe binary $here/pmdas/broken/$agent -d $broken_domain
301 end-of-file
303 $sudo cp $tmp.latest $PCP_PMCDCONF_PATH
304 $sudo $signal -a -s HUP pmcd >/dev/null 2>&1
305 sleep 4
306 _wait_for_pmcd
308 if _check_agent broken
309 then
310 echo "$agent is alive and well...hang on there should be some warnings"
311 pminfo -f broken
312 exit
313 elif [ "$num_warn" -ne 5 ]
314 then
315 echo "Failed to properly install $agent, expected 4 warnings"
316 exit
317 else
318 echo "$agent is alive and as well as can be expected"
322 # Copy and replace pmcd.conf
324 cp $PCP_PMCDCONF_PATH $tmp.conf
325 cat << end-of-file > $tmp.newconf
326 # pmcd.conf generated by QA 255
328 end-of-file
330 if [ $PCP_PLATFORM = linux ]
331 then
332 cat >>$tmp.newconf <<End-of-File
333 # from qa/$seq
334 linux 60 dso linux_init $PCP_PMDAS_DIR/linux/pmda_linux.so
335 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
336 End-of-File
337 elif [ $PCP_PLATFORM = darwin ]
338 then
339 cat >>$tmp.newconf <<End-of-File
340 # from qa/$seq
341 darwin 78 dso darwin_init $PCP_PMDAS_DIR/darwin/pmda_darwin.dylib
342 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.dylib
343 End-of-File
344 elif [ $PCP_PLATFORM = solaris ]
345 then
346 cat >>$tmp.newconf <<End-of-File
347 # from qa/$seq
348 solaris 75 dso solaris_init $PCP_PMDAS_DIR/solaris/pmda_solaris.so
349 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
350 End-of-File
351 elif [ $PCP_PLATFORM = freebsd ]
352 then
353 cat >>$tmp.newconf <<End-of-File
354 # from qa/$seq
355 freebsd 85 dso freebsd_init $PCP_PMDAS_DIR/freebsd/pmda_freebsd.so
356 pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so
357 End-of-File
358 else
359 echo "Arrgh ... need pmcd.conf for $PCP_PLATFORM"
360 exit 1
363 _renew_pmcd main
365 # Start with a fresh pmcd log
367 $sudo $signal -a pmgadgets pmchart pmview >/dev/null 2>&1
368 $sudo $PCP_RC_DIR/pcp restart | _filter_init 2>&1
369 _wait_for_pmcd
371 # Test 2.0 PMDA first
373 _agent_install simple $simple_domain true
374 _agent_remove simple
375 _agent_install simple $simple_domain false
376 _agent_remove simple
378 # Test 2.0 broken PMDA
380 _broken_install broken_pmda_2_0 2
381 _agent_remove broken
383 status=0
384 exit