autotest_common: waitforlisten - add 20s timeout and FreeBSD support

In case the process we are waiting for fail to start
listening on RPC socket the test script will stuck till the build times
out. Fix this by adding 20s timeout and 0.5s sleep in the while
loop.

For systems where there is no ip command and netstat output is missing
'Status' column for Unix sockets (like FreeBSD) call the get_rpc_methods
RPC command to check if process is listening.


Change-Id: Ia8b06af7875b65a7fd8be65cf55e92881f6f95db
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/433102
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-11-13 20:48:17 +01:00 committed by Ben Walker
parent f751ea1723
commit db1236ef10

View File

@ -308,40 +308,67 @@ function waitforlisten() {
local rpc_addr="${2:-$DEFAULT_RPC_ADDR}" local rpc_addr="${2:-$DEFAULT_RPC_ADDR}"
if hash ip; then
local have_ip_cmd=true
else
local have_ip_cmd=false
fi
if hash ss; then
local have_ss_cmd=true
else
local have_ss_cmd=false
fi
echo "Waiting for process to start up and listen on UNIX domain socket $rpc_addr..." echo "Waiting for process to start up and listen on UNIX domain socket $rpc_addr..."
# turn off trace for this loop # turn off trace for this loop
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
set +x set +x
local ret=0 local ret=0
while true; do local i
for (( i = 40; i != 0; i-- )); do
# if the process is no longer running, then exit the script # if the process is no longer running, then exit the script
# since it means the application crashed # since it means the application crashed
if ! kill -s 0 $1; then if ! kill -s 0 $1; then
echo "ERROR: process (pid: $1) is no longer running"
ret=1 ret=1
break break
fi fi
# FIXME: don't know how to fix this for FreeBSD
if $have_ip_cmd; then
namespace=$(ip netns identify $1) namespace=$(ip netns identify $1)
if [ -n "$namespace" ]; then if [ -n "$namespace" ]; then
ns_cmd="ip netns exec $namespace" ns_cmd="ip netns exec $namespace"
fi fi
fi
if hash ss; then if $have_ss_cmd; then
if $ns_cmd ss -ln | egrep -q "\s+$rpc_addr\s+"; then if $ns_cmd ss -ln | egrep -q "\s+$rpc_addr\s+"; then
break break
fi fi
else elif [[ "$(uname -s)" == "Linux" ]]; then
# if system doesn't have ss, just assume it has netstat # For Linux, if system doesn't have ss, just assume it has netstat
if $ns_cmd netstat -an | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then if $ns_cmd netstat -an | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then
break break
fi fi
else
# On FreeBSD netstat output 'State' column is missing for Unix sockets.
# To workaround this issue just try to use provided address.
# XXX: This solution could be used for other distros.
if $rootdir/scripts/rpc.py -t 1 -s "$rpc_addr" get_rpc_methods 1>&2 2>/dev/null; then
break
fi fi
fi
sleep 0.5
done done
$shell_restore_x $shell_restore_x
if [ $ret -ne 0 ]; then if (( i == 0 )); then
exit 1 echo "ERROR: timeout while waiting for process (pid: $1) to start listening on '$rpc_addr'"
ret=1
fi fi
return $ret
} }
function waitfornbd() { function waitfornbd() {