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:
Jana Radhakrishnan 2015-10-05 04:32:40 -07:00
parent a13f78369f
commit a22ce0938c
6 changed files with 231 additions and 31 deletions

View 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
}

View File

@ -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} <<EOF
title = "LibNetwork Configuration file"
title = "LibNetwork Configuration file for ${name}"
[daemon]
debug = false
@ -73,13 +92,13 @@ title = "LibNetwork Configuration file"
[cluster]
discovery = "consul://${bridge_ip}:8500"
Heartbeat = 10
[globalstore]
embedded = false
[globalstore.client]
provider = "consul"
Address = "${bridge_ip}:8500"
[scopes]
[scopes.global]
embedded = false
[scopes.global.client]
provider = "consul"
address = "${bridge_ip}:8500"
EOF
echo "parsed values: " ${name} ${hport} ${cport} ${hopt}
docker run \
-d \
--name=${name} \
@ -101,6 +120,8 @@ function skip_for_circleci() {
}
function stop_dnet() {
local name
name=$(dnet_container_name $1 $2)
rm -rf /tmp/dnet/${name} || true
docker stop ${name} || true
@ -111,6 +132,8 @@ function stop_dnet() {
}
function dnet_cmd() {
local hport
hport=$1
shift
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
@ -121,6 +144,8 @@ function dnet_exec() {
}
function runc() {
local dnet
dnet=${1}
shift
dnet_exec ${dnet} "cp /var/lib/docker/network/files/${1}*/* /scratch/rootfs/etc"

View File

@ -1,7 +1,19 @@
# -*- mode: sh -*-
#!/usr/bin/env bats
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" {
echo $(docker ps)
for i in `seq 1 3`;
@ -13,19 +25,17 @@ load helpers
for j in `seq 1 3`;
do
line=$(dnet_cmd $(inst_id2port $j) network ls | grep ${oname})
echo ${output}
[ "$status" -eq 0 ]
echo ${line}
name=$(echo ${line} | cut -d" " -f2)
driver=$(echo ${line} | cut -d" " -f3)
echo ${name} ${driver}
[ "$name" = "$oname" ]
[ "$driver" = "test" ]
result=$(is_network_exist $j ${oname} test)
[ "$result" = "true" ]
done
# Always try to remove the network from the first node
dnet_cmd $(inst_id2port 1) network rm ${oname}
# Always try to remove the network from the second node
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
}
@ -97,6 +107,7 @@ load helpers
dnet_cmd $(inst_id2port $i) network create -d test ${oname}
dnet_cmd $(inst_id2port $i) service publish ${osvc}.${oname}
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}
for j in `seq 1 3`;

View File

@ -14,35 +14,28 @@ load helpers
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
for i in `seq ${start} ${end}`;
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) service attach container_${i} ${osvc}.multihost
net_connect ${i} container_${i} multihost
done
# Now test connectivity between all the containers using service names
for i in `seq ${start} ${end}`;
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}`;
do
if [ "$i" -eq "$j" ]; then
continue
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
# Teardown the container connections and the network
for i in `seq ${start} ${end}`;
do
osvc="svc$i"
dnet_cmd $(inst_id2port $i) service detach container_${i} ${osvc}.multihost
net_disconnect ${i} container_${i} multihost
dnet_cmd $(inst_id2port $i) container rm container_${i}
dnet_cmd $(inst_id2port $i) service unpublish ${osvc}.multihost
done
run dnet_cmd $(inst_id2port 2) network rm multihost

View File

@ -78,6 +78,18 @@ unset cmap[dnet-2-multi]
stop_dnet 3 multi 1>>${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

View File

@ -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}