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
|
#!/bin/sh
# PCP QA Test No. 1695
# Valgrind pmproxy REST API test cases.
# Copyright (c) 2019 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
. ./common.keys
_check_valgrind
_cleanup()
{
cd $here
[ -n "$key_server_port" ] && $keys_cli -p $key_server_port shutdown
$sudo rm -rf $tmp $tmp.*
}
status=1 # failure is the default!
username=`id -u -n`
trap "_cleanup; exit \$status" 0 1 2 3 15
# create a pmproxy configuration
cat <<EOF > $tmp.conf
[pmproxy]
pcp.enabled = true
http.enabled = true
resp.enabled = false
[discover]
enabled = false
[pmsearch]
enabled = false
[pmseries]
enabled = false
EOF
_filter_port()
{
sed \
-e "s/ FD $port / FD PORT /g" \
-e '/PORT ipv6 /d' \
# end
}
# real QA test starts here
key_server_port=`_find_free_port`
echo "Start test key server ..."
$key_server --port $key_server_port --save "" > $tmp.keys 2>&1 &
_check_key_server_ping $key_server_port
_check_key_server_version $key_server_port
# start pmproxy
port=`_find_free_port`
mkdir -p $tmp.pmproxy/pmproxy
PCP_RUN_DIR=$tmp.pmproxy; export PCP_RUN_DIR
PCP_TMP_DIR=$tmp.pmproxy; export PCP_TMP_DIR
$valgrind_clean_assert pmproxy -f -r $key_server_port -p $port -U $username -l- -c $tmp.conf >$tmp.valout 2>$tmp.valerr &
pid=$!
echo "valgrind pid: $pid" >>$seq_full
echo "pmproxy port: $port" >>$seq_full
# valgrind takes awhile to fire up
i=0
while [ $i -lt 40 ]
do
$PCP_BINADM_DIR/telnet-probe -c localhost $port && break
sleep 1
i=`expr $i + 1`
done
if $PCP_BINADM_DIR/telnet-probe -c localhost $port
then
echo "Startup took $i secs" >>$seq_full
else
echo "Arrgh: valgrind failed start pmproxy and get port $port ready after 30 secs"
exit
fi
params="polltimeout=20"
jsonreq="-H Accept:application/json"
if which fuser >/dev/null
then
echo "fuser for port $port ..." >>$seq_full
$sudo fuser -n tcp $port >>$seq_full 2>&1
fi
if which pstree >/dev/null
then
echo "pstree for pid $pid" >>$seq_full
$sudo pstree -p $pid >>$seq_full 2>&1
fi
date >>$seq_full
echo "=== checking metric scrape operation ===" | tee -a $seq_full
curl -Gs "http://localhost:$port/metrics?$params" >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
echo "=== checking metric scrape JSON operation ===" | tee -a $seq_full
curl -Gs $jsonreq "http://localhost:$port/metrics?$params" >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
date >>$seq_full
echo "=== checking short-fuse scrape operation ===" | tee -a $seq_full
curl -Gs "http://localhost:$port/metrics?polltimeout=1" >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
date >>$seq_full
echo "=== checking repeated scrape operation ===" | tee -a $seq_full
for f in `seq 1 100`; do
curl -Gs "http://localhost:$port/metrics?names=kernel.all.load" >$tmp.tmp 2>&1
done
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
date >>$seq_full
echo "=== checking one client making multiple requests ===" | tee -a $seq_full
context="http://localhost:$port/pmapi/context"
curl -Gs $context $context >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
date >>$seq_full
echo "=== checking metric fetch operation ===" | tee -a $seq_full
metrics="sample.colour,sample.long.one,sample.long.one,sample.double.one"
curl -Gs "http://localhost:$port/pmapi/fetch?names=$metrics&$params" >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
date >>$seq_full
echo "=== checking url escaping operation ===" | tee -a $seq_full
metrics="%2Csample.long.one%2Csample.double.one%2C%2C" # %2C == ','
curl -Gs "http://localhost:$port/pmapi/fetch?names=$metrics&$params" >$tmp.tmp 2>&1
grep "^curl" $tmp.tmp
cat $tmp.tmp >>$seq_full
echo "=== check pmproxy is running ==="
pminfo -v -h localhost@localhost:$port hinv.ncpu
if [ $? -eq 0 ]; then
echo "pmproxy check passed"
else
echo "pmproxy check failed"
fi
# valgrind takes awhile to shutdown too
pmsignal $pid
pmsleep 3.5
echo "=== valgrind stdout ===" | tee -a $seq_full
cat $tmp.valout | _filter_valgrind
echo "=== valgrind stderr ===" | tee -a $seq_full
cat $tmp.valerr | _filter_pmproxy_log | _filter_port
# success, all done
status=0
exit
|