diff --git a/libnetwork/Makefile b/libnetwork/Makefile index 15ece669f9..05b1249361 100644 --- a/libnetwork/Makefile +++ b/libnetwork/Makefile @@ -10,12 +10,7 @@ cidocker = docker run ${ciargs} ${dockerargs} golang:1.4 all: ${build_image}.created build check integration-tests clean integration-tests: ./cmd/dnet/dnet - @if [ ! -d ./integration-tmp ]; then \ - mkdir -p ./integration-tmp; \ - git clone https://github.com/sstephenson/bats.git ./integration-tmp/bats; \ - ./integration-tmp/bats/install.sh ./integration-tmp; \ - fi - @./integration-tmp/bin/bats ./test/integration/dnet + @./test/integration/dnet/run-integration-tests.sh ./cmd/dnet/dnet: make build-local @@ -76,7 +71,7 @@ run-tests: done @echo "Done running tests" -check-local: check-format check-code start-services run-tests +check-local: check-format check-code start-services run-tests install-deps: apt-get update && apt-get -y install iptables zookeeperd diff --git a/libnetwork/test/integration/dnet/dnet.bats b/libnetwork/test/integration/dnet/dnet.bats index 3d3a94261a..e5c60dc055 100644 --- a/libnetwork/test/integration/dnet/dnet.bats +++ b/libnetwork/test/integration/dnet/dnet.bats @@ -3,13 +3,13 @@ load helpers @test "Test dnet custom port" { - start_dnet 1 a none null 4567 + start_dnet 1 a 4567 dnet_cmd 4567 network ls stop_dnet 1 a } @test "Test dnet invalid custom port" { - start_dnet 1 b none null 4567 + start_dnet 1 b 4567 run dnet_cmd 4568 network ls echo ${output} [ "$status" -ne 0 ] @@ -17,7 +17,7 @@ load helpers } @test "Test dnet invalid params" { - start_dnet 1 c none null + start_dnet 1 c run dnet_cmd 8080 network ls echo ${output} [ "$status" -ne 0 ] diff --git a/libnetwork/test/integration/dnet/helpers.bash b/libnetwork/test/integration/dnet/helpers.bash index b2fe6f59ca..7f6cfba05d 100644 --- a/libnetwork/test/integration/dnet/helpers.bash +++ b/libnetwork/test/integration/dnet/helpers.bash @@ -2,6 +2,10 @@ function inst_id2port() { echo $((41000+${1}-1)) } +function dnet_container_name() { + echo dnet-$1-$2 +} + function start_consul() { stop_consul docker run -d \ @@ -25,18 +29,19 @@ function stop_consul() { function start_dnet() { stop_dnet $1 $2 - name="dnet-$1-$2" - if [ -z "$5" ] + name=$(dnet_container_name $1 $2) + if [ -z "$3" ] then hport=$((41000+${1}-1)) cport=2385 hopt="" else - hport=$5 - cport=$5 + hport=$3 + cport=$3 hopt="-H tcp://0.0.0.0:${cport}" fi + bridge_ip=$(docker inspect --format '{{.NetworkSettings.Gateway}}' pr_consul) mkdir -p /tmp/dnet/${name} tomlfile="/tmp/dnet/${name}/libnetwork.toml" cat > ${tomlfile} <> ${tomlfile} </dev/null 2>&1 +cmap[pr_consul]=pr_consul + +# Test dnet configuration options +./integration-tmp/bin/bats ./test/integration/dnet/dnet.bats + +# Test a single node configuration with a global scope test driver + +## Setup +start_dnet 1 simple 1>/dev/null 2>&1 +cmap[dnet-1-simple]=dnet-1-simple + +## Run the test cases +./integration-tmp/bin/bats ./test/integration/dnet/simple.bats + +## Teardown +stop_dnet 1 simple 1>/dev/null 2>&1 +unset cmap[dnet-1-simple] + +# Test multi node configuration with a global scope test driver + +## Setup +start_dnet 1 multi 1>/dev/null 2>&1 +cmap[dnet-1-multi]=dnet-1-multi +start_dnet 2 multi 1>/dev/null 2>&1 +cmap[dnet-2-multi]=dnet-2-multi +start_dnet 3 multi 1>/dev/null 2>&1 +cmap[dnet-3-multi]=dnet-3-multi + +## Run the test cases +./integration-tmp/bin/bats ./test/integration/dnet/multi.bats + +## Teardown +stop_dnet 1 multi 1>/dev/null 2>&1 +unset cmap[dnet-1-multi] +stop_dnet 2 multi 1>/dev/null 2>&1 +unset cmap[dnet-2-multi] +stop_dnet 3 multi 1>/dev/null 2>&1 +unset cmap[dnet-3-multi] + +# Suite teardowm +stop_consul 1>/dev/null 2>&1 +unset cmap[pr_consul] diff --git a/libnetwork/test/integration/dnet/simple.bats b/libnetwork/test/integration/dnet/simple.bats index 5654cb7efc..5b96797472 100644 --- a/libnetwork/test/integration/dnet/simple.bats +++ b/libnetwork/test/integration/dnet/simple.bats @@ -2,33 +2,6 @@ load helpers -function setup() { - if [ "${BATS_TEST_NUMBER}" -eq 1 ]; then - start_consul - start_dnet 1 simple multihost test - fi -} - -function teardown() { - if [ "${BATS_TEST_NUMBER}" -eq 6 ]; then - stop_dnet 1 simple - stop_consul - fi -} - -@test "Test default network" { - echo $(docker ps) - run dnet_cmd $(inst_id2port 1) network ls - [ "$status" -eq 0 ] - echo ${output} - echo ${lines[1]} - name=$(echo ${lines[1]} | cut -d" " -f2) - driver=$(echo ${lines[1]} | cut -d" " -f3) - echo ${name} ${driver} - [ "$name" = "multihost" ] - [ "$driver" = "test" ] -} - @test "Test network create" { echo $(docker ps) run dnet_cmd $(inst_id2port 1) network create -d test mh1 @@ -54,9 +27,10 @@ function teardown() { @test "Test service create" { echo $(docker ps) + dnet_cmd $(inst_id2port 1) network create -d test multihost run dnet_cmd $(inst_id2port 1) service publish svc1.multihost - [ "$status" -eq 0 ] echo ${output} + [ "$status" -eq 0 ] run dnet_cmd $(inst_id2port 1) service ls [ "$status" -eq 0 ] echo ${output} @@ -67,10 +41,12 @@ function teardown() { [ "$network" = "multihost" ] [ "$svc" = "svc1" ] dnet_cmd $(inst_id2port 1) service unpublish svc1.multihost + dnet_cmd $(inst_id2port 1) network rm multihost } @test "Test service delete with id" { echo $(docker ps) + dnet_cmd $(inst_id2port 1) network create -d test multihost run dnet_cmd $(inst_id2port 1) service publish svc1.multihost [ "$status" -eq 0 ] echo ${output} @@ -79,11 +55,13 @@ function teardown() { echo ${output} echo ${lines[1]} id=$(echo ${lines[1]} | cut -d" " -f1) - dnet_cmd $(inst_id2port 1) service unpublish ${id} + dnet_cmd $(inst_id2port 1) service unpublish ${id}.multihost + dnet_cmd $(inst_id2port 1) network rm multihost } @test "Test service attach" { echo $(docker ps) + dnet_cmd $(inst_id2port 1) network create -d test multihost dnet_cmd $(inst_id2port 1) service publish svc1.multihost dnet_cmd $(inst_id2port 1) container create container_1 dnet_cmd $(inst_id2port 1) service attach container_1 svc1.multihost @@ -96,4 +74,5 @@ function teardown() { dnet_cmd $(inst_id2port 1) service detach container_1 svc1.multihost dnet_cmd $(inst_id2port 1) container rm container_1 dnet_cmd $(inst_id2port 1) service unpublish svc1.multihost + dnet_cmd $(inst_id2port 1) network rm multihost }