File: 1379

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (157 lines) | stat: -rwxr-xr-x 4,755 bytes parent folder | download
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
#!/bin/sh
# PCP QA Test No. 1379
# Exercise Unix domain socket access to pmproxy and the PMWEBAPI(3)
#
# 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
_get_libpcp_config
$unix_domain_sockets || _notrun "No PCP unix domain socket support"
which curl >/dev/null 2>&1 || _notrun "No curl binary installed"
curl --help all | grep -q unix-socket || _notrun "No curl unix domain socket support"

_cleanup()
{
    cd $here
    if $need_restore
    then
	need_restore=false
	_restore_config $PCP_SYSCONF_DIR/labels
	_restore_config $PCP_SYSCONF_DIR/pmproxy/pmproxy.conf
	_restore_config $PCP_SYSCONF_DIR/pmproxy/pmproxy.options
	_sighup_pmcd
    fi
    if $pmproxy_was_running
    then
	echo "Restart pmproxy ..." >>$seq_full
	_service pmproxy restart >>$seq_full 2>&1
	_wait_for_pmproxy
    else
	echo "Stopping pmproxy ..." >>$seq_full
	_service pmproxy stop >>$seq_full 2>&1
    fi
    $sudo rm -rf $tmp $tmp.*
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

pmproxy_was_running=false
[ -f $PCP_RUN_DIR/pmproxy.pid ] && pmproxy_was_running=true
echo "pmproxy_was_running=$pmproxy_was_running" >>$seq_full

hostname=`hostname`
machineid=`_machine_id`
domainname=`_domain_name`

_filter_json()
{
    echo "== $@ ==" | tee -a $seq_full
    tee -a $seq_full > $tmp.unfiltered

    pmjson < $tmp.unfiltered > $tmp.filtered
    status=$?
    if [ $status -eq 0 ]; then
        cat $tmp.filtered | \
        sed \
            -e '/"machineid": .*/d' \
            -e 's,"series": .*,"series": "SERIES",g' \
            -e 's,"source": .*,"source": "SOURCE",g' \
            -e 's,"context": .*,"context": "CONTEXT",g' \
            -e 's,"hostname": .*,"hostname": "HOSTNAME",g' \
            -e 's,"hostspec": .*,"hostname": "HOSTNAME",g' \
            -e 's,"domainname": .*,"domainname": "DOMAINNAME",g' \
            -e 's,"timestamp": [0-9][0-9]*.[0-9][0-9]*,"timestamp": TIME,g' \
            -e 's,"msec": [0-9][0-9]*,"msec": MILLISECONDS,g' \
            -e 's,"usec": [0-9][0-9]*,"usec": MICROSECONDS,g' \
            -e 's,"nsec": [0-9][0-9]*,"nsec": NANOSECONDS,g' \
            -e 's,"sec": [0-9][0-9]*,"sec": SECONDS,g' \
        #end
        _get_context < $tmp.filtered > $tmp.context
    else
	echo "Invalid JSON: $status"
	cat $tmp.unfiltered
	rm -f $tmp.context
    fi
}

# Expecting 3 lines like ... the ^M's in the last line is a little tricky
#
#  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                 Dload  Upload   Total   Spent    Left  Speed
#^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M100   249  100   249    0     0   243k      0 --:--:-- --:--:-- --:--:--  243k
_filter_curl()
{
    $PCP_AWK_PROG '
/% Total /		{ next }
/ Dload  Upload /	{ next }
/..:..:.. ..:..:../	{ next }
			{ print }'
}

_get_context()
{
    grep '"context"' | \
    sed \
        -e 's/.*context\": //g' \
        -e 's/,$//g' \
    #end
}

# real QA test starts here
_save_config $PCP_SYSCONF_DIR/labels
_save_config $PCP_SYSCONF_DIR/pmproxy/pmproxy.conf
_save_config $PCP_SYSCONF_DIR/pmproxy/pmproxy.options
need_restore=true

$sudo rm -rf $PCP_SYSCONF_DIR/labels/*
_sighup_pmcd || _exit 1

$sudo rm -f $PCP_SYSCONF_DIR/pmproxy/pmproxy.conf $PCP_SYSCONF_DIR/pmproxy/pmproxy.options
echo "--timeseries" >> $tmp.options
$sudo cp $tmp.options $PCP_SYSCONF_DIR/pmproxy/pmproxy.options
echo "[pmproxy]" >> $tmp.conf
echo "pcp.enabled = true" >> $tmp.conf
echo "http.enabled = true" >> $tmp.conf
echo "resp.enabled = true" >> $tmp.conf
echo "secure.enabled = true" >> $tmp.conf
$sudo cp $tmp.conf $PCP_SYSCONF_DIR/pmproxy/pmproxy.conf
cat $tmp.conf >> $seq_full

if ! _service pmproxy stop >/dev/null; then _exit 1; fi
if ! _service pmproxy start >>$seq_full 2>&1; then _exit 1; fi
_wait_for_pmproxy || _exit 1
cat $PCP_LOG_DIR/pmproxy/pmproxy.log >> $seq_full

socket="$PCP_RUN_DIR/pmproxy.socket"

# need sudo here to avoid "Permission denied" when trying to open
# $PCP_RUN_DIR/pmproxy.socket, e.g. on older Debian-based platforms
# also drop -s so we can see errors ... filter expected fluff out
# in _filter_curl
#
$sudo curl --unix-socket "$socket" \
	"http://localhost/pmapi/context" 2>$tmp.err \
| _filter_json "Check context creation on unix socket"
_filter_curl <$tmp.err

context="context=`cat $tmp.context`"
metrics='names=sample.long.one,sample.long.million'

$sudo curl --unix-socket "$socket" \
	"http://localhost/pmapi/fetch?$context&$metrics" 2>$tmp.err \
| _filter_json "Check metric fetching on that context"
_filter_curl <$tmp.err

# success, all done
status=0
exit