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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
#!/bin/sh
# PCP QA Test No. 1248
# pmlogctl - cond-create
#
# see qa/1249 for the pmiectl version of this test
#
# Copyright (c) 2020 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
if pmlogctl -c pmfind status 2>/dev/null | grep ' pmfind ' >/dev/null
then
_notrun "at least one pmlogger already defined for \"pmfind\" class"
fi
_cleanup()
{
echo "_cleanup: ..." >>$seq_full
cd $here
$sudo pmlogctl -af -c pmfind destroy localhost >>$seq_full 2>&1
$sudo rm -rf $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.?
_restore_config $PCP_ETC_DIR/pcp/pmlogger/class.d
$sudo rm -rf $tmp $tmp.*
for dir in $seq $seq-a $seq-b $seq-c
do
[ -d "$PCP_ARCHIVE_DIR/$dir" ] && $sudo rm -rf "$PCP_ARCHIVE_DIR/$dir"
done
}
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
localhost=`hostname`
# this test requires only the pmfind policy class is in place
#
_save_config $PCP_ETC_DIR/pcp/pmlogger/class.d
for policy in $PCP_ETC_DIR/pcp/pmlogger/class.d/*
do
case "$policy"
in
*/pmfind) ;;
*) $sudo rm -f "$policy"
;;
esac
done
_filter()
{
tee -a $seq_full \
| sed \
-e '/^# created by pmlogctl/s/ on .*/ on DATE/' \
-e "s;$tmp\.;TMP.;g" \
-e "s;$PCP_BINADM_DIR/;PCP_BINADM_DIR/;g" \
-e "s;$PCP_ARCHIVE_DIR/;PCP_ARCHIVE_DIR/;g" \
-e "s;$PCP_TMP_DIR/;PCP_TMP_DIR/;g" \
-e "s;$PCP_TMPFILE_DIR/pmlogctl\.[^/]*;PCP_TMPFILE_DIR/pmlogctl.XXXXX;g" \
-e "s;$PCP_ETC_DIR/;PCP_ETC_DIR/;g" \
-e '/^Host:/{
s/Host: '$localhost' /Host: LOCALHOSTNAME /
s/[0-9.]*$/DATESTAMP/
}' \
# end
}
# Build filter for any existing non-qa and non-primary pmlogger instances.
# The "pmcd Host" and "Class" fields from the pmlogctl status output
# should suffice to uniquely identify each.
#
pmlogctl status 2>&1 \
| $PCP_AWK_PROG >$tmp.awk '
NR == 1 { next }
NF >= 5 { if ($3 == "primary") next
print "$1 == \"" $1 "\" && $3 == \"" $3 "\" { next }"
}
END { print "{ print }" }'
# Note status command output order is non-deterministic, hence the sort
# at the end
#
_filter_status()
{
tee -a $seq_full \
| $PCP_AWK_PROG -f $tmp.awk \
| sed >$tmp.tmp \
-e "/^`hostname` .* primary /d" \
-e 's/[ ][ ]*/ /g' \
-e 's/2[0-9][0-9][0-9][01][0-9][0-3][0-9]\...\.[^ ]*/<archivename>/' \
-e "s/^$localhost /LOCALHOSTNAME /" \
-e "s/ $seq / <seq> /" \
-e 's/ [0-9][0-9]* / <pid> /' \
# end
head -1 $tmp.tmp
sed -e '1d' $tmp.tmp | LC_COLLATE=POSIX sort
}
cat <<End-of-File >$tmp.policy.head
# Installed by PCP QA test $seq on `date`
[class]
$seq
[ident]
$seq-%h
[control]
\$version=1.1
# existing config file
%h n n PCP_ARCHIVE_DIR/%i -c $tmp.config
End-of-File
cat <<End-of-File >$tmp.config
log mandatory on default { sample.lights }
End-of-File
# real QA test starts here
echo '== -NV expect pmfind class to be used' | tee -a $seq_full
pmlogctl -NV cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p, no [create] section, expect on instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
pmlogctl -NV -p $tmp.policy cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c, no [create] section, expect no instance to be created' | tee -a $seq_full
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo "[create]" >>$tmp.policy.head
echo | tee -a $seq_full
echo '== -NV -p -c exists() false, expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "exists(hinv.foo)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c exists() true (leaf in PMNS), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "exists(sample.bin)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c exists() true (non-leaf in PMNS), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "exists(sample)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c values() false (bad metric), expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(hinv.foo.bar)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c values() false (numval < 1), expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(sample.bad.novalues)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c values() true (leaf & singular), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(sample.long)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c values() true (leaf & indom), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(sample.bin)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c values() true (non-leaf & indom), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(disk.dev)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c condition() false (bad expr), expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "condition(hinv.ncpu >)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c condition() false (singular value == 0), expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "condition(hinv.ncpu < 1)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c condition() false (indom value < 0), expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "condition(-sample.bin)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c condition() true (singular value > 0), expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "values(hinv.ndisk > 0 ? hinv.ndisk : 1 + hinv.ncpu > 0 ? hinv.ndisk : 1)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c hostname() false, expect no instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "hostname(.*[fF][oO][oO].*)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
echo | tee -a $seq_full
echo '== -NV -p -c hostname() true, expect instance to be created' | tee -a $seq_full
cp $tmp.policy.head $tmp.policy
echo "hostname((local|LOCAL)host)" >>$tmp.policy
pmlogctl -NV -p $tmp.policy -c $seq cond-create localhost 2>&1 | _filter
# now use the installed class files, no -p or -c
#
$sudo cp $tmp.policy $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.1
echo | tee -a $seq_full
echo '== -NV, expect simple instance to be created' | tee -a $seq_full
pmlogctl -NV cond-create localhost 2>&1 | _filter
cat <<End-of-File >$tmp.policy
# Installed by PCP QA test $seq on `date`
[class]
$seq.2
[ident]
$seq.2-%h
[control]
\$version=1.1
# same existing config file
%h n n PCP_ARCHIVE_DIR/%i -c $tmp.config
[create]
condition(1)
End-of-File
$sudo cp $tmp.policy $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.2
echo | tee -a $seq_full
echo '== -i, 2 explicit configs, expect concat config file for one pmfind instance' | tee -a $seq_full
$sudo pmlogctl -i $seq cond-create localhost 2>&1 | _filter
pmlogctl -V status 2>&1 | _filter_status
grep sample.lights $PCP_ARCHIVE_DIR/$seq/$seq.config
PCP_DERIVED_CONFIG= pmafm $PCP_ARCHIVE_DIR/$seq/Latest pminfo | _filter
echo "--- start pmlogger config file ---" >>$seq_full
cat $PCP_ARCHIVE_DIR/$seq/$seq.config >>$seq_full
echo "--- end pmlogger config file ---" >>$seq_full
cat <<End-of-File >$tmp.policy
# Installed by PCP QA test $seq on `date`
[class]
$seq.3
[ident]
$seq.3-%h
[control]
\$version=1.1
# no config file @ start
%h n n PCP_ARCHIVE_DIR/%i -c ./%i.config
[create]
condition(hinv.ncpu > 0)
End-of-File
$sudo cp $tmp.policy $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.3
echo | tee -a $seq_full
echo '== -i, + logconf config, expect concat config file for one pmfind instance' | tee -a $seq_full
$sudo pmlogctl -i $seq-a cond-create localhost 2>&1 | _filter
pmlogctl -V status 2>&1 | _filter_status
for metric in sample.lights network.interface.total.bytes disk.dev.total
do
echo "check $metric ..."
grep -E "$metric( |\$)" $PCP_ARCHIVE_DIR/$seq-a/$seq-a.config
PCP_DERIVED_CONFIG= pmafm $PCP_ARCHIVE_DIR/$seq-a/Latest pminfo -v $metric \
| _filter
done
echo "--- start pmlogger config file ---" >>$seq_full
cat $PCP_ARCHIVE_DIR/$seq-a/$seq-a.config >>$seq_full
echo "--- end pmlogger config file ---" >>$seq_full
$sudo cp $tmp.policy $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.2
echo | tee -a $seq_full
echo '== -i, 2x logconf config, expect concat config file for one pmfind instance' | tee -a $seq_full
$sudo pmlogctl -i $seq-b cond-create localhost 2>&1 | _filter
pmlogctl -V status 2>&1 | _filter_status
for metric in sample.lights network.interface.total.bytes disk.dev.total
do
echo "check $metric ..."
grep -E "$metric( |\$)" $PCP_ARCHIVE_DIR/$seq-b/$seq-b.config
PCP_DERIVED_CONFIG= pmafm $PCP_ARCHIVE_DIR/$seq-b/Latest pminfo -v $metric \
| _filter
done
echo "--- start pmlogger config file ---" >>$seq_full
cat $PCP_ARCHIVE_DIR/$seq-b/$seq-b.config >>$seq_full
echo "--- end pmlogger config file ---" >>$seq_full
$sudo cp $tmp.policy $PCP_ETC_DIR/pcp/pmlogger/class.d/$seq.1
echo | tee -a $seq_full
echo '== -i, 3x logconf config, expect concat config file for one pmfind instance' | tee -a $seq_full
$sudo pmlogctl -i $seq-c cond-create localhost 2>&1 | _filter
pmlogctl -V status 2>&1 | _filter_status
for metric in sample.lights network.interface.total.bytes disk.dev.total
do
echo "check $metric ..."
grep -E "$metric( |\$)" $PCP_ARCHIVE_DIR/$seq-c/$seq-c.config
PCP_DERIVED_CONFIG= pmafm $PCP_ARCHIVE_DIR/$seq-c/Latest pminfo -v $metric \
| _filter
done
echo "--- start pmlogger config file ---" >>$seq_full
cat $PCP_ARCHIVE_DIR/$seq-c/$seq-c.config >>$seq_full
echo "--- end pmlogger config file ---" >>$seq_full
status=0
exit
|