Tobias Brunner b77e25c381 testing: The expect-connection helper may use swanctl to check for connections
Depending on the plugin configuration in the test scenario either
`ipsec statusall` or `swanctl --list-conns` is used to check for a named
connection.
2015-12-11 18:26:53 +01:00

34 lines
598 B
Bash
Executable File

#!/bin/bash
#
# Wait until a given IPsec connection becomes available
#
# Params:
# $1 - connection name
# $2 - maximum time to wait in seconds, default is 5 seconds
if [[ $# -lt 1 || $# -gt 2 ]]
then
echo "invalid arguments"
exit 1
fi
secs=$2
[ ! $secs ] && secs=5
cmd="swanctl --list-conns"
grep 'load.*stroke' /etc/strongswan.conf >/dev/null
if [ $? -eq 0 ]; then
cmd="ipsec statusall"
fi
let steps=$secs*10
for i in `seq 1 $steps`
do
$cmd 2>&1 | grep ^[[:space:]]*$1: >/dev/null
[ $? -eq 0 ] && exit 0
sleep 0.1
done
echo "Connection '$1' not available after $secs second(s)"
exit 1