File: 338

package info (click to toggle)
pcp 7.0.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,916 kB
  • sloc: ansic: 1,478,844; sh: 177,285; xml: 160,462; cpp: 83,809; python: 24,349; perl: 18,303; yacc: 6,877; lex: 2,864; makefile: 2,694; awk: 165; fortran: 60; java: 52
file content (269 lines) | stat: -rwxr-xr-x 7,820 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#! /bin/sh
# PCP QA Test No. 338
# pmlogger_daily ... do you work at all?
#
# NEW VERSION for YYYYDDMM style naming convention (see also 530
# for the old YYMMDD style naming convention)
#
# See also 1473 for a variant of this test that uses $(date ...)
# in the directory field of the control file.
#
# Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
#
# check-group-include: pmlogrewrite pmlogextract
#

seq=`basename $0`
echo "QA output created by $seq"

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

# This test is not stable in the vicinity of a timezone change, e.g.
# daylight saving or summer time transitions.
# Don't run if this happened in the last 2 days.
#
now_hr=`pmdate '%H'`
now_min=`pmdate '%M'`
now_hr_2=`pmdate -2d '%H'`
[ $now_hr != $now_hr_2 ] && \
_notrun "timezone change? now = ${now_hr}H:??M, 2 days ago = ${now_hr_2}H:??M"

# This test is also unstable when run close to the new day boundary.
# Don't run if within 10 minutes of midnight.
#
[ "$now_hr" = "00" -a $now_min -lt 10 ] && \
_notrun "current time - $now_hr:$now_min - is too close to midnight"

_filter()
{
    if fmt --help 2>&1 | grep '.-w, ' >/dev/null
    then
	# GNU-style fmt(1)
	# -w, --width=WIDTH         maximum line width (default of 75 columns)
	cmd="fmt -w 76"
    elif fmt --help 2>&1 | grep '.-w .* width' >/dev/null
    then
	# FreeBSD-style fmt
        # -w <n> set maximum width to <n>
	cmd="fmt -w 76"
    elif fmt --help 2>&1 | grep '.-w width' >/dev/null
    then
	# OpenBSD-style fmt
        # -w width
	cmd="fmt -w 76"
    elif fmt --help 2>&1 | grep '.-[mg] ' >/dev/null
    then
	# NetBSD's version of fmt is different (may apply to other variants) ...
	cmd="fmt -g 74 -m 75"
    else
	echo "Warning: no clue how to set max line length for fmt(1)"
	cmd="fmt"
    fi
    tee -a $seq_full \
    | $PCP_AWK_PROG '
BEGIN				{ cmd = "'"`echo $cmd`"'" }
/^Archive files older than/	{ eatlines=1; longone="   "; print; next }
eatlines			{ if ( match ($0, "^    ") ) {
				    for ( i=1; i <=NF; i++ ) {
					longone = sprintf ("%s %s",longone,$i)
				    }
				  } else {
				    print longone | cmd
				    close (cmd)
				    longone = ""; eatlines = 0 
				    print  
				  }
				  next
				}
END				{ if ( eatlines ) {
				    print longone | cmd
				    close (cmd)
				  }
				}
				{ print }' \
    | sed -f $tmp.sed \
    | sed \
	-e '/^Roll .*\/NOTICES/d' \
	-e '/^Start .*\/NOTICES/d' \
	-e '/^Start \[/s/ 2[0-9:. -]*/ DATESTAMP/' \
	-e '/^End \[/s/ 2[0-9:. -]*/ DATESTAMP /' \
	-e '/^Add merge callback for: pmlogger_daily_report/d' \
	-e '/^Merge callbacks .../d' \
	-e '/^callback: .*pmlogger_daily_report/d' \
	-e "s;$tmp;TMP;g" \
	-e "s/`hostname`/HOST/g" \
	-e "s/localhost/HOST/g" \
	-e "s/local:/HOST/g" \
	-e "s/`hostname | sed -e 's/\..*//'`/HOST/g" \
	-e '/\/var\/adm\/pcplog\/NOTICES/d' \
	-e 's/-rw-r--r--\./-rw-r--r--/' \
    | $PCP_AWK_PROG '
/-rw-r--r--/	{ print $1,"...",$5,"...",$9; next }
		{ print }' \
    | _filter_cron_scripts
}

_fixperms()
{
    # pmlogger_daily runs as the user "pcp" ... fix ownership
    #
    $sudo touch $tmp.log
    find $tmp.log $tmp/* -type f | xargs $sudo chown $PCP_USER:$PCP_GROUP
    find $tmp/* -type d | xargs -r $sudo chown $PCP_USER:$PCP_GROUP
    $sudo chown $PCP_USER:$PCP_GROUP $tmp
}

NEEDREWRITE=$PCP_LOG_DIR/pmlogger/.NeedRewrite

_cleanup()
{
    cd $here
    $sudo rm -f $tmp.*
    $sudo rm -rf $tmp
    [ -f $NEEDREWRITE.$seq ] && $sudo mv $NEEDREWRITE.$seq $NEEDREWRITE
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

[ -f $NEEDREWRITE ] && $sudo mv $NEEDREWRITE $NEEDREWRITE.$seq

# take explicit control of the umask
umask 022

mkdir $tmp

# try to track down QA failures in CI ...
# finally understood ... with systemctl if pmlogger is started
# but NOT enabled, we get sightly different output
#
rm -f $seq.out
. $PCP_SHARE_DIR/lib/rc-proc.sh
# is_chkconfig_on() is a shell procedure from rc-proc.sh, so
#	if VERBOSE_CONFIG=true is_chkconfig_on ...
# sets $VERBOSE_CONFIG for THIS shell ... aargh
#
VERBOSE_CONFIG=true
if is_chkconfig_on pmlogger >>$seq_full 2>&1
then
    echo "is_chkconfig_on pmlogger => true" >>$seq_full
    ln $seq.out.enabled $seq.out
else
    echo "is_chkconfig_on pmlogger => false" >>$seq_full
    ln $seq.out.disabled $seq.out
fi
VERBOSE_CONFIG=false
if [ "$PCPQA_SYSTEMD" = yes ]
then
    systemctl is-enabled pmlogger.service >>$seq_full 2>&1
    if systemctl -q is-enabled pmlogger.service >>$seq_full 2>&1
    then
	echo "-q is-enabled pmlogger => true" >>$seq_full
    else
	echo "-q is-enabled pmlogger => false" >>$seq_full
    fi
    systemctl status pmlogger >>$seq_full
fi

# real QA test starts here
unset verbose
verbose_text=''
for loop in 1 2
do
    echo >$tmp.sed
    for day in 0 1 2 3 4 5
    do
	fmt=%Y%m%d
	# aiming for the time to be 00:02 and 00:04 on each day,
	# even if that is ahead of NOW for today
	#
	now_hr=`pmdate %H`
	hour=-$now_hr
	now_min=`pmdate %M`
	min2=`expr 2 - $now_min`
	[ "$min2" -ge 0 ] && min2="+$min2"
	min4=`expr 4 - $now_min`
	[ "$min4" -ge 0 ] && min4="+$min4"
	namea=`pmdate -${day}d ${hour}H ${min2}M $fmt.%H.%M`
	nameb=`pmdate -${day}d ${hour}H ${min4}M $fmt.%H.%M`
	yesterday=`pmdate -1d ${hour}H ${min2}M $fmt`
	stampa=`echo $namea | sed -e 's/\.//g'`
	stampb=`echo $nameb | sed -e 's/\.//g'`
	echo "s/$namea/NOW-$day.00.02/g" >>$tmp.sed
	echo "s/$nameb/NOW-$day.00.04/g" >>$tmp.sed

	for ext in 0 index meta
	do
	    $sudo cp archives/arch_a.$ext $tmp/$namea.$ext
	    $sudo touch -t $stampa $tmp/$namea.$ext
	    $sudo cp archives/arch_b.$ext $tmp/$nameb.$ext
	    $sudo touch -t $stampb $tmp/$nameb.$ext
	done
    done
    echo "s/NOW-0/TODAY/g" >>$tmp.sed
    echo "s/NOW-1/YESTERDAY/g" >>$tmp.sed
    echo "s/`pmdate %Y%m%d`/TODAY/g" >>$tmp.sed
    echo "s/$yesterday/YESTERDAY/g" >>$tmp.sed

    echo >$tmp.control '$version=1.1
LOCALHOSTNAME	n   n	'"$tmp"'	-c ./config'

    cat $tmp.sed >>$seq_full
    echo >>$seq_full

    echo
    echo "=== [$verbose_text] regular show ==="
    echo "=== [$verbose_text] regular show ===" >>$seq_full
    _fixperms
    # need to be a place the user $PCP_USER can cd to from pmlogger_daily
    #
    cd /var/tmp
    $sudo -u $PCP_USER -g $PCP_GROUP sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_daily -P -D -o -x forever -c $tmp.control -k 4 $verbose -l $tmp.log"
    cd $here

    $sudo cat $tmp.log | _filter
    ls -lt $tmp >>$seq_full
    ls $tmp | sed -f $tmp.sed | tee -a $seq_full | LC_COLLATE=POSIX sort

    echo
    echo "=== [$verbose_text] nothing to do but cull some more ==="
    echo "=== [$verbose_text] nothing to do but cull some more ===" >>$seq_full
    for ext in 0 index meta
    do
	$sudo mv $tmp/$yesterday.$ext $tmp/save.$ext
    done
    _fixperms
    cd /var/tmp
    $sudo -u $PCP_USER -g $PCP_GROUP sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_daily -P -D -o -x forever -c $tmp.control -k 3 $verbose -l $tmp.log"
    cd $here
    $sudo cat $tmp.log | _filter
    ls -lt $tmp >>$seq_full
    ls $tmp | sed -f $tmp.sed | tee -a $seq_full | LC_COLLATE=POSIX sort

    echo
    echo "=== [$verbose_text] error, output already exists ==="
    echo "=== [$verbose_text] error, output already exists ===" >>$seq_full
    for ext in 0 index meta
    do
	$sudo cp archives/arch_a.$ext $tmp/$yesterday.17.18.$ext
	$sudo mv $tmp/save.$ext $tmp/$yesterday.$ext
    done
    _fixperms
    cd /var/tmp
    $sudo -u $PCP_USER -g $PCP_GROUP sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_daily -P -D -o -x forever -c $tmp.control -k 3 $verbose -l $tmp.log"
    cd $here
    $sudo cat $tmp.log | _filter
    ls -lt $tmp >>$seq_full
    ls $tmp | sed -f $tmp.sed | tee -a $seq_full | LC_COLLATE=POSIX sort

    verbose=-V
    verbose_text='verbose'
    $sudo rm -f $tmp/*
done

# all done
status=0
exit