Merge branch 'master' of https://github.com/kmcdonell/pcp into kenj-merge
[pcp.git] / qa / 115
blob36405a88252376c05572aba25d43fd3d22a995b8
1 #! /bin/sh
2 # PCP QA Test No. 115
3 # exercises pmie_check functionality
5 # Copyright (c) 2002 Silicon Graphics, Inc. All Rights Reserved.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get standard environment, filters and checks
12 . ./common.product
13 . ./common.filter
14 . ./common.check
16 [ -f /etc/gentoo-release ] && _notrun "Gentoo is lacking chkconfig support"
17 [ -f /etc/slackware-version ] && _notrun "Slackware is lacking chkconfig support"
19 if [ -z "$PCP_PMIECONTROL_PATH" ]
20 then
21 echo "Error: botched installation - PCP_PMIECONTROL_PATH not defined"
22 exit 1
25 _cleanup()
27 if $needclean
28 then
29 _restore_config $PCP_PMIECONTROL_PATH
30 _restore_config $PCP_PMCDCONF_PATH
32 $sudo rm -rf $tmp.nogo $tmp.locker
33 for file in $tmp.*
35 echo >>$here/$seq.full
36 echo "=== $file ===" >>$here/$seq.full
37 cat $file >>$here/$seq.full
38 done
39 $sudo rm -f $tmp.*
42 status=1 # failure is the default!
43 $sudo rm -f $tmp.* $seq.full
44 signal=$PCP_BINADM_DIR/pmsignal
45 needclean=false
46 trap "_cleanup; exit \$status" 0 1 2 3 15
48 lhost=`hostname | sed -e 's/\..*//'`
49 host=`_get_fqdn`
50 remote=`./getpmcdhosts -n 1 -L 2>$tmp.out`
51 rhost=`echo $remote | sed -e 's/\..*//'`
52 [ -z "$remote" ] && _notrun `cat $tmp.out`
54 # Now that we have pmmgr in the mix, there is more than one pmie
55 # potentially running, so lines like this
56 # ... try /var/lib/pcp/tmp/pmie/25453: different logfile, skip
57 # /var/log/pcp/pmmgr/bozo/pmie.log differs to /tmp/SEQ-PID.log1
58 # are now expected, and not a problem.
60 # mkdir: error lines ... not consistency in format, so cull 'em
61 # ditto for cd errors reported from pmie_check
63 _filter()
65 sed \
66 -e "s/$seq-$$/SEQ-PID/g" \
67 -e "s;$PCP_BIN_DIR/pmie;\$PCP_BIN_DIR/pmie;" \
68 -e 's/line [0-9][0-9]*:/line N:/' \
69 -e 's/$/ /' \
70 -e 's/\([ "]\)'"$remote"'\([ "]\)/\1REMOTEHOST\2/g' \
71 -e 's/\([ "]\)'"$rhost"'\([ "]\)/\1REMOTEHOST\2/g' \
72 -e 's/\([ "]\)'"$host"'\([ "]\)/\1LOCALHOST\2/g' \
73 -e 's/\([ "]\)local:\([ "]\)/\1LOCALHOST\2/g' \
74 -e "s;/private/tmp;/tmp;g" \
75 -e '/ try .* different logfile, skip/d' \
76 -e '/\/pmmgr\/.* differs to /d' \
77 -e '/^.r[-w][-x]r[-w][-x]/s/.* \//... ls output ... /' \
78 -e '/mkdir:/d' \
79 -e '/\/pmie_check:.*cd:/d' \
80 -e 's/[ ]*$//' \
81 -e 's/^[ ]*//' \
82 -e 's/\.\.failed/failed (status=1)/' \
83 # end
86 _count_pmies()
88 count=0
89 if [ -d $PCP_TMP_DIR/pmie ]
90 then cd $PCP_TMP_DIR/pmie
91 else return 0
94 ls -l >>$here/$seq.full
95 plist=`ls -1`
96 echo "plist=$plist" >>$here/$seq.full
97 cd $here
99 for process in $plist
101 ps -p $process >/dev/null 2>&1
102 if [ $? = 1 ]
103 then
104 echo "urk, $PCP_TMP_DIR/pmie/$process has no running pmie instance"
105 else
106 count=`expr $count + 1`
107 ps -f -p $process >>$here/$seq.full
108 if `which pstree >/dev/null 2>&1`
109 then
110 pstree $process >>$here/$seq.full
113 done
115 return $count
118 # create a basic pmcd config file
119 cat >$tmp.pmcd.conf << EOF
120 # from QA $seq
121 pmcd 2 dso pmcd_init pmda_pmcd.so
124 # create a pmie config file
125 cat >$tmp.conf << EOF
126 foo = sample.long.one;
127 doo = sample.long.ten;
130 # create pmie control files
131 cat >$tmp.control.v1.0 << EOF
132 \$version=1.0
133 $remote n $tmp.log1 -c $tmp.conf
134 $remote n $tmp.log2 -c $tmp.conf
135 LOCALHOSTNAME n $tmp.log0 -c $tmp.conf
137 cat >$tmp.control.v1.1 << EOF
138 \$version=1.1
139 $remote n n $tmp.log1 -c $tmp.conf
140 $remote n n $tmp.log2 -c $tmp.conf
141 LOCALHOSTNAME y n $tmp.log0 -c $tmp.conf
144 # real QA test starts here
145 _save_config $PCP_PMIECONTROL_PATH
146 _save_config $PCP_PMCDCONF_PATH
147 needclean=true
148 $sudo cp $tmp.pmcd.conf $PCP_PMCDCONF_PATH
150 $sudo $signal -a -s TERM pmie >/dev/null 2>&1
151 sleep 1
152 _change_config pmcd on
153 _change_config pmie off
154 $sudo rm -f $PCP_TMP_DIR/pmie/*
156 _count_pmies
157 echo "pmie count at start of QA testing: $?"
158 echo
160 echo === check default install operation ===
161 _service pmie restart 2>&1 | _filter_pmie_start
162 _count_pmies
163 # chkconfig no longer controls start-ability, expect non-zero
164 echo "pmie count after chkconfig pmie off: $?"
165 echo
167 echo === check for missing control file ===
168 _change_config pmie off
169 $sudo rm -f $PCP_PMIECONTROL_PATH
170 _change_config pmie on
171 _service pmie restart 2>&1 | _filter_pmie_start | _filter
172 _count_pmies
173 echo "pmie count after attempt without control file: $?"
174 echo
176 echo === check pmie_check and custom configs ===
177 echo "--- v1.0 ---"
178 pmie_check -V -V -N -c $tmp.control.v1.0 -l $tmp.log
179 cat $tmp.log | _filter
180 # don't bother counting pmie processes, as -N is used above!
182 echo
183 echo "--- v1.1 ---"
184 pmie_check -V -V -N -c $tmp.control.v1.1 -l $tmp.log
185 cat $tmp.log | _filter
186 # don't bother counting pmie processes, as -N is used above!
188 echo
190 echo "=== warnings ... ==="
191 echo "--- stale lock file ---"
192 case=1
193 cat >$tmp.warning.$case << EOF
194 \$version=1.1
195 LOCALHOSTNAME n n $tmp.locker/ok.$case -c $tmp.conf
197 mkdir $tmp.locker
198 touch -t `pmdate -35M %Y%m%d%H%M` $tmp.locker/ok.$case.lock
199 pmie_check -V -V -N -c $tmp.warning.$case -l $tmp.warning.$case.log
200 cat $tmp.warning.$case.log | _filter
201 echo
202 echo "--- existing lock file ---"
203 case=`expr $case + 1`
204 cat >$tmp.warning.$case << EOF
205 \$version=1.1
206 LOCALHOSTNAME n n $tmp.locker/ok.$case -c $tmp.conf
208 rm -f $tmp.locker/ok.$case.lock
209 touch $tmp.locker/ok.$case.lock
210 pmie_check -V -V -N -c $tmp.warning.$case -l $tmp.warning.$case.log
211 cat $tmp.warning.$case.log | _filter
212 echo
213 echo "--- can't create lock file ---"
214 case=`expr $case + 1`
215 cat >$tmp.warning.$case << EOF
216 \$version=1.1
217 LOCALHOSTNAME n n $tmp.locker/ok.$case -c $tmp.conf
219 chmod 555 $tmp.locker
220 pmie_check -V -V -N -c $tmp.warning.$case -l $tmp.warning.$case.log
221 cat $tmp.warning.$case.log | _filter
222 $sudo rm -rf $tmp.locker
223 echo
224 echo "--- bad in-line shell commands ---"
225 case=`expr $case + 1`
226 cat >$tmp.warning.$case << EOF
227 \$version=1.1
228 \$date
229 \$PATH=/some/where/bad:\$PATH
230 \$IFS=a
231 LOCALHOSTNAME n n $tmp.ok.$case -c $tmp.conf
233 pmie_check -V -V -N -c $tmp.warning.$case -l $tmp.warning.$case.log
234 cat $tmp.warning.$case.log | _filter
235 echo
236 echo "--- missing \$version but really v1.1 ... original control.local issue ---"
237 case=`expr $case + 1`
238 cat >$tmp.warning.$case << EOF
239 LOCALHOSTNAME n n $tmp.ok.$case -c $tmp.conf
241 pmie_check -V -V -N -c $tmp.warning.$case -l $tmp.warning.$case.log
242 cat $tmp.warning.$case.log | _filter
243 echo
245 echo "=== errors ... ==="
246 echo "--- bad version ---"
247 case=1
248 cat >$tmp.error.$case << EOF
249 \$version=0.0
250 LOCALHOSTNAME n $tmp.bad.$case -c $tmp.conf
252 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
253 cat $tmp.bad.$case.log | _filter
254 echo
255 case=`expr $case + 1`
256 echo "--- v1.0 socks != y|n ---"
257 cat >$tmp.error.$case << EOF
258 \$version=1.0
259 LOCALHOSTNAME x $tmp.bad.$case -c $tmp.conf
261 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
262 cat $tmp.bad.$case.log | _filter
263 echo
264 case=`expr $case + 1`
265 echo "--- v1.1 socks != y|n ---"
266 cat >$tmp.error.$case << EOF
267 \$version=1.1
268 LOCALHOSTNAME n x $tmp.bad.$case -c $tmp.conf
270 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
271 cat $tmp.bad.$case.log | _filter
272 echo
273 case=`expr $case + 1`
274 echo "--- v1.1 primary != y|n ---"
275 cat >$tmp.error.$case << EOF
276 \$version=1.1
277 LOCALHOSTNAME x n $tmp.bad.$case -c $tmp.conf
279 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
280 cat $tmp.bad.$case.log | _filter
281 echo
282 case=`expr $case + 1`
283 echo "--- v1.0 insufficient fields ---"
284 cat >$tmp.error.$case << EOF
285 \$version=1.0
286 LOCALHOSTNAME n $tmp.bad.$case
288 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
289 cat $tmp.bad.$case.log | _filter
290 echo
291 case=`expr $case + 1`
292 echo "--- v1.1 insufficient fields ---"
293 cat >$tmp.error.$case << EOF
294 \$version=1.1
295 LOCALHOSTNAME n n $tmp.bad.$case
297 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
298 cat $tmp.bad.$case.log | _filter
299 echo
300 mkdir $tmp.nogo
301 chmod 000 $tmp.nogo
302 case=`expr $case + 1`
303 echo "--- can't create dir for logfile ---"
304 cat >$tmp.error.$case << EOF
305 \$version=1.1
306 LOCALHOSTNAME n n $tmp.nogo/subdir/bad.$case -c $tmp.conf
308 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
309 cat $tmp.bad.$case.log | _filter
310 echo
311 case=`expr $case + 1`
312 echo "--- can't chdir to dir for logfile ---"
313 cat >$tmp.error.$case << EOF
314 \$version=1.1
315 LOCALHOSTNAME n n $tmp.nogo/bad.$case -c $tmp.conf
317 pmie_check -V -V -N -c $tmp.error.$case -l $tmp.bad.$case.log
318 cat $tmp.bad.$case.log | _filter
319 echo
320 $sudo rm -rf $tmp.nogo
322 _service pmie stop 2>&1 \
323 | _filter_pmie_start \
324 | sed \
325 -e '/PMIE not running/d' \
326 -e '/pmie not running/d' \
327 # end
328 _change_config pmie off
330 status=0
331 exit