File: 686

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 (188 lines) | stat: -rwxr-xr-x 4,381 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
#!/bin/sh
# PCP QA Test No. 686
# pmlogger_daily ... does culling happen if merging/rewrite fails?
#
# Copyright (c) 2018 Ken McDonell.  All Rights Reserved.
#

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

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

NEEDREWRITE=$PCP_LOG_DIR/pmlogger/.NeedRewrite

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

_filter()
{
    tee -a $seq_full \
    | sed \
	-e '/^Roll .*\/NOTICES/d' \
	-e '/^Start .*\/NOTICES/d' \
	-e '/^Start \[/s/ 2[0-9:. -]*/ DATESTAMP/' \
	-e '/^End \[/s/ 2[0-9:. -]*/ DATESTAMP /' \
	-e "s@$tmp@TMP@g" \
	-e "s@$PCP_BINADM_DIR@PCP_BINADM_DIR@g" \
	-e '/^.[rwx-][rwx-][rwx-]/s/.* 20/<ls output> 20/' \
	-e "s/$TODAY/TODAY/g" \
	-e "s/$YESTERDAY/YESTERDAY/g" \
	-e '/Warning: skipping log rotation because we don/d' \
	
	# -e '/^+ date-and-timestamp/s/stamp .*/stamp .../' \
	# -e '/^pmlogger_daily:.*\.control:[0-9]]$/d' \
    # end
}

# replacement for fmt(1) that is the same on every platform ... mimics
# the FSF version with a maximum line length of 72 columns
#
_fmt()
{
    $PCP_AWK_PROG '
BEGIN		{ len = 0 }
		{ for (i = 1; i <= NF; i++) {
		    wlen = length($i)
		    if (len + 1 + wlen > 72) {
			printf "\n"
			len = 0
		    }
		    if (len + 1 + wlen <= 72) {
			if (len == 0) {
			    printf "%s",$i
			    len = wlen;
			}
			else {
			    printf " %s",$i
			    len += 1 + wlen
			}
		    }
		  }
		}
END		{ if (len > 0) printf "\n" }'
}

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

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

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

TODAY=`pmdate %Y%m%d`
YESTERDAY=`pmdate -1d %Y%m%d`
# setup the log farm
#
cat <<End-of-File >$tmp.farm
myhost		archives/ok-foo	20180524
myhost		archives/ok-foo	20180525.00.10
myhost		archives/ok-foo	20180525.20.30
myhost		archives/ok-foo	20180526.00.10
myhost		archives/ok-foo	20180526.20.30
myhost		archives/ok-foo	$YESTERDAY.00.10
myhost		archives/ok-foo	$YESTERDAY.12.10
myhost		archives/ok-foo	$TODAY.00.10
End-of-File

_setup()
{
    cd $here
    $sudo rm -rf $tmp/*
    if ./mk.logfarm -c $tmp.farm $tmp >$tmp.out 2>&1
    then
	_filter <$tmp.out
    else
	cat $tmp.out
	echo "Arrgh ... mk.logfarm failed!"
	exit
    fi
    cd $tmp
    find * \
    | while read f
    do
	case "$f"
	in
	    */..)	;;
	    *)		$sudo chown $PCP_USER:$PCP_GROUP "$f"
	    		;;
	esac
    done
}

# create test control file
#
cat <<End-of-File >$tmp.control
\$version=1.1
#Host           P?  S?  directory       args
localhost       n   n   $tmp/myhost    -c /no/such/config
End-of-File

mkdir $tmp
cd $tmp

# real QA test starts here
PCP_DERIVED_CONFIG=; export PCP_DERIVED_CONFIG

echo "=== merge fails because output archive already exists ==="
_setup
$sudo -u $PCP_USER touch -t 201805260100.00 $tmp/myhost/20180526.meta
echo "Before ..."
ls $tmp/myhost | _filter | _fmt
echo
$sudo rm -f $tmp.log
$sudo -u $PCP_USER $PCP_BINADM_DIR/pmlogger_daily -P -D -c $tmp.control -k 7 -x never -V -l $tmp.log >$tmp.err 2>&1
_filter <$tmp.err
_filter <$tmp.log
echo
echo "After ..."
ls $tmp/myhost | _filter | _fmt

echo
echo "=== merge fails because input archives are bad ==="
_setup
# truncated metadata, merge should fail
for suff in 0 meta index
do
    $sudo cp $here/badarchives/badmeta-2.$suff $tmp/myhost/20180526.10.20.$suff
    $sudo chown $PCP_USER:$PCP_GROUP $tmp/myhost/20180526.10.20.$suff
    $sudo touch -t 201805261020.00 $tmp/myhost/20180526.10.20.$suff
done
echo "Before ..."
ls $tmp/myhost | _filter | _fmt
echo
$sudo rm -f $tmp.log
$sudo -u $PCP_USER $PCP_BINADM_DIR/pmlogger_daily -P -D -c $tmp.control -k 7 -x never -V -l $tmp.log >$tmp.err 2>&1
_filter <$tmp.err
_filter <$tmp.log
echo
echo "After ..."
ls $tmp/myhost | _filter | _fmt

echo
echo "=== logrewrite fails ==="
_setup
echo "metric 1.2.3 {" >$tmp.badrewrite
$sudo -u $PCP_USER cp $tmp.badrewrite $tmp/myhost/pmlogrewrite
echo "Before ..."
ls $tmp/myhost | _filter | _fmt
echo
$sudo rm -f $tmp.log
$sudo -u $PCP_USER $PCP_BINADM_DIR/pmlogger_daily -P -D -c $tmp.control -k 7 -x never -V -l $tmp.log >$tmp.err 2>&1
_filter <$tmp.err
_filter <$tmp.log
echo
echo "After ..."
ls $tmp/myhost | _filter | _fmt

# success, all done
status=0
exit