integration: Improved discovery testing.

Verify that swarm can see new nodes joining discovery.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2015-05-05 19:14:59 -07:00
parent 9124f3a0c7
commit 3501e45f4f
3 changed files with 44 additions and 29 deletions

View File

@ -5,27 +5,30 @@ load helpers
# create a blank temp file for discovery # create a blank temp file for discovery
DISCOVERY_FILE=$(mktemp) DISCOVERY_FILE=$(mktemp)
function setup() {
start_docker 2
}
function teardown() { function teardown() {
swarm_manage_cleanup swarm_manage_cleanup
stop_docker stop_docker
rm -f $DISCOVERY_FILE rm -f "$DISCOVERY_FILE"
} }
function setup_file_discovery() { function setup_file_discovery() {
rm -f "$DISCOVERY_FILE"
for host in ${HOSTS[@]}; do for host in ${HOSTS[@]}; do
echo "$host" >> $DISCOVERY_FILE echo "$host" >> $DISCOVERY_FILE
done done
} }
@test "file discovery" { @test "file discovery" {
# Start 2 engines, register them in a file, then start swarm and make sure
# it sees them.
start_docker 2
setup_file_discovery setup_file_discovery
swarm_manage file://$DISCOVERY_FILE swarm_manage "file://$DISCOVERY_FILE"
all_nodes_registered_in_swarm
run docker_swarm info # Add another engine to the cluster, update the discovery file and make
[ "$status" -eq 0 ] # sure it's picked up by swarm.
[[ "$output" == *"Nodes: 2"* ]] start_docker 1
setup_file_discovery
retry 10 1 all_nodes_registered_in_swarm
} }

View File

@ -2,32 +2,38 @@
load helpers load helpers
function token_cleanup() { TOKEN=""
curl -X DELETE https://discovery-stage.hub.docker.com/v1/clusters/$1
}
function setup() { function token_cleanup() {
start_docker 2 [ -z "$TOKEN" ] && return
echo "Removing $TOKEN"
curl -X DELETE "https://discovery-stage.hub.docker.com/v1/clusters/$TOKEN"
} }
function teardown() { function teardown() {
swarm_join_cleanup
swarm_manage_cleanup swarm_manage_cleanup
swarm_join_cleanup
stop_docker stop_docker
token_cleanup
} }
@test "token discovery" { @test "token discovery" {
# Create a cluster and validate the token.
run swarm create run swarm create
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" =~ ^[0-9a-f]{32}$ ]] [[ "$output" =~ ^[0-9a-f]{32}$ ]]
TOKEN="$output" TOKEN="$output"
swarm_manage "token://$TOKEN" # Start 2 engines and make them join the cluster.
start_docker 2
swarm_join "token://$TOKEN" swarm_join "token://$TOKEN"
run docker_swarm info # Start a manager and ensure it sees all the engines.
echo $output swarm_manage "token://$TOKEN"
[[ "$output" == *"Nodes: 2"* ]] all_nodes_registered_in_swarm
token_cleanup "$TOKEN" # Add another engine to the cluster and make sure it's picked up by swarm.
start_docker 1
swarm_join "token://$TOKEN"
retry 10 1 all_nodes_registered_in_swarm
} }

View File

@ -9,31 +9,37 @@ ZK_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 7000 ))
ZK_CONTAINER_NAME=swarm_integration_zk ZK_CONTAINER_NAME=swarm_integration_zk
function start_zk() { function start_zk() {
run docker run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper run docker_host run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
function stop_zk() { function stop_zk() {
run docker rm -f -v $ZK_CONTAINER_NAME run docker_host rm -f -v $ZK_CONTAINER_NAME
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
function setup() { function setup() {
start_zk start_zk
start_docker 2
} }
function teardown() { function teardown() {
swarm_join_cleanup
swarm_manage_cleanup swarm_manage_cleanup
swarm_join_cleanup
stop_docker stop_docker
stop_zk stop_zk
} }
@test "zookeeperk discovery" { @test "zookeeper discovery" {
swarm_manage zk://${ZK_HOST}/test # Start 2 engines and make them join the cluster.
swarm_join zk://${ZK_HOST}/test start_docker 2
swarm_join "zk://${ZK_HOST}/test"
run docker_swarm info # Start a manager and ensure it sees all the engines.
[[ "$output" == *"Nodes: 2"* ]] swarm_manage "zk://${ZK_HOST}/test"
all_nodes_registered_in_swarm
# Add another engine to the cluster and make sure it's picked up by swarm.
start_docker 1
swarm_join "zk://${ZK_HOST}/test"
retry 30 1 all_nodes_registered_in_swarm
} }