zsh completions: minor tweaks
[pcp.git] / qa / 1111
bloba2072b562e99f5daa174e0af3be13b7456673256
1 #! /bin/sh
2 # PCP QA Test No. 1111
3 # checks basic pcp2influxdb functionality
5 # Copyright (c) 2015 Red Hat, Inc.
7 seq=`basename $0`
8 echo "QA output created by $seq"
10 . ./common.python
12 $python -c "from pcp import pmapi" >/dev/null 2>&1
13 [ $? -eq 0 ] || _notrun "python pcp pmapi module not installed"
14 which socat >/dev/null 2>&1 || _notrun "socat binary not installed"
15 which pcp2influxdb >$seq.full 2>&1 || _notrun "pcp2influxdb not installed"
17 $python -c "import requests" >/dev/null 2>&1
18 [ $? -eq 0 ] || _notrun "python requests module not installed"
19 major=`$python -c 'import requests; print(requests.__version__.split(".")[0])'`
20 [ $major -ge 1 ] || _notrun "python requests module too old (v$major)"
22 port=8086
23 echo | $PCP_BINADM_DIR/telnet-probe localhost $port \
24 && _notrun "Someone already listening on typical InfluxDB $port"
26 $sudo rm -rf $seq.full $tmp.*
27 signal=$PCP_BINADM_DIR/pmsignal
28 status=1 # failure is the default!
30 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
32 _full_stash()
34 echo "--- pcp2influxdb stdout --" >>$seq.full
35 cat $tmp.p2i.out >>$seq.full
36 echo "--- pcp2influxdb stderr --" >>$seq.full
37 cat $tmp.p2i.err >>$seq.full
38 echo "--- socket cat stdout --" >>$seq.full
39 cat $tmp.socat.out >>$seq.full
40 echo "--- socket cat stderr --" >>$seq.full
41 cat $tmp.socat.err >>$seq.full
44 scale=10
45 ncpu=`pmprobe -v hinv.ncpu | awk '{print $3*'$scale'".0"}'`
46 pcp2influxdb="$python `which pcp2influxdb`"
48 echo | tee -a $seq.full
49 echo "=== 1. pcp2influxdb one-shot noauth ===" | tee -a $seq.full
50 socat tcp-listen:$port,reuseaddr - >$tmp.socat.out 2>$tmp.socat.err &
51 pid=$!
52 sleep 2
53 $pcp2influxdb --database roar -t 1 hinv.ncpu >$tmp.p2i.out 2>$tmp.p2i.err & # will error out after socket cat dies
54 p2ipid=$!
55 sleep 3
56 $signal $pid $p2ipid 2>/dev/null
57 wait
58 egrep -q "^POST \/write\?db=roar" $tmp.socat.out
59 [ $? -eq 0 ] && echo "Found POST URL in noauth output"
60 egrep -q "hinv_ncpu value=[0-9]+(\.[0-9]+)? [0-9]+$" $tmp.socat.out
61 [ $? -eq 0 ] && echo "Found proper metric body in noauth output"
62 _full_stash
64 echo "=== 2. pcp2influxdb noauth with tags ===" | tee -a $seq.full
65 socat tcp-listen:$port,reuseaddr - >$tmp.socat.out 2>$tmp.socat.err &
66 pid=$!
67 sleep 2
68 $pcp2influxdb --database roar --tag-string host=me.example.com -t 1 hinv.ncpu \
69 >$tmp.p2i.out 2>$tmp.p2i.err & # will error out after socket cat dies
70 p2ipid=$!
71 sleep 3
72 $signal $pid $p2ipid 2>/dev/null
73 wait
74 egrep -q "^POST \/write\?db=roar" $tmp.socat.out
75 [ $? -eq 0 ] && echo "Found POST URL in noauth output"
76 egrep -q "hinv_ncpu,host=me\.example\.com value=[0-9]+(\.[0-9]+)? [0-9]+$" $tmp.socat.out
77 [ $? -eq 0 ] && echo "Found proper metric body in noauth output"
78 _full_stash
80 echo "=== 3. pcp2influxdb auth with tags ===" | tee -a $seq.full
81 socat tcp-listen:$port,reuseaddr - >$tmp.socat.out 2>$tmp.socat.err &
82 pid=$!
83 sleep 2
84 $pcp2influxdb --database roar --db-user pcp --db-password hey \
85 --tag-string host=me.example.com -t 1 hinv.ncpu \
86 >$tmp.p2i.out 2>$tmp.p2i.err & # will error out after socket cat dies
87 p2ipid=$!
88 sleep 3
89 $signal $pid $p2ipid 2>/dev/null
90 wait
91 egrep -q "^POST \/write\?db=roar" $tmp.socat.out
92 [ $? -eq 0 ] && echo "Found POST URL in output"
93 egrep -q "Authorization: Basic cGNwOmhleQ==" $tmp.socat.out
94 [ $? -eq 0 ] && echo "Found auth data in HTTP request"
95 egrep -q "hinv_ncpu,host=me\.example\.com value=[0-9]+(\.[0-9]+)? [0-9]+$" $tmp.socat.out
96 [ $? -eq 0 ] && echo "Found proper metric body in output"
97 _full_stash
99 echo "=== 4. pcp2influxdb bad-instance tolerance ===" | tee -a $seq.full
100 rm -f $tmp.socat.out $tmp.socat.err
101 socat tcp-listen:$port,reuseaddr - >>$tmp.socat.out 2>>$tmp.socat.err &
102 pid=$!
103 sleep 2
104 $pcp2influxdb -t 2 sample.bogus_bin sample.aggregate.null sample.string.hullo NoSuchMetric sample.bad >$tmp.p2i.out 2>$tmp.p2i.err &
105 p2ipid=$!
106 sleep 8 # enough for at least 2 messages
107 $signal $pid $p2ipid 2>/dev/null
108 wait
109 grep 'Excluding' $tmp.p2i.err
110 _full_stash
112 status=0
113 exit