1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

libnetwork: remove old integration tests

This was used for testing purposes when libnetwork was in a separate repo, using
the dnet utility, which was removed in 7266a956a8.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-23 19:30:02 +02:00
parent 46f4a45769
commit 571baffd59
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
11 changed files with 0 additions and 1345 deletions

View file

@ -1,34 +0,0 @@
# LibNetwork Integration Tests
Integration tests provide end-to-end testing of LibNetwork and Drivers.
While unit tests verify the code is working as expected by relying on mocks and
artificially created fixtures, integration tests actually use real docker
engines and communicate to it through the CLI.
Note that integration tests do **not** replace unit tests and Docker is used as a good use-case.
As a rule of thumb, code should be tested thoroughly with unit tests.
Integration tests on the other hand are meant to test a specific feature end to end.
Integration tests are written in *bash* using the
[bats](https://github.com/sstephenson/bats) framework.
## Pre-Requisites
1. Bats (https://github.com/sstephenson/bats#installing-bats-from-source)
2. Docker Machine (https://github.com/docker/machine)
3. Virtualbox (as a Docker machine driver)
## Running integration tests
* Start by [installing] (https://github.com/sstephenson/bats#installing-bats-from-source) *bats* on your system.
* If not done already, [install](https://docs.docker.com/machine/) *docker-machine* into /usr/bin
* Make sure Virtualbox is installed as well, which will be used by docker-machine as a driver to launch VMs
In order to run all integration tests, pass *bats* the test path:
```
$ bats test/integration/daemon-configs.bats
```

View file

@ -1,104 +0,0 @@
#!/usr/bin/env bats
load helpers
export DRIVER=virtualbox
export NAME="bats-$DRIVER-daemon-configs"
export MACHINE_STORAGE_PATH=/tmp/machine-bats-daemon-test-$DRIVER
# Default memsize is 1024MB and disksize is 20000MB
# These values are defined in drivers/virtualbox/virtualbox.go
export DEFAULT_MEMSIZE=1024
export DEFAULT_DISKSIZE=20000
export CUSTOM_MEMSIZE=1536
export CUSTOM_DISKSIZE=10000
export CUSTOM_CPUCOUNT=1
export BAD_URL="http://dev.null:9111/bad.iso"
function setup() {
# add sleep because vbox; ugh
sleep 1
}
findDiskSize() {
# SATA-0-0 is usually the boot2disk.iso image
# We assume that SATA 1-0 is root disk VMDK and grab this UUID
# e.g. "SATA-ImageUUID-1-0"="fb5f33a7-e4e3-4cb9-877c-f9415ae2adea"
# TODO(slashk): does this work on Windows ?
run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep SATA-ImageUUID-1-0 | cut -d'=' -f2"
run bash -c "VBoxManage showhdinfo $output | grep "Capacity:" | awk -F' ' '{ print $2 }'"
}
findMemorySize() {
run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep memory= | cut -d'=' -f2"
}
findCPUCount() {
run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep cpus= | cut -d'=' -f2"
}
buildMachineWithOldIsoCheckUpgrade() {
run wget https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso -O $MACHINE_STORAGE_PATH/cache/boot2docker.iso
run machine create -d virtualbox $NAME
run machine upgrade $NAME
}
@test "$DRIVER: machine should not exist" {
run machine active $NAME
[ "$status" -eq 1 ]
}
@test "$DRIVER: VM should not exist" {
run VBoxManage showvminfo $NAME
[ "$status" -eq 1 ]
}
@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
[ "$status" -eq 0 ]
}
@test "$DRIVER: active" {
run machine active $NAME
[ "$status" -eq 0 ]
}
@test "$DRIVER: check default machine memory size" {
findMemorySize
[[ ${output} == "${DEFAULT_MEMSIZE}" ]]
}
@test "$DRIVER: check default machine disksize" {
findDiskSize
[[ ${output} == *"$DEFAULT_DISKSIZE"* ]]
}
@test "$DRIVER: test bridge-ip" {
run machine ssh $NAME sudo /etc/init.d/docker stop
run machine ssh $NAME sudo ifconfig docker0 down
run machine ssh $NAME sudo ip link delete docker0
BIP='--bip=172.168.45.1/24'
set_extra_config $BIP
cat ${TMP_EXTRA_ARGS_FILE} | machine ssh $NAME sudo tee /var/lib/boot2docker/profile
cat ${DAEMON_CFG_FILE} | machine ssh $NAME "sudo tee -a /var/lib/boot2docker/profile"
run machine ssh $NAME sudo /etc/init.d/docker start
run machine ssh $NAME ifconfig docker0
[ "$status" -eq 0 ]
[[ ${lines[1]} =~ "172.168.45.1" ]]
}
@test "$DRIVER: run busybox container" {
run machine ssh $NAME sudo cat /var/lib/boot2docker/profile
run docker $(machine config $NAME) run busybox echo hello world
[ "$status" -eq 0 ]
}
@test "$DRIVER: remove machine" {
run machine rm -f $NAME
}
# Cleanup of machine store should always be the last 'test'
@test "$DRIVER: cleanup" {
run rm -rf $MACHINE_STORAGE_PATH
[ "$status" -eq 0 ]
}

View file

@ -1,4 +0,0 @@
CACERT=/var/lib/boot2docker/ca.pem
SERVERCERT=/var/lib/boot2docker/server-key.pem
SERVERKEY=/var/lib/boot2docker/server.pem
DOCKER_TLS=no

View file

@ -1,287 +0,0 @@
# -*- 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
if [ "${nw_name}" != "internal" ]; then
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_${i}) \
"ping -c 1 www.google.com"
fi
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
if [ -n "$3" ]; then
return
fi
# 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" {
echo $(docker ps)
test_single_network_connectivity bridge 3
}
@test "Test default network dnet restart" {
echo $(docker ps)
for iter in `seq 1 2`;
do
test_single_network_connectivity bridge 3
if [ "$iter" -eq 1 ]; then
docker restart dnet-1-bridge
wait_for_dnet $(inst_id2port 1) dnet-1-bridge
fi
done
}
@test "Test default network dnet ungraceful restart" {
echo $(docker ps)
for iter in `seq 1 2`;
do
if [ "$iter" -eq 1 ]; then
test_single_network_connectivity bridge 3 skip
docker restart dnet-1-bridge
wait_for_dnet $(inst_id2port 1) dnet-1-bridge
else
test_single_network_connectivity bridge 3
fi
done
}
@test "Test bridge network" {
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" {
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
if [ "$iter" -eq 1 ]; then
docker restart dnet-1-bridge
wait_for_dnet $(inst_id2port 1) dnet-1-bridge
fi
done
dnet_cmd $(inst_id2port 1) network rm singlehost
}
@test "Test bridge network dnet ungraceful restart" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d bridge singlehost
for iter in `seq 1 2`;
do
if [ "$iter" -eq 1 ]; then
test_single_network_connectivity singlehost 3 skip
docker restart dnet-1-bridge
wait_for_dnet $(inst_id2port 1) dnet-1-bridge
else
test_single_network_connectivity singlehost 3
fi
done
dnet_cmd $(inst_id2port 1) network rm singlehost
}
@test "Test multiple bridge networks" {
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
svcs=(
0,0
2,3
1,3
1,2
)
echo "Test connectivity failure"
for i in `seq ${start} ${end}`;
do
IFS=, read a b <<<"${svcs[$i]}"
osvc="svc${a}${b}"
echo "pinging ${osvc}"
runc_nofail $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_${i}) "ping -c 1 ${osvc}"
[ "${status}" -ne 0 ]
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
}
@test "Test bridge network alias support" {
dnet_cmd $(inst_id2port 1) network create -d bridge br1
dnet_cmd $(inst_id2port 1) container create container_1
net_connect 1 container_1 br1 container_2:c2
dnet_cmd $(inst_id2port 1) container create container_2
net_connect 1 container_2 br1
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 container_2"
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 c2"
net_disconnect 1 container_1 br1
net_disconnect 1 container_2 br1
dnet_cmd $(inst_id2port 1) container rm container_1
dnet_cmd $(inst_id2port 1) container rm container_2
dnet_cmd $(inst_id2port 1) network rm br1
}
@test "Test bridge network global alias support" {
dnet_cmd $(inst_id2port 1) network create -d bridge br1
dnet_cmd $(inst_id2port 1) network create -d bridge br2
dnet_cmd $(inst_id2port 1) container create container_1
net_connect 1 container_1 br1 : c1
dnet_cmd $(inst_id2port 1) container create container_2
net_connect 1 container_2 br1 : shared
dnet_cmd $(inst_id2port 1) container create container_3
net_connect 1 container_3 br1 : shared
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_2) "ping -c 1 container_1"
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_2) "ping -c 1 c1"
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 container_2"
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 shared"
net_disconnect 1 container_2 br1
dnet_cmd $(inst_id2port 1) container rm container_2
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 container_3"
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 shared"
net_disconnect 1 container_1 br1
dnet_cmd $(inst_id2port 1) container rm container_1
net_disconnect 1 container_3 br1
dnet_cmd $(inst_id2port 1) container rm container_3
dnet_cmd $(inst_id2port 1) network rm br1
}
@test "Test bridge network internal network" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d bridge --internal internal
dnet_cmd $(inst_id2port 1) container create container_1
# connects to internal network, confirm it can't communicate with outside world
net_connect 1 container_1 internal
run runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 8.8.8.8"
[[ "$output" == *"1 packets transmitted, 0 packets received, 100% packet loss"* ]]
net_disconnect 1 container_1 internal
# connects to bridge network, confirm it can communicate with outside world
net_connect 1 container_1 bridge
runc $(dnet_container_name 1 bridge) $(get_sbox_id 1 container_1) "ping -c 1 8.8.8.8"
net_disconnect 1 container_1 bridge
dnet_cmd $(inst_id2port 1) container rm container_1
# test communications within internal network
test_single_network_connectivity internal 3
dnet_cmd $(inst_id2port 1) network rm internal
}

View file

@ -1,31 +0,0 @@
#!/usr/bin/env bats
load helpers
@test "Test dnet custom port" {
start_dnet 1 a 4567
dnet_cmd 4567 network ls
stop_dnet 1 a
}
@test "Test dnet invalid custom port" {
start_dnet 1 b 4567
run dnet_cmd 4568 network ls
echo ${output}
[ "$status" -ne 0 ]
stop_dnet 1 b
}
@test "Test dnet invalid params" {
start_dnet 1 c
run dnet_cmd 8080 network ls
echo ${output}
[ "$status" -ne 0 ]
run ./bin/dnet -H=unix://var/run/dnet.sock network ls
echo ${output}
[ "$status" -ne 0 ]
run ./bin/dnet -H= -l=invalid network ls
echo ${output}
[ "$status" -ne 0 ]
stop_dnet 1 c
}

View file

@ -1,478 +0,0 @@
function get_docker_bridge_ip() {
echo $(docker run --rm -it busybox ip route show | grep default | cut -d" " -f3)
}
function inst_id2port() {
echo $((41000+${1}-1))
}
function dnet_container_name() {
echo dnet-$1-$2
}
function dnet_container_ip() {
docker inspect --format '{{.NetworkSettings.IPAddress}}' 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() {
local al gl
if [ -n "$4" ]; then
if [ "${4}" != ":" ]; then
al="--alias=${4}"
fi
fi
if [ -n "$5" ]; then
gl="--alias=${5}"
fi
dnet_cmd $(inst_id2port ${1}) service publish $gl ${2}.${3}
dnet_cmd $(inst_id2port ${1}) service attach $al ${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}
}
hrun() {
local e E T oldIFS
[[ ! "$-" =~ e ]] || e=1
[[ ! "$-" =~ E ]] || E=1
[[ ! "$-" =~ T ]] || T=1
set +e
set +E
set +T
output="$("$@" 2>&1)"
status="$?"
oldIFS=$IFS
IFS=$'\n' lines=($output)
[ -z "$e" ] || set -e
[ -z "$E" ] || set -E
[ -z "$T" ] || set -T
IFS=$oldIFS
}
function wait_for_dnet() {
local hport
hport=$1
echo "waiting on dnet to come up ..."
for i in `seq 1 10`;
do
hrun ./bin/dnet -H tcp://127.0.0.1:${hport} network ls
echo ${output}
if [ "$status" -eq 0 ]; then
return
fi
if [[ "${lines[1]}" =~ .*EOF.* ]]
then
docker logs ${2}
fi
echo "still waiting after ${i} seconds"
sleep 1
done
}
function parse_discovery_str() {
local d provider address
discovery=$1
provider=$(echo ${discovery} | cut -d":" -f1)
address=$(echo ${discovery} | cut -d":" -f2):$(echo ${discovery} | cut -d":" -f3)
address=${address:2}
echo "${discovery} ${provider} ${address}"
}
function start_dnet() {
local inst suffix name hport cport hopt store bridge_ip labels tomlfile nip
local discovery provider address
inst=$1
shift
suffix=$1
shift
store=$(echo $suffix | cut -d":" -f1)
nip=$(echo $suffix | cut -s -d":" -f2)
stop_dnet ${inst} ${store}
name=$(dnet_container_name ${inst} ${store})
hport=$((41000+${inst}-1))
cport=2385
hopt=""
while [ -n "$1" ]
do
if [[ "$1" =~ ^[0-9]+$ ]]
then
hport=$1
cport=$1
hopt="-H tcp://0.0.0.0:${cport}"
else
store=$1
fi
shift
done
bridge_ip=$(get_docker_bridge_ip)
echo "start_dnet parsed values: " ${inst} ${suffix} ${name} ${hport} ${cport} ${hopt} ${store}
mkdir -p /tmp/dnet/${name}
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
# Try discovery URLs with or without path
neigh_ip=""
neighbors=""
if [ "$nip" != "" ]; then
neighbors=${nip}
fi
discovery=""
provider=""
address=""
if [ "$discovery" != "" ]; then
cat > ${tomlfile} <<EOF
title = "LibNetwork Configuration file for ${name}"
[daemon]
debug = false
[cluster]
discovery = "${discovery}"
Heartbeat = 10
[scopes]
[scopes.global]
[scopes.global.client]
provider = "${provider}"
address = "${address}"
EOF
else
cat > ${tomlfile} <<EOF
title = "LibNetwork Configuration file for ${name}"
[daemon]
debug = false
[orchestration]
agent = true
bind = "eth0"
peer = "${neighbors}"
EOF
fi
cat ${tomlfile}
docker run \
-d \
--hostname=$(echo ${name} | sed s/_/-/g) \
--name=${name} \
--privileged \
-p ${hport}:${cport} \
-e _OVERLAY_HOST_MODE \
-v $(pwd)/:/go/src/github.com/docker/libnetwork \
-v /tmp:/tmp \
-v $(pwd)/${TMPC_ROOT}:/scratch \
-v /usr/local/bin/runc:/usr/local/bin/runc \
-w /go/src/github.com/docker/libnetwork \
mrjana/golang ./bin/dnet -d -D ${hopt} -c ${tomlfile}
wait_for_dnet $(inst_id2port ${inst}) ${name}
}
function start_ovrouter() {
local name=${1}
local parent=${2}
docker run \
-d \
--name=${name} \
--net=container:${parent} \
--volumes-from ${parent} \
-w /go/src/github.com/docker/libnetwork \
mrjana/golang ./cmd/ovrouter/ovrouter eth0
}
function stop_dnet() {
local name
name=$(dnet_container_name $1 $2)
rm -rf /tmp/dnet/${name} || true
docker rm -f ${name} || true
}
function dnet_cmd() {
local hport
hport=$1
shift
./bin/dnet -H tcp://127.0.0.1:${hport} $*
}
function dnet_exec() {
docker exec -it ${1} bash -c "trap \"echo SIGHUP\" SIGHUP; $2"
}
function runc() {
local dnet
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"
}
function runc_nofail() {
local dnet
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"
set +e
dnet_exec ${dnet} "ip netns exec c unshare -fmuip --mount-proc chroot \"/scratch/rootfs\" /bin/sh -c \"/bin/mount -t proc proc /proc && ${2}\""
status="$?"
set -e
dnet_exec ${dnet} "umount /var/run/netns/c && rm /var/run/netns/c"
}
function test_overlay() {
dnet_suffix=$1
echo $(docker ps)
start=1
end=3
# Setup overlay network and connect containers to it
if [ -z "${2}" -o "${2}" != "skip_add" ]; then
if [ -z "${2}" -o "${2}" != "internal" ]; then
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
else
dnet_cmd $(inst_id2port 1) network create -d overlay --internal multihost
fi
fi
for i in `seq ${start} ${end}`;
do
dnet_cmd $(inst_id2port $i) container create container_${i}
net_connect ${i} container_${i} multihost
done
# Now test connectivity between all the containers using service names
for i in `seq ${start} ${end}`;
do
if [ -z "${2}" -o "${2}" != "internal" ]; then
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) \
"ping -c 1 www.google.com"
else
default_route=`runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ip route | grep default"`
[ "$default_route" = "" ]
fi
for j in `seq ${start} ${end}`;
do
if [ "$i" -eq "$j" ]; then
continue
fi
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) \
"ping -c 1 container_$j"
done
done
# Setup bridge network and connect containers to it
if [ -z "${2}" -o "${2}" != "skip_add" ]; then
if [ -z "${2}" -o "${2}" != "internal" ]; then
dnet_cmd $(inst_id2port 1) network create -d bridge br1
dnet_cmd $(inst_id2port 1) network create -d bridge br2
net_connect ${start} container_${start} br1
net_connect ${start} container_${start} br2
# Make sure external connectivity works
runc $(dnet_container_name ${start} $dnet_suffix) $(get_sbox_id ${start} container_${start}) \
"ping -c 1 www.google.com"
net_disconnect ${start} container_${start} br1
net_disconnect ${start} container_${start} br2
# Make sure external connectivity works
runc $(dnet_container_name ${start} $dnet_suffix) $(get_sbox_id ${start} container_${start}) \
"ping -c 1 www.google.com"
dnet_cmd $(inst_id2port 1) network rm br1
dnet_cmd $(inst_id2port 1) network rm br2
# Disconnect from overlay network
net_disconnect ${start} container_${start} multihost
# Connect to overlay network again
net_connect ${start} container_${start} multihost
# Make sure external connectivity still works
runc $(dnet_container_name ${start} $dnet_suffix) $(get_sbox_id ${start} container_${start}) \
"ping -c 1 www.google.com"
fi
fi
# Teardown the container connections and the network
for i in `seq ${start} ${end}`;
do
net_disconnect ${i} container_${i} multihost
dnet_cmd $(inst_id2port $i) container rm container_${i}
done
if [ -z "${2}" -o "${2}" != "skip_rm" ]; then
dnet_cmd $(inst_id2port 2) network rm multihost
fi
}
function check_etchosts() {
local dnet sbid retval
dnet=${1}
shift
sbid=${1}
shift
retval="true"
for i in $*;
do
run runc ${dnet} ${sbid} "cat /etc/hosts"
if [ "$status" -ne 0 ]; then
retval="${output}"
break
fi
line=$(echo ${output} | grep ${i})
if [ "${line}" == "" ]; then
retval="false"
fi
done
echo ${retval}
}
function test_overlay_singlehost() {
dnet_suffix=$1
shift
echo $(docker ps)
start=1
end=3
# Setup overlay network and connect containers to it
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
for i in `seq ${start} ${end}`;
do
dnet_cmd $(inst_id2port 1) container create container_${i}
net_connect 1 container_${i} multihost
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 $dnet_suffix) $(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} multihost
dnet_cmd $(inst_id2port 1) container rm container_${i}
done
dnet_cmd $(inst_id2port 1) network rm multihost
}
function test_overlay_hostmode() {
dnet_suffix=$1
shift
echo $(docker ps)
start=1
end=2
# Setup overlay network and connect containers to it
dnet_cmd $(inst_id2port 1) network create -d overlay multihost1
dnet_cmd $(inst_id2port 1) network create -d overlay multihost2
dnet_cmd $(inst_id2port 1) network ls
for i in `seq ${start} ${end}`;
do
dnet_cmd $(inst_id2port 1) container create mh1_${i}
net_connect 1 mh1_${i} multihost1
done
for i in `seq ${start} ${end}`;
do
dnet_cmd $(inst_id2port 1) container create mh2_${i}
net_connect 1 mh2_${i} multihost2
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
# Find the IP addresses of the j containers on both networks
hrun runc $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh1_${i}) "nslookup mh1_$j"
mh1_j_ip=$(echo ${output} | awk '{print $11}')
hrun runc $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh2_${i}) "nslookup mh2_$j"
mh2_j_ip=$(echo ${output} | awk '{print $11}')
# Ping the j containers in the same network and ensure they are successful
runc $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh1_${i}) \
"ping -c 1 mh1_$j"
runc $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh2_${i}) \
"ping -c 1 mh2_$j"
# Try pinging j container IPs from the container in the other network and make sure that they are not successful
runc_nofail $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh1_${i}) "ping -c 1 ${mh2_j_ip}"
[ "${status}" -ne 0 ]
runc_nofail $(dnet_container_name 1 $dnet_suffix) $(get_sbox_id 1 mh2_${i}) "ping -c 1 ${mh1_j_ip}"
[ "${status}" -ne 0 ]
# Try pinging the j container IPS from the host(dnet container in this case) and make syre that they are not successful
hrun docker exec -it $(dnet_container_name 1 $dnet_suffix) "ping -c 1 ${mh1_j_ip}"
[ "${status}" -ne 0 ]
hrun docker exec -it $(dnet_container_name 1 $dnet_suffix) "ping -c 1 ${mh2_j_ip}"
[ "${status}" -ne 0 ]
done
done
# Teardown the container connections and the network
for i in `seq ${start} ${end}`;
do
net_disconnect 1 mh1_${i} multihost1
dnet_cmd $(inst_id2port 1) container rm mh1_${i}
done
for i in `seq ${start} ${end}`;
do
net_disconnect 1 mh2_${i} multihost2
dnet_cmd $(inst_id2port 1) container rm mh2_${i}
done
dnet_cmd $(inst_id2port 1) network rm multihost1
dnet_cmd $(inst_id2port 1) network rm multihost2
}

View file

@ -1,130 +0,0 @@
# -*- 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`;
do
oname="mh$i"
run dnet_cmd $(inst_id2port $i) network create -d test ${oname}
echo ${output}
[ "$status" -eq 0 ]
for j in `seq 1 3`;
do
result=$(is_network_exist $j ${oname} test)
[ "$result" = "true" ]
done
# 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
}
@test "Test multinode service create" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d test multihost
for i in `seq 1 3`;
do
oname="svc$i"
run dnet_cmd $(inst_id2port $i) service publish ${oname}.multihost
echo ${output}
[ "$status" -eq 0 ]
for j in `seq 1 3`;
do
run dnet_cmd $(inst_id2port $j) service ls
[ "$status" -eq 0 ]
echo ${output}
echo ${lines[1]}
svc=$(echo ${lines[1]} | cut -d" " -f2)
network=$(echo ${lines[1]} | cut -d" " -f3)
echo ${svc} ${network}
[ "$network" = "multihost" ]
[ "$svc" = "${oname}" ]
done
dnet_cmd $(inst_id2port 2) service unpublish ${oname}.multihost
done
dnet_cmd $(inst_id2port 3) network rm multihost
}
@test "Test multinode service attach" {
echo $(docker ps)
dnet_cmd $(inst_id2port 2) network create -d test multihost
dnet_cmd $(inst_id2port 3) service publish svc.multihost
for i in `seq 1 3`;
do
dnet_cmd $(inst_id2port $i) container create container_${i}
dnet_cmd $(inst_id2port $i) service attach container_${i} svc.multihost
run dnet_cmd $(inst_id2port $i) service ls
[ "$status" -eq 0 ]
echo ${output}
echo ${lines[1]}
container=$(echo ${lines[1]} | cut -d" " -f4)
[ "$container" = "container_$i" ]
for j in `seq 1 3`;
do
if [ "$j" = "$i" ]; then
continue
fi
dnet_cmd $(inst_id2port $j) container create container_${j}
run dnet_cmd $(inst_id2port $j) service attach container_${j} svc.multihost
echo ${output}
[ "$status" -ne 0 ]
dnet_cmd $(inst_id2port $j) container rm container_${j}
done
dnet_cmd $(inst_id2port $i) service detach container_${i} svc.multihost
dnet_cmd $(inst_id2port $i) container rm container_${i}
done
dnet_cmd $(inst_id2port 1) service unpublish svc.multihost
dnet_cmd $(inst_id2port 3) network rm multihost
}
@test "Test multinode network and service delete" {
echo $(docker ps)
for i in `seq 1 3`;
do
oname="mh$i"
osvc="svc$i"
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`;
do
run dnet_cmd $(inst_id2port $i) service unpublish ${osvc}.${oname}
echo ${output}
[ "$status" -ne 0 ]
run dnet_cmd $(inst_id2port $j) network rm ${oname}
echo ${output}
[ "$status" -ne 0 ]
done
dnet_cmd $(inst_id2port $i) service detach container_${i} ${osvc}.${oname}
dnet_cmd $(inst_id2port $i) container rm container_${i}
# Always try to remove the service from different nodes
dnet_cmd $(inst_id2port 2) service unpublish ${osvc}.${oname}
dnet_cmd $(inst_id2port 3) network rm ${oname}
done
}

View file

@ -1,57 +0,0 @@
# -*- mode: sh -*-
#!/usr/bin/env bats
load helpers
function test_overlay_local() {
dnet_suffix=$1
echo $(docker ps)
start=1
end=3
for i in `seq ${start} ${end}`;
do
echo "iteration count ${i}"
dnet_cmd $(inst_id2port $i) network create -d overlay --id=mhid --subnet=10.1.0.0/16 --ip-range=10.1.${i}.0/24 --opt=com.docker.network.driver.overlay.vxlanid_list=1024 multihost
dnet_cmd $(inst_id2port $i) container create container_${i}
net_connect ${i} container_${i} multihost
done
# Now test connectivity between all the containers using service names
for i in `seq ${start} ${end}`;
do
if [ -z "${2}" -o "${2}" != "internal" ]; then
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) \
"ping -c 1 www.google.com"
else
default_route=`runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ip route | grep default"`
[ "$default_route" = "" ]
fi
for j in `seq ${start} ${end}`;
do
if [ "$i" -eq "$j" ]; then
continue
fi
#runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ping -c 1 10.1.${j}.1"
runc $(dnet_container_name $i $dnet_suffix) $(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
net_disconnect ${i} container_${i} multihost
dnet_cmd $(inst_id2port $i) container rm container_${i}
done
if [ -z "${2}" -o "${2}" != "skip_rm" ]; then
dnet_cmd $(inst_id2port 2) network rm multihost
fi
}
@test "Test overlay network in local scope" {
test_overlay_local local
}
#"ping -c 1 10.1.${j}.1"

View file

@ -1,91 +0,0 @@
#!/usr/bin/env bash
set -e
export INTEGRATION_ROOT=./integration-tmp
export TMPC_ROOT=./integration-tmp/tmpc
declare -A cmap
trap "cleanup_containers" EXIT SIGINT
function cleanup_containers() {
for c in "${!cmap[@]}"; do
docker rm -f $c 1>> ${INTEGRATION_ROOT}/test.log 2>&1 || true
done
unset cmap
}
function run_bridge_tests() {
## 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
## Teardown
stop_dnet 1 bridge 1>> ${INTEGRATION_ROOT}/test.log 2>&1
unset cmap[dnet-1-bridge]
}
function run_overlay_local_tests() {
## Test overlay network in local scope
## Setup
start_dnet 1 local 1>> ${INTEGRATION_ROOT}/test.log 2>&1
cmap[dnet - 1 - local]=dnet-1-local
start_dnet 2 local:$(dnet_container_ip 1 local) 1>> ${INTEGRATION_ROOT}/test.log 2>&1
cmap[dnet - 2 - local]=dnet-2-local
start_dnet 3 local:$(dnet_container_ip 1 local) 1>> ${INTEGRATION_ROOT}/test.log 2>&1
cmap[dnet - 3 - local]=dnet-3-local
## Run the test cases
./integration-tmp/bin/bats ./test/integration/dnet/overlay-local.bats
## Teardown
stop_dnet 1 local 1>> ${INTEGRATION_ROOT}/test.log 2>&1
unset cmap[dnet-1-local]
stop_dnet 2 local 1>> ${INTEGRATION_ROOT}/test.log 2>&1
unset cmap[dnet-2-local]
stop_dnet 3 local 1>> ${INTEGRATION_ROOT}/test.log 2>&1
unset cmap[dnet-3-local]
}
function run_dnet_tests() {
# Test dnet configuration options
./integration-tmp/bin/bats ./test/integration/dnet/dnet.bats
}
source ./test/integration/dnet/helpers.bash
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
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
# Suite setup
if [ -z "$SUITES" ]; then
suites="dnet bridge"
else
suites="$SUITES"
fi
echo ""
for suite in ${suites}; do
suite_func=run_${suite}_tests
echo "Running ${suite}_tests ..."
declare -F $suite_func > /dev/null && $suite_func
echo ""
done

View file

@ -1,80 +0,0 @@
#!/usr/bin/env bats
load helpers
@test "Test network create" {
echo $(docker ps)
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)
driver=$(echo ${line} | cut -d" " -f3)
echo ${name} ${driver}
[ "$name" = "mh1" ]
[ "$driver" = "test" ]
dnet_cmd $(inst_id2port 1) network rm mh1
}
@test "Test network delete with id" {
echo $(docker ps)
run dnet_cmd $(inst_id2port 1) network create -d test mh1
[ "$status" -eq 0 ]
echo ${output}
dnet_cmd $(inst_id2port 1) network rm ${output}
}
@test "Test service create" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d test multihost
run dnet_cmd $(inst_id2port 1) service publish svc1.multihost
echo ${output}
[ "$status" -eq 0 ]
run dnet_cmd $(inst_id2port 1) service ls
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}
[ "$network" = "multihost" ]
[ "$svc" = "svc1" ]
dnet_cmd $(inst_id2port 1) service unpublish svc1.multihost
dnet_cmd $(inst_id2port 1) network rm multihost
}
@test "Test service delete with id" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d test multihost
run dnet_cmd $(inst_id2port 1) service publish svc1.multihost
[ "$status" -eq 0 ]
echo ${output}
run dnet_cmd $(inst_id2port 1) service ls
[ "$status" -eq 0 ]
echo ${output}
echo ${lines[1]}
id=$(echo ${lines[1]} | cut -d" " -f1)
dnet_cmd $(inst_id2port 1) service unpublish ${id}.multihost
dnet_cmd $(inst_id2port 1) network rm multihost
}
@test "Test service attach" {
echo $(docker ps)
dnet_cmd $(inst_id2port 1) network create -d test multihost
dnet_cmd $(inst_id2port 1) service publish svc1.multihost
dnet_cmd $(inst_id2port 1) container create container_1
dnet_cmd $(inst_id2port 1) service attach container_1 svc1.multihost
run dnet_cmd $(inst_id2port 1) service ls
[ "$status" -eq 0 ]
echo ${output}
echo ${lines[1]}
container=$(echo ${lines[1]} | cut -d" " -f4)
[ "$container" = "container_1" ]
dnet_cmd $(inst_id2port 1) service detach container_1 svc1.multihost
dnet_cmd $(inst_id2port 1) container rm container_1
dnet_cmd $(inst_id2port 1) service unpublish svc1.multihost
dnet_cmd $(inst_id2port 1) network rm multihost
}

View file

@ -1,49 +0,0 @@
#!/bin/bash
# Root directory of the repository.
MACHINE_ROOT=/usr/bin
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
else
ARCH="386"
fi
MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH
BATS_LOG=/tmp/bats.log
touch ${BATS_LOG}
rm ${BATS_LOG}
teardown() {
echo "$BATS_TEST_NAME
----------
$output
----------
" >> ${BATS_LOG}
}
EXTRA_ARGS_CFG='EXTRA_ARGS'
EXTRA_ARGS='--tlsverify --tlscacert=/var/lib/boot2docker/ca.pem --tlskey=/var/lib/boot2docker/server-key.pem --tlscert=/var/lib/boot2docker/server.pem --label=provider=virtualbox -H tcp://0.0.0.0:2376'
TMP_EXTRA_ARGS_FILE=/tmp/tmp_extra_args
DAEMON_CFG_FILE=${BATS_TEST_DIRNAME}/daemon.cfg
set_extra_config() {
if [ -f ${TMP_EXTRA_ARGS_FILE} ]; then
rm ${TMP_EXTRA_ARGS_FILE}
fi
echo -n "${EXTRA_ARGS_CFG}='" > ${TMP_EXTRA_ARGS_FILE}
echo -n "$1 " >> ${TMP_EXTRA_ARGS_FILE}
echo "${EXTRA_ARGS}'" >> ${TMP_EXTRA_ARGS_FILE}
}
if [ ! -e $MACHINE_ROOT/$MACHINE_BIN_NAME ]; then
echo "${MACHINE_ROOT}/${MACHINE_BIN_NAME} not found"
exit 1
fi
function machine() {
${MACHINE_ROOT}/$MACHINE_BIN_NAME "$@"
}