From ce44f2478d4237912548031d5e6e907493834951 Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Wed, 23 Sep 2015 19:31:50 -0700 Subject: [PATCH] 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 --- libnetwork/Makefile | 2 +- libnetwork/cmd/dnet/dnet.go | 17 +++++ libnetwork/test/integration/dnet/helpers.bash | 63 +++++++++++++++---- libnetwork/test/integration/dnet/overlay.bats | 49 +++++++++++++++ .../integration/dnet/run-integration-tests.sh | 56 +++++++++++++---- 5 files changed, 160 insertions(+), 27 deletions(-) create mode 100644 libnetwork/test/integration/dnet/overlay.bats diff --git a/libnetwork/Makefile b/libnetwork/Makefile index 05b1249361..40079bd28f 100644 --- a/libnetwork/Makefile +++ b/libnetwork/Makefile @@ -13,7 +13,7 @@ integration-tests: ./cmd/dnet/dnet @./test/integration/dnet/run-integration-tests.sh ./cmd/dnet/dnet: - make build-local + make build clean: @if [ -e ./cmd/dnet/dnet ]; then \ diff --git a/libnetwork/cmd/dnet/dnet.go b/libnetwork/cmd/dnet/dnet.go index ee114d80f6..989d3b12ca 100644 --- a/libnetwork/cmd/dnet/dnet.go +++ b/libnetwork/cmd/dnet/dnet.go @@ -9,7 +9,9 @@ import ( "net/http" "net/http/httptest" "os" + "os/signal" "strings" + "syscall" "github.com/codegangsta/cli" "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 = r.PathPrefix("/sandboxes").Subrouter() post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler) + + handleSignals(controller) + 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 { mux := http.NewServeMux() server := httptest.NewServer(mux) diff --git a/libnetwork/test/integration/dnet/helpers.bash b/libnetwork/test/integration/dnet/helpers.bash index 7b89ddc78a..f0adf6eb40 100644 --- a/libnetwork/test/integration/dnet/helpers.bash +++ b/libnetwork/test/integration/dnet/helpers.bash @@ -28,20 +28,40 @@ function stop_consul() { } function start_dnet() { - stop_dnet $1 $2 - name=$(dnet_container_name $1 $2) - if [ -z "$3" ] - then - hport=$((41000+${1}-1)) - cport=2385 - hopt="" - else - hport=$3 - cport=$3 - hopt="-H tcp://0.0.0.0:${cport}" - fi + inst=$1 + shift + suffix=$1 + shift + + stop_dnet ${inst} ${suffix} + name=$(dnet_container_name ${inst} ${suffix}) + + hport=$((41000+${inst}-1)) + cport=2385 + hopt="" + isnum='^[0-9]+$' + + while [ -n "$1" ] + do + if [[ "$1" =~ ^[0-9]+$ ]] + then + hport=$1 + cport=$1 + hopt="-H tcp://0.0.0.0:${cport}" + else + neighip=$1 + fi + shift + done 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} tomlfile="/tmp/dnet/${name}/libnetwork.toml" cat > ${tomlfile} < ${TMPC_ROOT}/busybox.tar + mkdir -p ${TMPC_ROOT}/rootfs + tar -C ${TMPC_ROOT}/rootfs -xf ${TMPC_ROOT}/busybox.tar +fi + declare -A cmap trap "cleanup_containers" EXIT SIGINT @@ -27,7 +38,7 @@ function cleanup_containers() { source ./test/integration/dnet/helpers.bash # Suite setup -start_consul 1>/dev/null 2>&1 +start_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1 cmap[pr_consul]=pr_consul # Test dnet configuration options @@ -36,37 +47,56 @@ cmap[pr_consul]=pr_consul # Test a single node configuration with a global scope test driver ## 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 ## Run the test cases ./integration-tmp/bin/bats ./test/integration/dnet/simple.bats ## 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] # Test multi node configuration with a global scope test driver ## 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 -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 -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 ## Run the test cases ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats ## 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] -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] -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] +## 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 -stop_consul 1>/dev/null 2>&1 +stop_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1 unset cmap[pr_consul]