mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add overlay network integration test
This commit adds a basic overlay network connectivity integration test. By doing this it adds the basic functions to form a crude container to run the networking tests. The container uses a busybox rootfs with network namespace and /etc/hosts and /etc/resolv.conf generated by libnetwork. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
50ec2d3a50
commit
ce44f2478d
5 changed files with 160 additions and 27 deletions
|
@ -13,7 +13,7 @@ integration-tests: ./cmd/dnet/dnet
|
||||||
@./test/integration/dnet/run-integration-tests.sh
|
@./test/integration/dnet/run-integration-tests.sh
|
||||||
|
|
||||||
./cmd/dnet/dnet:
|
./cmd/dnet/dnet:
|
||||||
make build-local
|
make build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@if [ -e ./cmd/dnet/dnet ]; then \
|
@if [ -e ./cmd/dnet/dnet ]; then \
|
||||||
|
|
|
@ -9,7 +9,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
|
@ -165,9 +167,24 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
|
||||||
post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
|
post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
|
||||||
post = r.PathPrefix("/sandboxes").Subrouter()
|
post = r.PathPrefix("/sandboxes").Subrouter()
|
||||||
post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
|
post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
|
||||||
|
|
||||||
|
handleSignals(controller)
|
||||||
|
|
||||||
return http.ListenAndServe(d.addr, r)
|
return http.ListenAndServe(d.addr, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleSignals(controller libnetwork.NetworkController) {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}
|
||||||
|
signal.Notify(c, signals...)
|
||||||
|
go func() {
|
||||||
|
for _ = range c {
|
||||||
|
controller.Stop()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func startTestDriver() error {
|
func startTestDriver() error {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
server := httptest.NewServer(mux)
|
server := httptest.NewServer(mux)
|
||||||
|
|
|
@ -28,20 +28,40 @@ function stop_consul() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_dnet() {
|
function start_dnet() {
|
||||||
stop_dnet $1 $2
|
inst=$1
|
||||||
name=$(dnet_container_name $1 $2)
|
shift
|
||||||
if [ -z "$3" ]
|
suffix=$1
|
||||||
then
|
shift
|
||||||
hport=$((41000+${1}-1))
|
|
||||||
|
stop_dnet ${inst} ${suffix}
|
||||||
|
name=$(dnet_container_name ${inst} ${suffix})
|
||||||
|
|
||||||
|
hport=$((41000+${inst}-1))
|
||||||
cport=2385
|
cport=2385
|
||||||
hopt=""
|
hopt=""
|
||||||
else
|
isnum='^[0-9]+$'
|
||||||
hport=$3
|
|
||||||
cport=$3
|
while [ -n "$1" ]
|
||||||
|
do
|
||||||
|
if [[ "$1" =~ ^[0-9]+$ ]]
|
||||||
|
then
|
||||||
|
hport=$1
|
||||||
|
cport=$1
|
||||||
hopt="-H tcp://0.0.0.0:${cport}"
|
hopt="-H tcp://0.0.0.0:${cport}"
|
||||||
|
else
|
||||||
|
neighip=$1
|
||||||
fi
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
bridge_ip=$(docker inspect --format '{{.NetworkSettings.Gateway}}' pr_consul)
|
bridge_ip=$(docker inspect --format '{{.NetworkSettings.Gateway}}' pr_consul)
|
||||||
|
|
||||||
|
if [ -z "$neighip" ]; then
|
||||||
|
labels="\"com.docker.network.driver.overlay.bind_interface=eth0\""
|
||||||
|
else
|
||||||
|
labels="\"com.docker.network.driver.overlay.bind_interface=eth0\", \"com.docker.network.driver.overlay.neighbor_ip=${neighip}\""
|
||||||
|
fi
|
||||||
|
|
||||||
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
|
||||||
|
@ -49,13 +69,14 @@ title = "LibNetwork Configuration file"
|
||||||
|
|
||||||
[daemon]
|
[daemon]
|
||||||
debug = false
|
debug = false
|
||||||
labels = ["com.docker.network.driver.overlay.bind_interface=eth0"]
|
labels = [${labels}]
|
||||||
[globalstore]
|
[globalstore]
|
||||||
embedded = false
|
embedded = false
|
||||||
[globalstore.client]
|
[globalstore.client]
|
||||||
provider = "consul"
|
provider = "consul"
|
||||||
Address = "${bridge_ip}:8500"
|
Address = "${bridge_ip}:8500"
|
||||||
EOF
|
EOF
|
||||||
|
echo "parsed values: " ${name} ${hport} ${cport} ${hopt}
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--name=${name} \
|
--name=${name} \
|
||||||
|
@ -63,6 +84,8 @@ EOF
|
||||||
-p ${hport}:${cport} \
|
-p ${hport}:${cport} \
|
||||||
-v $(pwd)/:/go/src/github.com/docker/libnetwork \
|
-v $(pwd)/:/go/src/github.com/docker/libnetwork \
|
||||||
-v /tmp:/tmp \
|
-v /tmp:/tmp \
|
||||||
|
-v $(pwd)/${TMPC_ROOT}:/scratch \
|
||||||
|
-v /usr/local/bin/runc:/usr/local/bin/runc \
|
||||||
-w /go/src/github.com/docker/libnetwork \
|
-w /go/src/github.com/docker/libnetwork \
|
||||||
golang:1.4 ./cmd/dnet/dnet -d -D ${hopt} -c ${tomlfile}
|
golang:1.4 ./cmd/dnet/dnet -d -D ${hopt} -c ${tomlfile}
|
||||||
sleep 2
|
sleep 2
|
||||||
|
@ -89,3 +112,17 @@ function dnet_cmd() {
|
||||||
shift
|
shift
|
||||||
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
|
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dnet_exec() {
|
||||||
|
docker exec -it ${1} bash -c "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
function runc() {
|
||||||
|
dnet=${1}
|
||||||
|
shift
|
||||||
|
dnet_exec ${dnet} "cp /var/lib/docker/network/files/${1}*/* /scratch/rootfs/etc"
|
||||||
|
dnet_exec ${dnet} "mkdir -p /var/run/netns"
|
||||||
|
dnet_exec ${dnet} "touch /var/run/netns/c && mount -o bind /var/run/docker/netns/${1} /var/run/netns/c"
|
||||||
|
dnet_exec ${dnet} "ip netns exec c unshare -fmuip --mount-proc chroot \"/scratch/rootfs\" /bin/sh -c \"/bin/mount -t proc proc /proc && ${2}\""
|
||||||
|
dnet_exec ${dnet} "umount /var/run/netns/c && rm /var/run/netns/c"
|
||||||
|
}
|
||||||
|
|
49
libnetwork/test/integration/dnet/overlay.bats
Normal file
49
libnetwork/test/integration/dnet/overlay.bats
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# -*- mode: sh -*-
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
@test "Test overlay network" {
|
||||||
|
skip_for_circleci
|
||||||
|
|
||||||
|
echo $(docker ps)
|
||||||
|
|
||||||
|
start=1
|
||||||
|
end=3
|
||||||
|
# Setup overlay network and connect containers ot it
|
||||||
|
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
|
||||||
|
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"
|
||||||
|
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
|
||||||
|
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
|
||||||
|
}
|
|
@ -2,12 +2,23 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ ! -d ./integration-tmp ]; then
|
export INTEGRATION_ROOT=./integration-tmp
|
||||||
mkdir -p ./integration-tmp
|
export TMPC_ROOT=./integration-tmp/tmpc
|
||||||
git clone https://github.com/sstephenson/bats.git ./integration-tmp/bats
|
|
||||||
|
if [ ! -d ${INTEGRATION_ROOT} ]; then
|
||||||
|
mkdir -p ${INTEGRATION_ROOT}
|
||||||
|
git clone https://github.com/sstephenson/bats.git ${INTEGRATION_ROOT}/bats
|
||||||
./integration-tmp/bats/install.sh ./integration-tmp
|
./integration-tmp/bats/install.sh ./integration-tmp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -d ${TMPC_ROOT} ]; then
|
||||||
|
mkdir -p ${TMPC_ROOT}
|
||||||
|
docker pull busybox:ubuntu
|
||||||
|
docker export $(docker create busybox:ubuntu) > ${TMPC_ROOT}/busybox.tar
|
||||||
|
mkdir -p ${TMPC_ROOT}/rootfs
|
||||||
|
tar -C ${TMPC_ROOT}/rootfs -xf ${TMPC_ROOT}/busybox.tar
|
||||||
|
fi
|
||||||
|
|
||||||
declare -A cmap
|
declare -A cmap
|
||||||
|
|
||||||
trap "cleanup_containers" EXIT SIGINT
|
trap "cleanup_containers" EXIT SIGINT
|
||||||
|
@ -27,7 +38,7 @@ function cleanup_containers() {
|
||||||
source ./test/integration/dnet/helpers.bash
|
source ./test/integration/dnet/helpers.bash
|
||||||
|
|
||||||
# Suite setup
|
# Suite setup
|
||||||
start_consul 1>/dev/null 2>&1
|
start_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[pr_consul]=pr_consul
|
cmap[pr_consul]=pr_consul
|
||||||
|
|
||||||
# Test dnet configuration options
|
# Test dnet configuration options
|
||||||
|
@ -36,37 +47,56 @@ cmap[pr_consul]=pr_consul
|
||||||
# Test a single node configuration with a global scope test driver
|
# Test a single node configuration with a global scope test driver
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
start_dnet 1 simple 1>/dev/null 2>&1
|
start_dnet 1 simple 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[dnet-1-simple]=dnet-1-simple
|
cmap[dnet-1-simple]=dnet-1-simple
|
||||||
|
|
||||||
## Run the test cases
|
## Run the test cases
|
||||||
./integration-tmp/bin/bats ./test/integration/dnet/simple.bats
|
./integration-tmp/bin/bats ./test/integration/dnet/simple.bats
|
||||||
|
|
||||||
## Teardown
|
## Teardown
|
||||||
stop_dnet 1 simple 1>/dev/null 2>&1
|
stop_dnet 1 simple 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
unset cmap[dnet-1-simple]
|
unset cmap[dnet-1-simple]
|
||||||
|
|
||||||
# Test multi node configuration with a global scope test driver
|
# Test multi node configuration with a global scope test driver
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
start_dnet 1 multi 1>/dev/null 2>&1
|
start_dnet 1 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[dnet-1-multi]=dnet-1-multi
|
cmap[dnet-1-multi]=dnet-1-multi
|
||||||
start_dnet 2 multi 1>/dev/null 2>&1
|
start_dnet 2 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[dnet-2-multi]=dnet-2-multi
|
cmap[dnet-2-multi]=dnet-2-multi
|
||||||
start_dnet 3 multi 1>/dev/null 2>&1
|
start_dnet 3 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
cmap[dnet-3-multi]=dnet-3-multi
|
cmap[dnet-3-multi]=dnet-3-multi
|
||||||
|
|
||||||
## Run the test cases
|
## Run the test cases
|
||||||
./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
|
./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
|
||||||
|
|
||||||
## Teardown
|
## Teardown
|
||||||
stop_dnet 1 multi 1>/dev/null 2>&1
|
stop_dnet 1 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
unset cmap[dnet-1-multi]
|
unset cmap[dnet-1-multi]
|
||||||
stop_dnet 2 multi 1>/dev/null 2>&1
|
stop_dnet 2 multi 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
unset cmap[dnet-2-multi]
|
unset cmap[dnet-2-multi]
|
||||||
stop_dnet 3 multi 1>/dev/null 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 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-1-overlay]=dnet-1-overlay
|
||||||
|
start_dnet 2 overlay $(docker inspect --format '{{.NetworkSettings.IPAddress}}' dnet-1-overlay) 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-2-overlay]=dnet-2-overlay
|
||||||
|
start_dnet 3 overlay $(docker inspect --format '{{.NetworkSettings.IPAddress}}' dnet-2-overlay) 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-3-overlay]=dnet-3-overlay
|
||||||
|
|
||||||
|
## Run the test cases
|
||||||
|
./integration-tmp/bin/bats ./test/integration/dnet/overlay.bats
|
||||||
|
|
||||||
|
## Teardown
|
||||||
|
stop_dnet 1 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-1-overlay]
|
||||||
|
stop_dnet 2 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-2-overlay]
|
||||||
|
stop_dnet 3 overlay 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-3-overlay]
|
||||||
|
|
||||||
# Suite teardowm
|
# Suite teardowm
|
||||||
stop_consul 1>/dev/null 2>&1
|
stop_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
unset cmap[pr_consul]
|
unset cmap[pr_consul]
|
||||||
|
|
Loading…
Add table
Reference in a new issue