integration helpers: Allow to run multiple managers.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2015-07-28 18:26:17 -07:00
parent c82a953422
commit 22dcdc245d
1 changed files with 15 additions and 7 deletions

View File

@ -17,8 +17,8 @@ DOCKER_IMAGE=${DOCKER_IMAGE:-dockerswarm/dind-master}
DOCKER_VERSION=${DOCKER_VERSION:-latest}
DOCKER_BINARY=${DOCKER_BINARY:-`command -v docker`}
# Host on which the manager will listen to (random port between 6000 and 7000).
SWARM_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 6000 ))
# Port on which the manager will listen to (random port between 6000 and 7000).
SWARM_BASE_PORT=$(( ( RANDOM % 1000 ) + 6000 ))
# Use a random base port (for engines) between 5000 and 6000.
BASE_PORT=$(( ( RANDOM % 1000 ) + 5000 ))
@ -50,7 +50,7 @@ function docker_host() {
# Run the docker CLI against swarm.
function docker_swarm() {
docker -H $SWARM_HOST "$@"
docker -H ${SWARM_HOSTS[0]} "$@"
}
# Run the swarm binary. You must NOT fork this command (swarm foo &) as the PID
@ -94,9 +94,15 @@ function swarm_manage() {
discovery="$@"
fi
"$SWARM_BINARY" -l debug manage -H "$SWARM_HOST" --heartbeat=1s "$discovery" &
SWARM_PID=$!
wait_until_reachable "$SWARM_HOST"
local i=${#SWARM_MANAGE_PID[@]}
local port=$(($SWARM_BASE_PORT + $i))
local host=127.0.0.1:$port
echo "$SWARM_BINARY" -l debug manage -H "$host" --heartbeat=1s $discovery
"$SWARM_BINARY" -l debug manage -H "$host" --heartbeat=1s $discovery &
SWARM_MANAGE_PID[$i]=$!
SWARM_HOSTS[$i]=$host
wait_until_reachable "$host"
}
# swarm join every engine created with `start_docker`.
@ -124,7 +130,9 @@ function swarm_join() {
# Stops the manager.
function swarm_manage_cleanup() {
kill $SWARM_PID || true
for pid in ${SWARM_MANAGE_PID[@]}; do
kill $pid || true
done
}
# Clean up Swarm join processes