diff --git a/libnetwork/test/integration/dnet/bridge.bats b/libnetwork/test/integration/dnet/bridge.bats new file mode 100644 index 0000000000..12c265f0ae --- /dev/null +++ b/libnetwork/test/integration/dnet/bridge.bats @@ -0,0 +1,157 @@ +# -*- mode: sh -*- +#!/usr/bin/env bats + +load helpers + +function test_single_network_connectivity() { + local nw_name start end + + nw_name=${1} + start=1 + end=${2} + + # Create containers and connect them to the network + for i in `seq ${start} ${end}`; + do + dnet_cmd $(inst_id2port 1) container create container_${i} + net_connect 1 container_${i} ${nw_name} + done + + # Now test connectivity between all the containers using service names + for i in `seq ${start} ${end}`; + do + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_${i}) \ + "ping -c 1 container_${j}" + done + done + + # Teardown the container connections and the network + for i in `seq ${start} ${end}`; + do + net_disconnect 1 container_${i} ${nw_name} + dnet_cmd $(inst_id2port 1) container rm container_${i} + done +} + +@test "Test default bridge network" { + skip_for_circleci + + echo $(docker ps) + test_single_network_connectivity bridge 3 +} + +@test "Test bridge network" { + skip_for_circleci + + echo $(docker ps) + dnet_cmd $(inst_id2port 1) network create -d bridge singlehost + test_single_network_connectivity singlehost 3 + dnet_cmd $(inst_id2port 1) network rm singlehost +} + +@test "Test bridge network dnet restart" { + skip_for_circleci + + echo $(docker ps) + dnet_cmd $(inst_id2port 1) network create -d bridge singlehost + + for iter in `seq 1 2`; + do + test_single_network_connectivity singlehost 3 + docker restart dnet-1-bridge + sleep 2 + done + + dnet_cmd $(inst_id2port 1) network rm singlehost +} + +@test "Test multiple bridge networks" { + skip_for_circleci + + echo $(docker ps) + + start=1 + end=3 + + for i in `seq ${start} ${end}`; + do + dnet_cmd $(inst_id2port 1) container create container_${i} + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + + if [ "$i" -lt "$j" ]; then + dnet_cmd $(inst_id2port 1) network create -d bridge sh${i}${j} + nw=sh${i}${j} + else + nw=sh${j}${i} + fi + + osvc="svc${i}${j}" + dnet_cmd $(inst_id2port 1) service publish ${osvc}.${nw} + dnet_cmd $(inst_id2port 1) service attach container_${i} ${osvc}.${nw} + done + done + + for i in `seq ${start} ${end}`; + do + echo ${i1} + for j in `seq ${start} ${end}`; + do + echo ${j1} + if [ "$i" -eq "$j" ]; then + continue + fi + + osvc="svc${j}${i}" + echo "pinging ${osvc}" + dnet_cmd $(inst_id2port 1) service ls + runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_${i}) "cat /etc/hosts" + runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_${i}) "ping -c 1 ${osvc}" + done + done + + for i in `seq ${start} ${end}`; + do + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + + if [ "$i" -lt "$j" ]; then + nw=sh${i}${j} + else + nw=sh${j}${i} + fi + + osvc="svc${i}${j}" + dnet_cmd $(inst_id2port 1) service detach container_${i} ${osvc}.${nw} + dnet_cmd $(inst_id2port 1) service unpublish ${osvc}.${nw} + + done + dnet_cmd $(inst_id2port 1) container rm container_${i} + done + + for i in `seq ${start} ${end}`; + do + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + + if [ "$i" -lt "$j" ]; then + dnet_cmd $(inst_id2port 1) network rm sh${i}${j} + fi + done + done + +} diff --git a/libnetwork/test/integration/dnet/helpers.bash b/libnetwork/test/integration/dnet/helpers.bash index 935ae28092..5a6a6e3237 100644 --- a/libnetwork/test/integration/dnet/helpers.bash +++ b/libnetwork/test/integration/dnet/helpers.bash @@ -6,6 +6,23 @@ function dnet_container_name() { echo dnet-$1-$2 } +function get_sbox_id() { + local line + + line=$(dnet_cmd $(inst_id2port ${1}) service ls | grep ${2}) + echo ${line} | cut -d" " -f5 +} + +function net_connect() { + dnet_cmd $(inst_id2port ${1}) service publish ${2}.${3} + dnet_cmd $(inst_id2port ${1}) service attach ${2} ${2}.${3} +} + +function net_disconnect() { + dnet_cmd $(inst_id2port ${1}) service detach ${2} ${2}.${3} + dnet_cmd $(inst_id2port ${1}) service unpublish ${2}.${3} +} + function start_consul() { stop_consul docker run -d \ @@ -28,6 +45,7 @@ function stop_consul() { } function start_dnet() { + local inst suffix name hport cport hopt neighip bridge_ip labels tomlfile inst=$1 shift suffix=$1 @@ -39,7 +57,6 @@ function start_dnet() { hport=$((41000+${inst}-1)) cport=2385 hopt="" - isnum='^[0-9]+$' while [ -n "$1" ] do @@ -62,10 +79,12 @@ function start_dnet() { labels="\"com.docker.network.driver.overlay.bind_interface=eth0\", \"com.docker.network.driver.overlay.neighbor_ip=${neighip}\"" fi + echo "parsed values: " ${name} ${hport} ${cport} ${hopt} ${neighip} ${labels} + mkdir -p /tmp/dnet/${name} tomlfile="/tmp/dnet/${name}/libnetwork.toml" cat > ${tomlfile} <>${INTEGRATION_ROOT}/test.log 2>&1 unset cmap[dnet-3-multi] +## Setup +start_dnet 1 bridge 1>>${INTEGRATION_ROOT}/test.log 2>&1 +cmap[dnet-1-bridge]=dnet-1-bridge + +## Run the test cases +./integration-tmp/bin/bats ./test/integration/dnet/bridge.bats +#docker logs dnet-1-bridge + +## Teardown +stop_dnet 1 bridge 1>>${INTEGRATION_ROOT}/test.log 2>&1 +unset cmap[dnet-1-bridge] + ## Setup start_dnet 1 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1 cmap[dnet-1-overlay]=dnet-1-overlay diff --git a/libnetwork/test/integration/dnet/simple.bats b/libnetwork/test/integration/dnet/simple.bats index 5b96797472..96365eaae3 100644 --- a/libnetwork/test/integration/dnet/simple.bats +++ b/libnetwork/test/integration/dnet/simple.bats @@ -7,6 +7,8 @@ load helpers run dnet_cmd $(inst_id2port 1) network create -d test mh1 echo ${output} [ "$status" -eq 0 ] + run dnet_cmd $(inst_id2port 1) network ls + echo ${output} line=$(dnet_cmd $(inst_id2port 1) network ls | grep mh1) echo ${line} name=$(echo ${line} | cut -d" " -f2) @@ -32,9 +34,9 @@ load helpers echo ${output} [ "$status" -eq 0 ] run dnet_cmd $(inst_id2port 1) service ls - [ "$status" -eq 0 ] echo ${output} echo ${lines[1]} + [ "$status" -eq 0 ] svc=$(echo ${lines[1]} | cut -d" " -f2) network=$(echo ${lines[1]} | cut -d" " -f3) echo ${svc} ${network}