From a250ded7159cdca0737a36939bb7c103ce73b352 Mon Sep 17 00:00:00 2001 From: Isabel Jimenez Date: Tue, 1 Dec 2015 19:02:21 -0500 Subject: [PATCH] Adding zk tests for swarm-mesos integration Signed-off-by: Isabel Jimenez --- test/integration/mesos/mesos_helpers.bash | 18 ++++++++++ test/integration/mesos/zk/zk.bats | 40 +++++++++++++++++++++++ test/integration/test_runner.sh | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/integration/mesos/zk/zk.bats diff --git a/test/integration/mesos/mesos_helpers.bash b/test/integration/mesos/mesos_helpers.bash index 9f30eb74f6..d310630b93 100644 --- a/test/integration/mesos/mesos_helpers.bash +++ b/test/integration/mesos/mesos_helpers.bash @@ -27,6 +27,24 @@ function start_mesos() { done } +function start_mesos_zk() { + local current=${#DOCKER_CONTAINERS[@]} + MESOS_MASTER=$( + docker_host run -d --name mesos-master --net=host \ + $MESOS_IMAGE mesos-master --ip=127.0.0.1 --work_dir=/var/lib/mesos --registry=in_memory --quorum=2 --zk=$1 --port=$MESOS_MASTER_PORT + ) + + retry 10 1 eval "docker_host ps | grep 'mesos-master'" + for ((i=0; i < current; i++)); do + local docker_port=$(echo ${HOSTS[$i]} | cut -d: -f2) + MESOS_SLAVES[$i]=$( + docker_host run --privileged -d --name mesos-slave-$i --volumes-from node-$i -e DOCKER_HOST="${HOSTS[$i]}" -v /sys/fs/cgroup:/sys/fs/cgroup --net=host \ + $MESOS_IMAGE mesos-slave --master=127.0.0.1:$MESOS_MASTER_PORT --containerizers=docker --attributes="docker_port:$docker_port" --hostname=127.0.0.1 --port=$(($MESOS_MASTER_PORT + (1 + $i))) --docker=/usr/local/bin/docker --executor_environment_variables="{\"DOCKER_HOST\":\"${HOSTS[$i]}\"}" + ) + retry 10 1 eval "docker_host ps | grep 'mesos-slave-$i'" + done +} + # Stop mesos master and slave. function stop_mesos() { echo "Stopping $MESOS_MASTER" diff --git a/test/integration/mesos/zk/zk.bats b/test/integration/mesos/zk/zk.bats new file mode 100644 index 0000000000..4a68afa968 --- /dev/null +++ b/test/integration/mesos/zk/zk.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats + +load ../mesos_helpers + +# Address on which the store will listen (random port between 8000 and 9000). +STORE_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 7000 )) + +# Discovery parameter for Swarm +DISCOVERY="zk://${STORE_HOST}/test" + +# Container name for integration test +CONTAINER_NAME=swarm_integration_zk + +function start_store() { + docker_host run --name $CONTAINER_NAME -p $STORE_HOST:2181 -d dnephin/docker-zookeeper:3.4.6 +} + +function stop_store() { + docker_host rm -f -v $CONTAINER_NAME +} + +function teardown() { + swarm_manage_cleanup + stop_mesos + stop_docker + stop_store +} + +@test "mesos - zookeeper" { + start_store + start_docker 2 + start_mesos_zk $DISCOVERY + + swarm_manage --cluster-driver mesos-experimental $DISCOVERY + sleep 5 + + run docker_swarm info + [ "$status" -eq 0 ] + [[ "${output}" == *'Offers: 2'* ]] +} diff --git a/test/integration/test_runner.sh b/test/integration/test_runner.sh index f706f6053a..a278aed763 100755 --- a/test/integration/test_runner.sh +++ b/test/integration/test_runner.sh @@ -12,7 +12,7 @@ function execute() { } # Tests to run. Defaults to all. -TESTS=${@:-. compose discovery api mesos/api mesos/compose} +TESTS=${@:-. compose discovery api mesos/api mesos/compose mesos/zk} # Generate a temporary binary for the tests. export SWARM_BINARY=`mktemp`