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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
#!/bin/sh
# PCP QA Test No. 1458
# Exercise access pmproxy with secure.enabled = false
#
# The main purpose of this is to test that the component works correctly
# when secure.enabled = false; we can expect the https URLs to fail.
#
# See https://github.com/performancecopilot/pcp/issues/1490
# Copyright (c) 2019,2021 Red Hat
# Modified by Netflix, Inc.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
_check_series # pmseries availability means libuv is in use
_check_valgrind
openssl help 2>/dev/null || _notrun "No openssl binary found"
if [ -f /etc/lsb-release ]
then
. /etc/lsb-release
if [ "$DISTRIB_ID" = Ubuntu ]
then
# This test fails for Ubuntu 19.10 with a myriad of errors involving
# the use of uninitialized values. The code paths very but typically
# involve libuv -> libssl -> libcrypto
#
case "$DISTRIB_RELEASE"
in
19.10)
_notrun "problems with libuv, libssl, libcrypto and valgrind on Ubuntu $DISTRIB_RELEASE"
;;
esac
fi
fi
_cleanup()
{
cd $here
if $need_restore
then
need_restore=false
_restore_config $PCP_SYSCONF_DIR/labels
_sighup_pmcd
fi
date >>$seq_full
for suff in '' .prev
do
echo "--- $PCP_LOG_DIR/pmproxy/pmproxy.log$suff ---" >>$seq_full
if [ -f $PCP_LOG_DIR/pmproxy/pmproxy.log$suff ]
then
cat $PCP_LOG_DIR/pmproxy/pmproxy.log$suff >>$seq_full
else
echo "... does not exist" >>$seq_full
fi
done
if $restart_redis
then
_service redis-server start
echo "Restarting redis-server ..." >>$seq_full
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID]|/[r]edis-server( |$)' >>$seq_full
fi
$sudo rm -rf $tmp $tmp.*
}
status=1 # failure is the default!
need_restore=false
username=`id -u -n`
trap "_cleanup; exit \$status" 0 1 2 3 15
# if redis-server is installed and running, it needs to be at least
# version 5 ... otherwise stop redis-server and restart when this
# test is done
# redis-server --version output looks like
# Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=c15f5256d258cb6b
#
restart_redis=false
if which redis-server >/dev/null 2>&1
then
redis_vers=`redis-server --version | sed -e 's/.* v=//' -e 's/ .*//'`
echo "redis_vers=$redis_vers" >>$seq_full
case "$redis_vers"
in
1.*|2.*|3.*|4.*)
# too old for pmproxy
#
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID]|/[r]edis-server( |$)' >>$seq_full
redis_pid=`$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep '[r]edis-server ' | $PCP_AWK_PROG '{print $2}'`
echo "redis_pid=$redis_pid" >>$seq_full
if [ -n "$redis_pid" ]
then
_service redis-server stop
restart_redis=true
fi
;;
esac
fi
_check_empty()
{
tee -a $seq_full > $tmp.unfiltered
if [ -s $tmp.unfiltered ]
then
echo "Botch: got output from curl"
else
echo "Good!, empty output from curl"
fi
}
_filter_json()
{
tee -a $seq_full > $tmp.unfiltered
if [ -s $tmp.unfiltered ]
then
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,"context": .*,"context": "CONTEXT",g' \
-e 's,"hostname": .*,"hostname": "HOSTNAME",g' \
-e 's,"domainname": .*,"domainname": "DOMAINNAME",g' \
#end
else
echo "Invalid JSON: $status"
cat $tmp.unfiltered
rm -f $tmp.context
fi
else
echo "Botch: no output from curl"
fi
}
_filter_port()
{
sed \
-e '/ ipv6 /d' \
-e "s/ $port / PORT /g" \
#end
}
# real QA test starts here
_save_config $PCP_SYSCONF_DIR/labels
need_restore=true
$sudo rm -rf $PCP_SYSCONF_DIR/labels/*
_sighup_pmcd || _exit 1
openssl req \
-new -newkey rsa:4096 -days 365 -nodes -x509 \
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.pcpqa.com" \
-keyout $tmp.key -out $tmp.cert >>$seq_full 2>&1
# creates a self-signed (insecure) certificate, so for testing only
echo "[keys]" >> $tmp.conf
echo "enabled = false" >> $tmp.conf
echo "[pmproxy]" >> $tmp.conf
echo "http.enabled = true" >> $tmp.conf
echo "secure.enabled = false" >> $tmp.conf
port=`_find_free_port`
mkdir -p $tmp.pmproxy/pmproxy
export PCP_RUN_DIR=$tmp.pmproxy
export PCP_TMP_DIR=$tmp.pmproxy
$valgrind_clean_assert pmproxy -f -l- --timeseries \
-c $tmp.conf -p $port -U $username \
>$tmp.valout 2>$tmp.valerr &
pid=$!
echo "valgrind pid: $pid" >>$seq_full
echo "pmproxy port: $port" >>$seq_full
# valgrind takes awhile to fire up
date >>$seq_full
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 40 secs"
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID]|/[p]mproxy( |$)|[v]algrind ' >$tmp.triage 2>&1
if [ -s $tmp.triage ]
then
echo "--- likely looking processes ..." >>$seq_full
cat $tmp.triage >>$seq_full
else
echo "--- there are no likely looking processes!" >>$seq_full
fi
echo "--- valgrind stdout ---" >>$seq_full
cat $tmp.valout >>$seq_full
echo "--- valgrind stderr ---" >>$seq_full
cat $tmp.valerr >>$seq_full
exit
fi
date >>$seq_full
echo "=== checking serial http operation ===" | tee -a $seq_full
for i in 1 2 3 4; do
curl -Gs "http://localhost:$port/pmapi/metric?name=sample.long.ten" 2>$tmp.err$i >$tmp.out$i
done
for i in 1 2 3 4; do
echo === out$i === | tee -a $seq_full
_filter_json < $tmp.out$i
done
date >>$seq_full
echo "=== checking parallel http operation ===" | tee -a $seq_full
for i in 1 2 3 4; do
curl -Gs "http://localhost:$port/pmapi/metric?name=sample.long.ten" 2>$tmp.err$i >$tmp.out$i & 2>/dev/null eval pid$i=$!
done
wait $pid1 $pid2 $pid3 $pid4
for i in 1 2 3 4; do
echo === out$i === | tee -a $seq_full
_filter_json < $tmp.out$i
done
date >>$seq_full
echo "=== checking serial https/TLS operation ===" | tee -a $seq_full
for i in 1 2 3 4; do
curl -k -Gs "https://localhost:$port/pmapi/metric?name=sample.long.ten" 2>$tmp.err$i >$tmp.out$i
done
for i in 1 2 3 4; do
echo === out$i === | tee -a $seq_full
_check_empty < $tmp.out$i
done
date >>$seq_full
echo "=== checking parallel https/TLS operation ===" | tee -a $seq_full
for i in 1 2 3 4; do
curl -k -Gs "https://localhost:$port/pmapi/metric?name=sample.long.ten" 2>$tmp.err$i >$tmp.out$i & 2>/dev/null eval pid$i=$!
done
wait $pid1 $pid2 $pid3 $pid4
for i in 1 2 3 4; do
echo === out$i === | tee -a $seq_full
_check_empty < $tmp.out$i
done
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 >/dev/null 2>&1
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 \
| sed -e '/Cannot connect to key server: Connection refused/d'
# final kill if it's spinning
$sudo kill -9 $pid >/dev/null 2>&1
# success, all done
status=0
exit
|