Skip to content

Commit

Permalink
[FAB-3013] Run servers at 0.0.0.0 in the FVT image
Browse files Browse the repository at this point in the history
The load driver can be used to run load tests against any
Fabric CA server. Since the FVT image has capability to run
Fabric CA server in cluster topology fronted by a proxy, it is
recommended that FVT image is used to run load tests. Note that
the load-test make target runs the load against FVT image.

In order for servers to be accessible in the host machine,
they need to be run at 0.0.0.0 but on different ports in
the FVT image. This will allow us to analyze the cpu/memory
profiles from the host machine using tool like go-torch, which
is not installed in the FVT image.

With this change, Fabric CA servers in the FVT image will run
on different ports at IP 0.0.0.0.

Change-Id: Ia183fb2e4e7382a4a0625156df08238f8ca844e9
Signed-off-by: Anil Ambati <[email protected]>
  • Loading branch information
Anil Ambati committed Aug 25, 2017
1 parent 940cc6a commit 7bca42a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 31 deletions.
107 changes: 79 additions & 28 deletions scripts/fvt/fabric-ca_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function usage() {
echo " -X) set PROXY='true' - start haproxy for \$FABRIC_CA_INSTANCES of fabric-ca servers"
echo " -K) set KILL='true' - kill all running fabric-ca instances and haproxy"
echo " -L) list all running fabric-ca instances"
echo " -P) Enable profiling port on the server"
echo " ?|h) this help text"
echo ""
echo "Defaults: -d sqlite3 -n 1 -k ecdsa -l 256"
Expand Down Expand Up @@ -57,9 +58,12 @@ resetFabricCa(){

listFabricCa(){
echo "Listening servers;"
lsof -n -i tcp:${USER_CA_PORT-$CA_DEFAULT_PORT}


local port=${USER_CA_PORT-$CA_DEFAULT_PORT}
local inst=0
while test $((inst)) -lt $FABRIC_CA_INSTANCES; do
lsof -n -i tcp:$((port+$inst))
inst=$((inst+1))
done
case $DRIVER in
mysql)
echo ""
Expand Down Expand Up @@ -134,7 +138,7 @@ function startHaproxy() {
defaults
log global
option dontlognull
maxconn 1024
maxconn 4096
timeout connect 5000
timeout client 50000
timeout server 50000
Expand All @@ -146,15 +150,36 @@ frontend haproxy
default_backend fabric-cas
backend fabric-cas
mode tcp
mode tcp
balance roundrobin";
# For each requested instance passed to startHaproxy
# (which is determined by the -n option passed to the
# main script) create a backend server in haproxy config
# Each server binds to a unique port on INADDR_ANY
while test $((i)) -lt $inst; do
echo " server server$i localhost:$((server_port+$i))"
i=$((i+1))
done
if test -n "$FABRIC_CA_SERVER_PROFILE_PORT" ; then
echo "
frontend haproxy-profile
bind *:8889
mode http
option tcplog
default_backend fabric-ca-profile
backend fabric-ca-profile
mode http
http-request set-header X-Forwarded-Port %[dst_port]
balance roundrobin";
# For each requested instance passed to startHaproxy
# (which is determined by the -n option passed to the
# main script) create a backend server in haproxy config
# Each server uses a separate loopback address.
while test $((i++)) -lt $inst; do
echo " server server$i 127.0.0.$i:$server_port"
done)
while test $((i)) -lt $inst; do
echo " server server$i localhost:$((FABRIC_CA_SERVER_PROFILE_PORT+$i))"
i=$((i+1))
done
fi
)
;;
*)
haproxy -f <(echo "global
Expand All @@ -165,7 +190,7 @@ defaults
mode http
option httplog
option dontlognull
maxconn 1024
maxconn 4096
timeout connect 5000
timeout client 50000
timeout server 50000
Expand All @@ -187,9 +212,28 @@ backend fabric-cas
mode http
http-request set-header X-Forwarded-Port %[dst_port]
balance roundrobin";
while test $((i++)) -lt $inst; do
echo " server server$i 127.0.0.$i:$server_port"
done)
while test $((i)) -lt $inst; do
echo " server server$i localhost:$((server_port+$i))"
i=$((i+1))
done
if test -n "$FABRIC_CA_SERVER_PROFILE_PORT" ; then
echo "
frontend haproxy-profile
bind *:8889
mode http
option tcplog
default_backend fabric-ca-profile
backend fabric-ca-profile
mode http
http-request set-header X-Forwarded-Port %[dst_port]
balance roundrobin";
while test $((i)) -lt $inst; do
echo " server server$i localhost:$((FABRIC_CA_SERVER_PROFILE_PORT+$i))"
i=$((i+1))
done
fi
)
;;
esac

Expand All @@ -200,22 +244,27 @@ function startFabricCa() {
local start=$SECONDS
local timeout="$((TIMEOUT*2))"
local now=0
local server_addr=127.0.0.$inst
local server_addr=0.0.0.0
local port=${USER_CA_PORT-$CA_DEFAULT_PORT}
port=$((port+$inst))
# if not explcitly set, use default
test -n "${USER_CA_PORT-$CA_DEFAULT_PORT}" && local server_port="--port ${USER_CA_PORT-$CA_DEFAULT_PORT}" || local server_port=""
test -n "${port}" && local server_port="--port $port" || local server_port=""

inst=0
$FABRIC_CA_SERVEREXEC start --address $server_addr $server_port --ca.certfile $DST_CERT \
if test -n "$FABRIC_CA_SERVER_PROFILE_PORT" ; then
local profile_port=$((FABRIC_CA_SERVER_PROFILE_PORT+$inst))
FABRIC_CA_SERVER_PROFILE_PORT=$profile_port $FABRIC_CA_SERVEREXEC start --address $server_addr $server_port --ca.certfile $DST_CERT \
--ca.keyfile $DST_KEY --config $RUNCONFIG 2>&1 &
# --db.datasource $DATASRC --ca.keyfile $DST_KEY --config $RUNCONFIG 2>&1 | sed 's/^/ /' &
until test "$started" = "$server_addr:${USER_CA_PORT-$CA_DEFAULT_PORT}" -o "$now" -gt "$timeout"; do
started=$(ss -ltnp src $server_addr:${USER_CA_PORT-$CA_DEFAULT_PORT} | awk 'NR!=1 {print $4}')
test "$started" = "$server_addr:${USER_CA_PORT-$CA_DEFAULT_PORT}" && break
else
$FABRIC_CA_SERVEREXEC start --address $server_addr $server_port --ca.certfile $DST_CERT \
--ca.keyfile $DST_KEY --config $RUNCONFIG 2>&1 &
fi
until test "$started" = ":::$port" -o "$now" -gt "$timeout"; do
started=$(ss -ltnp src :$port | awk 'NR!=1 {print $4}')
sleep .1
let now+=1
done
printf "FABRIC_CA server on $server_addr:${USER_CA_PORT-$CA_DEFAULT_PORT} "
if test "$started" = "$server_addr:${USER_CA_PORT-$CA_DEFAULT_PORT}"; then
printf "FABRIC_CA server on $server_addr:$port "
if test "$started" = ":::$port"; then
echo "STARTED"
else
RC=$((RC+1))
Expand All @@ -230,7 +279,7 @@ function killAllFabricCas() {
test -n "$proxypids" && kill $proxypids
}

while getopts "\?hRCISKXLDTAad:t:l:n:c:k:x:g:m:p:r:o:" option; do
while getopts "\?hRCISKXLDTAPad:t:l:n:c:k:x:g:m:p:r:o:" option; do
case "$option" in
a) LDAP_ENABLE="true" ;;
o) TIMEOUT="$OPTARG" ;;
Expand All @@ -254,6 +303,7 @@ while getopts "\?hRCISKXLDTAad:t:l:n:c:k:x:g:m:p:r:o:" option; do
K) KILL="true" ;;
L) LIST="true" ;;
T) TLS_ON="true" ;;
P) export FABRIC_CA_SERVER_PROFILE_PORT=$PROFILING_PORT ;;
\?|h) usage
exit 1
;;
Expand Down Expand Up @@ -322,8 +372,9 @@ test -n "$SERVERCONFIG" && cp "$SERVERCONFIG" "$RUNCONFIG"
$($INIT) && initFabricCa
if $($START); then
inst=0
while test $((inst++)) -lt $FABRIC_CA_INSTANCES; do
while test $((inst)) -lt $FABRIC_CA_INSTANCES; do
startFabricCa $inst
inst=$((inst+1))
done
fi
exit $RC
1 change: 1 addition & 0 deletions scripts/fvt/fabric-ca_utils
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export ROOTCERT="$TESTDATA/root.pem"
export CA_HOST_ADDRESS="localhost"
export PROXY_PORT="7054"
export CA_DEFAULT_PORT="1${PROXY_PORT}"
export PROFILING_PORT="2${PROXY_PORT}"

DATE='date +%Y-%m-%d'
TIME='date +%I:%M:%S%p'
Expand Down
3 changes: 2 additions & 1 deletion scripts/fvt/reenroll_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ for driver in sqlite3 postgres mysql; do
done

if ! $(${FABRIC_TLS:-false}); then
for s in $(eval echo {1..$NUM_SERVERS}); do
nums=$((NUM_SERVERS-1))
for s in $(eval echo {0..$nums}); do
curl -s http://${HOST}/ | awk -v s="server${s}" '$0~s'|html2text|grep HTTP
verifyServerTraffic $HOST server${s} $EXPECTED_DISTRIBUTION
test $? -ne 0 && ErrorMsg "Distributed traffic to server FAILED"
Expand Down
3 changes: 2 additions & 1 deletion scripts/fvt/reregister_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ for driver in sqlite3 postgres mysql; do
# all servers should register = number of successful requests
# but...it's only available when tls is disabled
if ! $(${FABRIC_TLS:-false}); then
for s in $(eval echo {1..$NUM_SERVERS}); do
nums=$((NUM_SERVERS-1))
for s in $(eval echo {0..$nums}); do
curl -s http://${HOST}/ | awk -v s="server${s}" '$0~s'|html2text|grep HTTP
verifyServerTraffic $HOST server${s} 0 0 "HTTP 5xx" gt
test $? -eq 0 || ErrorMsg "verifyServerTraffic failed"
Expand Down
3 changes: 2 additions & 1 deletion scripts/fvt/roundrobin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ for driver in sqlite3 mysql postgres ; do
test $? -ne 0 && ErrorMsg "registerAndEnroll failed"
reenroll admin
if ! $(${FABRIC_TLS:-false}); then
for s in $(eval echo {1..$NUM_SERVERS}); do
nums=$((NUM_SERVERS-1))
for s in $(eval echo {0..$nums}); do
curl -s http://$HOST/ |
awk -v s="server${s}\"" '$0~s'|
html2text |
Expand Down

0 comments on commit 7bca42a

Please sign in to comment.