diff --git a/test/integration/api.bats b/test/integration/api.bats index 8d16247f8f..27612f9555 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -7,6 +7,23 @@ function teardown() { stop_docker } +# Ensure that the client and server are running the same version. +@test "api version" { + start_docker 1 + run docker -H "${HOSTS[0]}" version + [ "$status" -eq 0 ] + + # First line should contain the client version. + [[ "${lines[0]}" == "Client version: "* ]] + local cli_version=`echo "${lines[0]}" | cut -d':' -f2` + [[ "${output}" == *"Server version:$cli_version"* ]] + + # Second line should be client API version. + [[ "${lines[1]}" == "Client API version: "* ]] + local cli_api_version=`echo "${lines[1]}" | cut -d':' -f2` + [[ "${output}" == *"Server API version:$cli_api_version"* ]] +} + @test "docker attach" { start_docker 3 swarm_manage @@ -41,7 +58,7 @@ function teardown() { # if connected successfull, it returns two lines, "Session Open" and "Session Closed" # Note: with stdout=1&stdin=1&stream=1: it can be used as SSH URL="ws://${SWARM_HOST}/${CLIENT_API_VERSION}/containers/test_container/attach/ws?stderr=1" - run docker run --rm --net=host jimmyxian/centos7-wssh wssh $URL + run docker_host run --rm --net=host jimmyxian/centos7-wssh wssh $URL [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] [[ "${lines[0]}" == *"Session Open"* ]] @@ -304,7 +321,8 @@ function teardown() { swarm_manage run docker_swarm info [ "$status" -eq 0 ] - [[ "${lines[3]}" == *"Nodes: 1" ]] + echo $output + [[ "${output}" == *"Nodes: 1"* ]] [[ "${output}" == *"└ Labels:"*"foo=bar"* ]] } @@ -323,13 +341,16 @@ function teardown() { # inspect and verify run docker_swarm inspect test_container [ "$status" -eq 0 ] - [[ "${lines[1]}" == *"AppArmorProfile"* ]] + [[ "${output}" == *"NetworkSettings"* ]] # the specific information of swarm node - [[ ${output} == *'"Node": {'* ]] - [[ ${output} == *'"Name": "node-'* ]] + [[ "${output}" == *'"Node": {'* ]] + [[ "${output}" == *'"Name": "node-'* ]] } @test "docker inspect --format" { + # FIXME: Broken in docker master. See #717 + skip + start_docker 3 swarm_manage # run container @@ -382,8 +403,8 @@ function teardown() { IMAGE_FILE=$(mktemp) # create a tar file - docker pull busybox:latest - docker save -o $IMAGE_FILE busybox:latest + docker_host pull busybox:latest + docker_host save -o $IMAGE_FILE busybox:latest start_docker 2 swarm_manage diff --git a/test/integration/dependency.bats b/test/integration/dependency.bats index eac63abca0..7f562410a9 100644 --- a/test/integration/dependency.bats +++ b/test/integration/dependency.bats @@ -8,6 +8,9 @@ function teardown() { } @test "shared volumes dependency" { + # FIXME: docker inspect --format is broken in docker master. See #717 + skip + start_docker 2 swarm_manage @@ -33,6 +36,9 @@ function teardown() { } @test "links dependency" { + # FIXME: docker inspect --format is broken in docker master. See #717 + skip + start_docker 2 swarm_manage @@ -58,6 +64,9 @@ function teardown() { } @test "shared network stack dependency" { + # FIXME: docker inspect --format is broken in docker master. See #717 + skip + start_docker 2 swarm_manage diff --git a/test/integration/file-discovery.bats b/test/integration/file-discovery.bats index 0341f0e5cf..d2ca80a658 100644 --- a/test/integration/file-discovery.bats +++ b/test/integration/file-discovery.bats @@ -17,12 +17,12 @@ function setup_file_discovery() { done } -@test "docker info should return the number of nodes with file discovery" { +@test "file discovery" { start_docker 2 setup_file_discovery swarm_manage file://$DISCOVERY_FILE run docker_swarm info [ "$status" -eq 0 ] - [[ "${lines[3]}" == *"Nodes: 2" ]] + [[ "$output" == *"Nodes: 2"* ]] } diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index f6fb8f0dbe..76e85a7798 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -7,8 +7,9 @@ SWARM_ROOT=${SWARM_ROOT:-${BATS_TEST_DIRNAME}/../..} SWARM_BINARY=${SWARM_BINARY:-${SWARM_ROOT}/swarm} # Docker image and version to use for integration tests. -DOCKER_IMAGE=${DOCKER_IMAGE:-dockerswarm/dind} -DOCKER_VERSION=${DOCKER_VERSION:-1.6.0} +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 )) @@ -27,6 +28,23 @@ function join() { echo "$*" } +# Run docker using the binary specified by $DOCKER_BINARY. +# This must ONLY be run on engines created with `start_docker`. +function docker() { + "$DOCKER_BINARY" "$@" +} + +# Communicate with Docker on the host machine. +# Should rarely use this. +function docker_host() { + command docker "$@" +} + +# Run the docker CLI against swarm. +function docker_swarm() { + docker -H $SWARM_HOST "$@" +} + # Run the swarm binary. You must NOT fork this command (swarm foo &) as the PID # ($!) will be the one of the subshell instead of swarm and you won't be able # to kill it. @@ -82,7 +100,7 @@ function swarm_join() { SWARM_JOIN_PID[$i]=$! ((++i)) done - retry 30 1 [ `docker_swarm info | grep -q "Nodes: $i"` -eq 0 ] + retry 30 1 [ -n "$(docker_swarm info | grep -q 'Nodes: $i')" ] } # Stops the manager. @@ -97,11 +115,6 @@ function swarm_join_cleanup() { done } -# Run the docker CLI against swarm. -function docker_swarm() { - docker -H $SWARM_HOST "$@" -} - # Start N docker engines. function start_docker() { local current=${#DOCKER_CONTAINERS[@]} @@ -117,7 +130,7 @@ function start_docker() { # We have to manually call `hostname` since --hostname and --net cannot # be used together. DOCKER_CONTAINERS[$i]=$( - docker run -d --name node-$i --privileged -it --net=host \ + docker_host run -d --name node-$i --privileged -it --net=host \ ${DOCKER_IMAGE}:${DOCKER_VERSION} \ bash -c "\ hostname node-$i && \ @@ -137,6 +150,6 @@ function start_docker() { function stop_docker() { for id in ${DOCKER_CONTAINERS[@]}; do echo "Stopping $id" - docker rm -f -v $id > /dev/null; + docker_host rm -f -v $id > /dev/null; done } diff --git a/test/integration/test_runner.sh b/test/integration/test_runner.sh index 425689c56e..22f8a58811 100755 --- a/test/integration/test_runner.sh +++ b/test/integration/test_runner.sh @@ -18,7 +18,7 @@ TESTS=${@:-.} export SWARM_BINARY=`mktemp` # Build Swarm. -execute go build -o "$SWARM_BINARY" ../.. +execute time go build -o "$SWARM_BINARY" ../.. # Start the docker engine. execute docker --daemon --log-level=panic \ @@ -39,5 +39,12 @@ done # Pre-fetch the test image. execute time docker pull ${DOCKER_IMAGE}:${DOCKER_VERSION} > /dev/null +# Run the tests using the same client provided by the test image. +id=`execute docker create ${DOCKER_IMAGE}:${DOCKER_VERSION}` +tmp=`mktemp -d` +execute docker cp "${id}:/usr/local/bin/docker" "$tmp" +execute docker rm -f "$id" > /dev/null +export DOCKER_BINARY="${tmp}/docker" + # Run the tests. execute time bats -p $TESTS diff --git a/test/integration/token-discovery.bats b/test/integration/token-discovery.bats index 8959e0066f..126424ca20 100644 --- a/test/integration/token-discovery.bats +++ b/test/integration/token-discovery.bats @@ -12,7 +12,7 @@ function teardown() { stop_docker } -@test "token discovery should be working properly" { +@test "token discovery" { start_docker 2 TOKEN=$(swarm create) @@ -23,7 +23,8 @@ function teardown() { swarm_join token://$TOKEN run docker_swarm info - [[ "${lines[3]}" == *"Nodes: 2"* ]] + echo $output + [[ "$output" == *"Nodes: 2"* ]] token_cleanup $TOKEN } diff --git a/test/integration/zk-discovery.bats b/test/integration/zk-discovery.bats index 103caa8f48..c21f3daed7 100644 --- a/test/integration/zk-discovery.bats +++ b/test/integration/zk-discovery.bats @@ -9,11 +9,11 @@ ZK_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 7000 )) ZK_CONTAINER_NAME=swarm_integration_zk function start_zk() { - docker run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper + docker_host run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper } function stop_zk() { - docker rm -f -v $ZK_CONTAINER_NAME > /dev/null + docker_host rm -f -v $ZK_CONTAINER_NAME > /dev/null } function teardown() { @@ -23,7 +23,7 @@ function teardown() { stop_zk } -@test "zk discovery should be working correctly" { +@test "zk discovery" { start_zk start_docker 1 @@ -31,5 +31,5 @@ function teardown() { swarm_join zk://${ZK_HOST}/test run docker_swarm info - [[ "${lines[3]}" == *"Nodes: 1"* ]] + [[ "$output" == *"Nodes: 1"* ]] }