mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add bridge network integration tests
Add a few bridge network integration tests which specifically deals with multiple bridge networks and libnetwork restart and persistence Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
a13f78369f
commit
a22ce0938c
6 changed files with 231 additions and 31 deletions
157
libnetwork/test/integration/dnet/bridge.bats
Normal file
157
libnetwork/test/integration/dnet/bridge.bats
Normal file
|
@ -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
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,23 @@ function dnet_container_name() {
|
||||||
echo dnet-$1-$2
|
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() {
|
function start_consul() {
|
||||||
stop_consul
|
stop_consul
|
||||||
docker run -d \
|
docker run -d \
|
||||||
|
@ -28,6 +45,7 @@ function stop_consul() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_dnet() {
|
function start_dnet() {
|
||||||
|
local inst suffix name hport cport hopt neighip bridge_ip labels tomlfile
|
||||||
inst=$1
|
inst=$1
|
||||||
shift
|
shift
|
||||||
suffix=$1
|
suffix=$1
|
||||||
|
@ -39,7 +57,6 @@ function start_dnet() {
|
||||||
hport=$((41000+${inst}-1))
|
hport=$((41000+${inst}-1))
|
||||||
cport=2385
|
cport=2385
|
||||||
hopt=""
|
hopt=""
|
||||||
isnum='^[0-9]+$'
|
|
||||||
|
|
||||||
while [ -n "$1" ]
|
while [ -n "$1" ]
|
||||||
do
|
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}\""
|
labels="\"com.docker.network.driver.overlay.bind_interface=eth0\", \"com.docker.network.driver.overlay.neighbor_ip=${neighip}\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "parsed values: " ${name} ${hport} ${cport} ${hopt} ${neighip} ${labels}
|
||||||
|
|
||||||
mkdir -p /tmp/dnet/${name}
|
mkdir -p /tmp/dnet/${name}
|
||||||
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
|
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
|
||||||
cat > ${tomlfile} <<EOF
|
cat > ${tomlfile} <<EOF
|
||||||
title = "LibNetwork Configuration file"
|
title = "LibNetwork Configuration file for ${name}"
|
||||||
|
|
||||||
[daemon]
|
[daemon]
|
||||||
debug = false
|
debug = false
|
||||||
|
@ -73,13 +92,13 @@ title = "LibNetwork Configuration file"
|
||||||
[cluster]
|
[cluster]
|
||||||
discovery = "consul://${bridge_ip}:8500"
|
discovery = "consul://${bridge_ip}:8500"
|
||||||
Heartbeat = 10
|
Heartbeat = 10
|
||||||
[globalstore]
|
[scopes]
|
||||||
embedded = false
|
[scopes.global]
|
||||||
[globalstore.client]
|
embedded = false
|
||||||
provider = "consul"
|
[scopes.global.client]
|
||||||
Address = "${bridge_ip}:8500"
|
provider = "consul"
|
||||||
|
address = "${bridge_ip}:8500"
|
||||||
EOF
|
EOF
|
||||||
echo "parsed values: " ${name} ${hport} ${cport} ${hopt}
|
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--name=${name} \
|
--name=${name} \
|
||||||
|
@ -101,6 +120,8 @@ function skip_for_circleci() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop_dnet() {
|
function stop_dnet() {
|
||||||
|
local name
|
||||||
|
|
||||||
name=$(dnet_container_name $1 $2)
|
name=$(dnet_container_name $1 $2)
|
||||||
rm -rf /tmp/dnet/${name} || true
|
rm -rf /tmp/dnet/${name} || true
|
||||||
docker stop ${name} || true
|
docker stop ${name} || true
|
||||||
|
@ -111,6 +132,8 @@ function stop_dnet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dnet_cmd() {
|
function dnet_cmd() {
|
||||||
|
local hport
|
||||||
|
|
||||||
hport=$1
|
hport=$1
|
||||||
shift
|
shift
|
||||||
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
|
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
|
||||||
|
@ -121,6 +144,8 @@ function dnet_exec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function runc() {
|
function runc() {
|
||||||
|
local dnet
|
||||||
|
|
||||||
dnet=${1}
|
dnet=${1}
|
||||||
shift
|
shift
|
||||||
dnet_exec ${dnet} "cp /var/lib/docker/network/files/${1}*/* /scratch/rootfs/etc"
|
dnet_exec ${dnet} "cp /var/lib/docker/network/files/${1}*/* /scratch/rootfs/etc"
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
# -*- mode: sh -*-
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
load helpers
|
load helpers
|
||||||
|
|
||||||
|
function is_network_exist() {
|
||||||
|
line=$(dnet_cmd $(inst_id2port $1) network ls | grep ${2})
|
||||||
|
name=$(echo ${line} | cut -d" " -f2)
|
||||||
|
driver=$(echo ${line} | cut -d" " -f3)
|
||||||
|
if [ "$name" == "$2" -a "$driver" == "$3" ]; then
|
||||||
|
echo "true"
|
||||||
|
else
|
||||||
|
echo "false"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
@test "Test multinode network create" {
|
@test "Test multinode network create" {
|
||||||
echo $(docker ps)
|
echo $(docker ps)
|
||||||
for i in `seq 1 3`;
|
for i in `seq 1 3`;
|
||||||
|
@ -13,19 +25,17 @@ load helpers
|
||||||
|
|
||||||
for j in `seq 1 3`;
|
for j in `seq 1 3`;
|
||||||
do
|
do
|
||||||
line=$(dnet_cmd $(inst_id2port $j) network ls | grep ${oname})
|
result=$(is_network_exist $j ${oname} test)
|
||||||
echo ${output}
|
[ "$result" = "true" ]
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
echo ${line}
|
|
||||||
name=$(echo ${line} | cut -d" " -f2)
|
|
||||||
driver=$(echo ${line} | cut -d" " -f3)
|
|
||||||
echo ${name} ${driver}
|
|
||||||
[ "$name" = "$oname" ]
|
|
||||||
[ "$driver" = "test" ]
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Always try to remove the network from the first node
|
# Always try to remove the network from the second node
|
||||||
dnet_cmd $(inst_id2port 1) network rm ${oname}
|
dnet_cmd $(inst_id2port 2) network rm ${oname}
|
||||||
|
echo "delete ${oname}"
|
||||||
|
nresult=$(is_network_exist 1 ${oname} test)
|
||||||
|
echo ${nresult}
|
||||||
|
dnet_cmd $(inst_id2port 1) network ls
|
||||||
|
[ "$nresult" = "false" ]
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +107,7 @@ load helpers
|
||||||
dnet_cmd $(inst_id2port $i) network create -d test ${oname}
|
dnet_cmd $(inst_id2port $i) network create -d test ${oname}
|
||||||
dnet_cmd $(inst_id2port $i) service publish ${osvc}.${oname}
|
dnet_cmd $(inst_id2port $i) service publish ${osvc}.${oname}
|
||||||
dnet_cmd $(inst_id2port $i) container create container_${i}
|
dnet_cmd $(inst_id2port $i) container create container_${i}
|
||||||
|
dnet_cmd $(inst_id2port $i) network ls
|
||||||
dnet_cmd $(inst_id2port $i) service attach container_${i} ${osvc}.${oname}
|
dnet_cmd $(inst_id2port $i) service attach container_${i} ${osvc}.${oname}
|
||||||
|
|
||||||
for j in `seq 1 3`;
|
for j in `seq 1 3`;
|
||||||
|
|
|
@ -14,35 +14,28 @@ load helpers
|
||||||
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
|
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
|
||||||
for i in `seq ${start} ${end}`;
|
for i in `seq ${start} ${end}`;
|
||||||
do
|
do
|
||||||
osvc="svc$i"
|
|
||||||
dnet_cmd $(inst_id2port $i) service publish ${osvc}.multihost
|
|
||||||
dnet_cmd $(inst_id2port $i) container create container_${i}
|
dnet_cmd $(inst_id2port $i) container create container_${i}
|
||||||
dnet_cmd $(inst_id2port $i) service attach container_${i} ${osvc}.multihost
|
net_connect ${i} container_${i} multihost
|
||||||
done
|
done
|
||||||
|
|
||||||
# Now test connectivity between all the containers using service names
|
# Now test connectivity between all the containers using service names
|
||||||
for i in `seq ${start} ${end}`;
|
for i in `seq ${start} ${end}`;
|
||||||
do
|
do
|
||||||
src="svc$i"
|
|
||||||
line=$(dnet_cmd $(inst_id2port $i) service ls | grep ${src})
|
|
||||||
echo ${line}
|
|
||||||
sbid=$(echo ${line} | cut -d" " -f5)
|
|
||||||
for j in `seq ${start} ${end}`;
|
for j in `seq ${start} ${end}`;
|
||||||
do
|
do
|
||||||
if [ "$i" -eq "$j" ]; then
|
if [ "$i" -eq "$j" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
runc $(dnet_container_name $i overlay) ${sbid} "ping -c 1 svc$j"
|
runc $(dnet_container_name $i overlay) $(get_sbox_id ${i} container_${i}) \
|
||||||
|
"ping -c 1 container_$j"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
# Teardown the container connections and the network
|
# Teardown the container connections and the network
|
||||||
for i in `seq ${start} ${end}`;
|
for i in `seq ${start} ${end}`;
|
||||||
do
|
do
|
||||||
osvc="svc$i"
|
net_disconnect ${i} container_${i} multihost
|
||||||
dnet_cmd $(inst_id2port $i) service detach container_${i} ${osvc}.multihost
|
|
||||||
dnet_cmd $(inst_id2port $i) container rm container_${i}
|
dnet_cmd $(inst_id2port $i) container rm container_${i}
|
||||||
dnet_cmd $(inst_id2port $i) service unpublish ${osvc}.multihost
|
|
||||||
done
|
done
|
||||||
|
|
||||||
run dnet_cmd $(inst_id2port 2) network rm multihost
|
run dnet_cmd $(inst_id2port 2) network rm multihost
|
||||||
|
|
|
@ -78,6 +78,18 @@ unset cmap[dnet-2-multi]
|
||||||
stop_dnet 3 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
stop_dnet 3 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
unset cmap[dnet-3-multi]
|
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
|
## Setup
|
||||||
start_dnet 1 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
start_dnet 1 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[dnet-1-overlay]=dnet-1-overlay
|
cmap[dnet-1-overlay]=dnet-1-overlay
|
||||||
|
|
|
@ -7,6 +7,8 @@ load helpers
|
||||||
run dnet_cmd $(inst_id2port 1) network create -d test mh1
|
run dnet_cmd $(inst_id2port 1) network create -d test mh1
|
||||||
echo ${output}
|
echo ${output}
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run dnet_cmd $(inst_id2port 1) network ls
|
||||||
|
echo ${output}
|
||||||
line=$(dnet_cmd $(inst_id2port 1) network ls | grep mh1)
|
line=$(dnet_cmd $(inst_id2port 1) network ls | grep mh1)
|
||||||
echo ${line}
|
echo ${line}
|
||||||
name=$(echo ${line} | cut -d" " -f2)
|
name=$(echo ${line} | cut -d" " -f2)
|
||||||
|
@ -32,9 +34,9 @@ load helpers
|
||||||
echo ${output}
|
echo ${output}
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
run dnet_cmd $(inst_id2port 1) service ls
|
run dnet_cmd $(inst_id2port 1) service ls
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
echo ${output}
|
echo ${output}
|
||||||
echo ${lines[1]}
|
echo ${lines[1]}
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
svc=$(echo ${lines[1]} | cut -d" " -f2)
|
svc=$(echo ${lines[1]} | cut -d" " -f2)
|
||||||
network=$(echo ${lines[1]} | cut -d" " -f3)
|
network=$(echo ${lines[1]} | cut -d" " -f3)
|
||||||
echo ${svc} ${network}
|
echo ${svc} ${network}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue