File: 457

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (255 lines) | stat: -rwxr-xr-x 6,918 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
#! /bin/sh
# PCP QA Test No. 457
# checks basic pmdalogger functionality
#
# Copyright (c) 2011 Aconex.  All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

[ -d $PCP_PMDAS_DIR/logger ] || _notrun "No pmdalogger installed"

_cleanup()
{
    if $_needclean
    then
	if [ -f $PCP_VAR_DIR/config/logger/logger.conf.$seq ]
	then
	    _restore_config $PCP_VAR_DIR/config/logger/logger.conf
	else
	    # don't leave our one behind here!
	    #
	    $sudo rm -f $PCP_VAR_DIR/config/logger/logger.conf
	fi
	_restore_pmda_install logger NOINSTALL
	if $install_on_cleanup
	then
	    ( cd $PCP_PMDAS_DIR/logger; $sudo ./Install <$tmp.input >/dev/null 2>&1 )
	else
	    ( cd $PCP_PMDAS_DIR/logger; $sudo ./Remove </dev/null >/dev/null 2>&1 )
	fi
	_needclean=false
    fi
    $sudo rm -fr $tmp.dir
    $sudo rm -f $tmp.*
    exit $status
}

_testdata()
{
    # generate data in a single write, for pmda determinism
    echo \
"TeSt DaTa ... TeSt DaTa ...
TeSt2 DaTa2 ... TeSt2 DaTa2"
}

_filter()
{
    sed \
	-e "s,$tmp,TMPFILE,g" \
	-e "s,$PCP_VAR_DIR,\$PCP_VAR_DIR,g" \
	-e 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9]*[0-9]/TIMESTAMP/g' \
	-e '/^# Installed/s/ on .*/ on .../' \
    # end
}

_filter_dir()
{
    # size is filesystem and blocksize dependent
    _filter | sed '/^logger\.perfile\.dir\.size$/ {
N
s:[0-9][0-9]*:SIZE:
}'
}

$sudo rm -fr $tmp.dir

# setup pmdalogger configuration file
echo "
# Installed by PCP QA test $seq on `date`
reg	n	$tmp.reg
fifo	n	$tmp.fifo
none	n	$tmp.none
empty	n	$tmp.empty
dir	n	$tmp.dir
pipe	n	$tmp.pipe|
" >$tmp.conf

# and reinstall PMDA Install script (if needed)
cat >$tmp.input <<End-of-File
1
y
End-of-File

install_on_cleanup=false
if pminfo -v logger >>$seq_full 2>&1
then
    if [ -f "$PCP_VAR_DIR/config/logger/logger.conf" ]
    then
	install_on_cleanup=true
    else
	# guard against a broken setup on entry ... the pminfo above
	# will return with status 0 if the PMDA is installed (even if
	# no metric values are available), but if logger.conf is not
	# there the Install in _cleanup() is doomed ...
	#
	echo "Botched install at test startup ... $PCP_VAR_DIR/config/logger/logger.conf is missing" >>$seq_full
    fi
fi
echo "install_on_cleanup=$install_on_cleanup" >>$seq_full

status=1	# failure is the default!
_needclean=true
trap "_cleanup" 0 1 2 3 15

# real QA test starts here

# need to save PMDA config (if it exists) now, before
# _prepare_pmda_install() that runs make clobber and may
# remove it
#
[ -d $PCP_VAR_DIR/config/logger ] || $sudo mkdir -p $PCP_VAR_DIR/config/logger
[ -f $PCP_VAR_DIR/config/logger/logger.conf ] && \
_save_config $PCP_VAR_DIR/config/logger/logger.conf

_prepare_pmda_install logger || _exit 1

# prepare test case files (see below)
_testdata > $tmp.reg
wc $tmp.reg >>$seq_full
cat $tmp.reg >>$seq_full
mkdir $tmp.dir
mkfifo $tmp.fifo
touch $tmp.empty
$sudo rm -f $tmp.pipe
cat <<End-of-File >$tmp.pipe
#!/bin/sh
# block and print something when SIGUSR1 delivered
echo \$\$ > $tmp.pipe.pid
trap "echo child" USR1	# refactor-ok
read book
End-of-File
chmod 755 $tmp.pipe

# start out with the "pid" file empty and world-writeable (logger PMDA is
# running as user pcp)
#
$sudo rm -f $tmp.pipe.pid

# $tmp.pipe.pid needs to be writeable by user $PCP_USER
#
touch $tmp.pipe.pid
$sudo chown $PCP_USER:$PCP_GROUP $tmp.pipe.pid
$sudo chmod 664 $tmp.pipe.pid

#debug# echo "--- start script ---" >>$seq_full
#debug# cat $tmp.pipe >>$seq_full
#debug# echo "--- end script ---" >>$seq_full
#debug# ls -l $tmp.pipe >>$seq_full

$sudo cp $tmp.conf $PCP_VAR_DIR/config/logger/logger.conf

# install PMDA accepting the defaults (esp config file)
$sudo ./Remove < /dev/null >/dev/null 2>&1
PCP_DEBUG=appl0,appl1; export PCP_DEBUG
$sudo ./Install < /dev/null >$tmp.out 2>&1
unset PCP_DEBUG
cat $tmp.out | _filter | _filter_pmda_install

# wait up to 20 seconds for $tmp.pipe.pid to appear (meaning the $tmp.pipe
# command has started)
#
i=0
while [ $i -lt 20 ]
do
    echo "wait #$i" >>$seq_full
    $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E "[P]PID|[.]pipe" >>$seq_full
    [ -s $tmp.pipe.pid ] && break
    sleep 1
    i=`expr $i + 1`
done
if [ ! -s $tmp.pipe.pid ]
then
    echo "Arrgh ..."
    $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E "[P]PID|[.]pipe|pmda[l]ogger|$seq[.]"
    cat $PCP_LOG_DIR/pmcd/logger.log >>$seq_full
    _fail "PID file from command pipe not found"
fi


echo
echo "=== 1. simple working case ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Checking initial data:""$PCP_ECHO_C"
pminfo -f logger.perfile.reg | _filter
_testdata >> $tmp.reg
wc $tmp.reg >>$seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Checking appended data:""$PCP_ECHO_C"
pminfo -f logger.perfile.reg | _filter

echo
echo "=== 2. named pipe (fifo) ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Check initial pipe""$PCP_ECHO_C"
pminfo -f logger.perfile.fifo | _filter
$PCP_ECHO_PROG $PCP_ECHO_N "Checking new pipe data""$PCP_ECHO_C"
_testdata >> $tmp.fifo
pminfo -f logger.perfile.fifo | _filter
$PCP_ECHO_PROG $PCP_ECHO_N "Unlink the fifo""$PCP_ECHO_C"
rm -f $tmp.fifo
pminfo -f logger.perfile.fifo | _filter

echo
echo "=== 3. log file rotation ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Checking removed file""$PCP_ECHO_C"
rm -f $tmp.reg
sleep 3	# pmda interval timer is 2 seconds
pminfo -f logger.perfile.reg  | _filter
$PCP_ECHO_PROG $PCP_ECHO_N "Checking new log file""$PCP_ECHO_C"
_testdata >> $tmp.reg
wc $tmp.reg >>$seq_full
sleep 3	# pmda interval timer is 2 seconds
pminfo -f logger.perfile.reg | _filter
wc $tmp.reg >>$seq_full
od -c $tmp.reg >>$seq_full

echo
echo "=== 4. non-existant file ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Check a missing file""$PCP_ECHO_C"
pminfo -f logger.perfile.none | _filter
_testdata >> $tmp.none
wc $tmp.none >>$seq_full
sleep 3	# pmda interval timer is 2 seconds
$PCP_ECHO_PROG $PCP_ECHO_N "Checking new log file""$PCP_ECHO_C"
pminfo -f logger.perfile.none | _filter

echo
echo "=== 5. empty file ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Check an empty file""$PCP_ECHO_C"
pminfo -f logger.perfile.empty | _filter
_testdata >> $tmp.empty
wc $tmp.empty >>$seq_full
sleep 3	# pmda interval timer is 2 seconds
$PCP_ECHO_PROG $PCP_ECHO_N "Checking new log file""$PCP_ECHO_C"
pminfo -f logger.perfile.empty | _filter

echo
echo "=== 6. directory ===" | tee -a $seq_full
$PCP_ECHO_PROG $PCP_ECHO_N "Check a directory""$PCP_ECHO_C"
pminfo -f logger.perfile.dir | _filter_dir

echo
echo "=== 7. command pipe ===" | tee -a $seq_full
pid=`cat $tmp.pipe.pid`
$PCP_ECHO_PROG $PCP_ECHO_N "Check a piped command""$PCP_ECHO_C"
pminfo -f logger.perfile.pipe | _filter
$PCP_ECHO_PROG $PCP_ECHO_N "Signal the command""$PCP_ECHO_C"
pmsignal -s USR1 $pid >/dev/null 2>&1
sleep 3	# some time for it to be delivered
pminfo -f logger.perfile.pipe | _filter

status=0
exit