python api: fix syntax error in recent context changes
[pcp.git] / qa / 1090
blob5edd9df4bf1b6880e543fa69b78c28caff4f29fe
1 #!/bin/sh
2 # PCP QA Test No. 1090
3 # Reproduce https://github.com/performancecopilot/pcp/issues/14
5 # Copyright (c) 2015 Ken McDonell. All Rights Reserved.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get webapi glue (includes standard environment, filters and checks)
12 . ./common.webapi
14 which curl >/dev/null 2>&1 || _notrun "No curl binary installed"
15 [ -f ${PCP_BINADM_DIR}/pmwebd ] || _notrun "pmwebd package not installed"
17 _cleanup()
19 cd $here
20 $sudo $PCP_RC_DIR/pmwebd stop >>$here/$seq.full 2>&1
21 $sudo $PCP_RC_DIR/pcp start >>$here/$seq.full 2>&1
22 _wait_for_pmcd
23 _wait_for_pmlogger
24 rm -rf $tmp.*
27 status=1 # failure is the default!
28 $sudo rm -rf $tmp $tmp.* $seq.full
29 trap "_cleanup; exit \$status" 0 1 2 3 15
31 _dump_curl()
33 echo "$1 curl ..." >>$here/$seq.full
34 echo "<stdout>" >>$here/$seq.full
35 ( cat $tmp.out; echo ) >>$here/$seq.full
36 echo "<stderr>" >>$here/$seq.full
37 ( cat $tmp.err; echo ) >>$here/$seq.full
40 _get_context()
42 # get a pmapi context reference from pmwebd
44 curl -s http://localhost:44323/pmapi/context?hostspec=localhost >$tmp.out 2>$tmp.err
45 _dump_curl context
46 # get context from a line like in $tmp.out
47 # { "context": 2062287553 }
48 ( cat $tmp.out; echo ) | $PCP_AWK_PROG '$2 == "\"context\":" { print $3 }'
51 _get_metrics()
53 # fetch metrics from context $1
55 curl -s http://localhost:44323/pmapi/"$1"/_metric?prefix=sample.long >$tmp.out 2>$tmp.err
56 _dump_curl metrics
57 # metrics are in lines like ...
58 # {"name":"sample.long.one","text-oneline":"1 as a 32-bit integer","text-help":"1 as a 32-bit integer","pmid":121634826,"sem":"instant","units":"","type":"32"},
59 ( cat $tmp.out; echo ) \
60 | grep '^{"name":' $tmp.out | sed -e 's/"text-help".*/.../' >$tmp.metrics
61 if [ -s $tmp.metrics ]
62 then
63 echo "Got these metrics ..."
64 cat $tmp.metrics
65 else
66 echo "Failed to get metrics ..."
67 cat $tmp.out; echo
71 $sudo $PCP_RC_DIR/pmwebd stop >>$here/$seq.full 2>&1
72 $sudo $PCP_RC_DIR/pmwebd start
73 _wait_for_pmwebd 44323
75 # real QA test starts here
76 ctx1=`_get_context`
77 echo "ctx1=$ctx1" >>$here/$seq.full
78 if [ -z "$ctx1" ]
79 then
80 echo "Arrg, failed to get context number from ..."
81 cat $tmp.out; echo
82 exit
84 echo "Got first context number."
85 _get_metrics $ctx1
87 # kill off pmcd
88 echo "Killing off pmcd ..."
89 $sudo $PCP_RC_DIR/pmcd stop 2>&1 | _filter_pcp_stop
91 echo "Retrying first context ..."
92 _get_metrics $ctx1
94 ctx2=`_get_context`
95 echo "ctx2=$ctx2" >>$here/$seq.full
96 if [ -n "$ctx2" ]
97 then
98 echo "Warning: got second context number from ..."
99 cat $tmp.out; echo
100 # ok, even though this is wrong (although it used to be that way),
101 # let's try and get some metrics ...
103 _get_metrics $ctx2
104 else
105 echo "No context number, as expected."
108 # start pmcd
109 echo "Restarting pmcd ..."
110 $sudo $PCP_RC_DIR/pmcd start 2>&1 | _filter_pcp_stop
111 _wait_for_pmcd
113 ctx3=`_get_context`
114 echo "ctx3=$ctx3" >>$here/$seq.full
115 if [ -z "$ctx3" ]
116 then
117 echo "Arrg, failed to get context number from ..."
118 cat $tmp.out; echo
119 exit
121 echo "Got third context number."
122 _get_metrics $ctx3
124 echo "Retrying first context ..."
125 _get_metrics $ctx1
127 # success, all done
128 status=0
130 exit