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
|
#!/bin/sh
# PCP QA Test No. 1090
# Reproduce https://github.com/performancecopilot/pcp/issues/14
# originally, but since then exercises context re-connection in
# the PMWEBAPI.
#
# Copyright (c) 2015 Ken McDonell. All Rights Reserved.
# 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
_check_series
which curl >/dev/null 2>&1 || _notrun "No curl binary installed"
# only restart pmproxy if it was running before the QA test starts
restart_pmproxy=false
[ -n "`_get_pids_by_name pmproxy`" ] && restart_pmproxy=true
_cleanup()
{
cd $here
_service pmproxy stop >/dev/null 2>&1
_restore_auto_restart pmproxy
$restart_pmproxy && _service pmproxy restart >/dev/null 2>&1
rm -rf $tmp.*
}
status=1 # failure is the default!
port=44322
trap "_cleanup; exit \$status" 0 1 2 3 15
_dump_curl()
{
echo "$1 curl ..." >>$seq_full
echo "<stdout>" >>$seq_full
( cat $tmp.out; echo ) >>$seq_full
echo "<stderr>" >>$seq_full
( cat $tmp.err; echo ) >>$seq_full
}
_get_context()
{
# get a pmapi context reference from pmwebapi
curl -s "http://localhost:$port/pmapi/context?hostspec=localhost&polltimeout=50000" >$tmp.out 2>$tmp.err
_dump_curl context
# { [...,] "context": 2062287553 [,...] }
pmjson -n < $tmp.out \
| $PCP_AWK_PROG '$1 == "\"context\":" { print $2 }' \
| sed -e 's/,//g' \
#end
}
_get_metrics()
{
# fetch metrics from context $1
#
curl -s http://localhost:$port/pmapi/"$1"/_metric?prefix=sample.long >$tmp.out 2>$tmp.err
_dump_curl metrics
# metrics are in lines like ...
# { [...,] "name": "sample.long.one" [,...] }
pmjson < $tmp.out \
| grep '"name"' \
| sed -e 's/^ *//g' \
| sed -e 's/,$//g' \
> $tmp.metrics
if [ -s $tmp.metrics ]
then
echo "Got these metrics ..."
cat $tmp.metrics
else
echo "Failed to get metrics ..."
pmjson < $tmp.out \
| sed -e '/"context":/d' \
> $tmp.nometrics
cat $tmp.nometrics
fi
#cat $PCP_LOG_DIR/pmproxy/pmproxy.log
}
_stop_auto_restart pmproxy
if ! _service pmproxy stop >/dev/null 2>&1; then _exit 1; fi
if ! _service pmproxy start; then _exit 1; fi \
| _filter_pmproxy_start
_wait_for_pmproxy $port || _exit 1
# real QA test starts here
ctx1=`_get_context`
echo "ctx1=$ctx1" >>$seq_full
if [ -z "$ctx1" ]
then
echo "Arrg, failed to get context number from ..."
cat $tmp.out; echo
exit
fi
echo "Got first context number."
_get_metrics $ctx1
# kill off pmcd
echo "Killing off pmcd ..."
if ! _service pmcd stop 2>&1; then _exit 1; fi | _filter_pcp_stop
echo "Retrying first context ..."
_get_metrics $ctx1
ctx2=`_get_context`
echo "ctx2=$ctx2" >>$seq_full
if [ -n "$ctx2" ]
then
echo "Warning: got second context number from ..."
cat $tmp.out; echo
# ok, even though this is wrong (although it used to be that way),
# let's try and get some metrics ...
#
_get_metrics $ctx2
else
echo "No context number, as expected."
fi
# start pmcd
echo "Restarting pmcd ..."
if ! _service pmcd start 2>&1; then _exit 1; fi | _filter_pcp_start
_wait_for_pmcd || _exit 1
ctx3=`_get_context`
echo "ctx3=$ctx3" >>$seq_full
if [ -z "$ctx3" ]
then
echo "Arrg, failed to get context number from ..."
cat $tmp.out; echo
exit
fi
echo "Got third context number."
_get_metrics $ctx3
echo "Retrying first context ..."
_get_metrics $ctx1
# success, all done
status=0
exit
|