Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker containers as hosts for testing netplugin #37

Merged
merged 11 commits into from
Apr 7, 2015
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ demo: build
clean-demo:
vagrant destroy -f

start-dockerdemo:
scripts/dockerhost/start-dockerhosts

clean-dockerdemo:
scripts/dockerhost/cleanup-dockerhosts

unit-test: build
CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOROOT=$(HOST_GOROOT) ./scripts/unittests -vagrant

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ In the examples directory [two_hosts_multiple_tenants.json](examples/two_hosts_m
[two_hosts_multiple_tenants_mix_vlan_vxlan.json](examples/two_hosts_multiple_tenants_mix_vlan_vxlan.json) shows the creation of a multi-tenant
(disjoint, overlapping) networks within a cluster.

####Trying the multi-host tests on a single machine using docker as hosts
If you cannot launch VM on your host one can also test the multi-host network by simulating hosts using docker containers. Please see [docs/Dockerhost.md](docs/Dockerhost.md) for instructions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sachja overall LGTM
Suggest replacing If you cannot... with If you cannot launch a VM on your host, especially when the host is a VM itself, you can also...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


####Auto-allocation of IP addresses
The plugin can automatically manage the IP address pools and assign an appropriate IP address based on the subnet that was associated with the network. However this doesn't take away the flexibility to keep a specific IP address of a container, which can always be specified as shown earlier. To automatically allocate the IP address, just avoid specifying the IP address during endpoint creation or endpoint description

Expand Down
71 changes: 71 additions & 0 deletions docs/Dockerhost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
The multi node container networking can now be tested on a single VM by running docker inside docker.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - suggest removing now from can now be...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

https://blog.docker.com/2013/09/docker-can-now-run-within-docker/

The outside docker containers act like physical hosts in our test and are connected using a standard linux bridge. Inside each "host container" we run a namespaced instance of docker, OVS , etcd and netplugin instance. One can now launch containers from within each "host containers" and use netplugin networking to connect them.

Prerequisites
-------------
The following needs to be installed on the host machine
1. Docker
2. nsenter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a pointer to nsenter repo so someone can get going)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

3. Linux bridge

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linux bridge is included in linux if I am not mistaken, do you mean brutils? It may be a good idea to give an example that on Ubuntu one can use apt-get install bridge-utils

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Step to launch docker hosts are :
--------------------------------
```
cd $GOPATH/src/github.com/contiv/netplugin
CONTINV_NODES=2 make start-dockerdemo
```

This will start CONTIV_NODES number of containers with docker image called ubuntu_netplugin which is just ubuntu image with docker, etcd and ovs installed.

Now start a shell within any of the "host containers" using following convenient wrapper around nsenter :
```
docker-sh netplugin-node<x>
```

Start netplugin, post netplugin config and launch containers inside the "host containers" the same way you do on VMs.
Note : currently the demo is working only if config is posted before containers are started .. need to debug why the reverse is not working.

To cleanup all the docker hosts and the virtual interfaces created do
```
make cleanup-dockerdemo
```

Example for testing TwoHostMultiVlan you can do :

1. Launch the two host containers

```
export CONTIV_NODES=2
make start-dockerdemo
```

2. Load the netplugin configuration
```
docker-sh netplugin-node1
/netplugin/bin/netdcli -cfg /netplugin/examples/two_hosts_multiple_vlans_nets.json
```

3. Launch container1 on host1

```
docker-sh netplugin-node1
docker run -it --name=myContainer1 --hostname=myContainer1 ubuntu /bin/bash
```

4. Launch container3 on host2

```
docker-sh netplugin-node2
docker run -it --name=myContainer3 --hostname=myContainer1 ubuntu /bin/bash
```

5. Test connectivity between the containers using ping. Go to the shell for container1
```
root@myContainer1:/# ping -c3 11.1.2.2
PING 11.1.2.2 (11.1.2.2) 56(84) bytes of data.
64 bytes from 11.1.2.2: icmp_seq=1 ttl=64 time=3.15 ms
64 bytes from 11.1.2.2: icmp_seq=2 ttl=64 time=1.36 ms
```

2 changes: 1 addition & 1 deletion scripts/checks
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ echo "Checking gofmt..."
fmtRes=$(gofmt -l ./)
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 1
# exit 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exit with '0' code when go-fmt fails? Any reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that got in by mistake. Reverted.

Btw if i do a make build two times without clean i get gofmt errors.

fi

echo "All checks passed!!"
20 changes: 20 additions & 0 deletions scripts/dockerhost/cleanup-dockerhosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#!/bin/bash

num_nodes=1
if [ -z "$CONTIV_NODES" ];
then
num_nodes=1
else
num_nodes=$CONTIV_NODES
fi
echo $num_nodes

for i in `seq 1 $num_nodes`;
do
hostname="netplugin-node$i"
echo "Cleaning $hostname"
sudo docker exec $hostname service docker stop
sudo docker rm -f $hostname
sudo ip link delete $i-ext
done
6 changes: 6 additions & 0 deletions scripts/dockerhost/create_loop_devices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
for i in `seq 9 20`;
do
sudo /bin/mknod -m640 /dev/loop$i b 7 $i
sudo /bin/chown root:disk /dev/loop$i
done
3 changes: 3 additions & 0 deletions scripts/dockerhost/docker-ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@"
3 changes: 3 additions & 0 deletions scripts/dockerhost/docker-pid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

sudo docker inspect --format '{{ .State.Pid }}' "$@"
3 changes: 3 additions & 0 deletions scripts/dockerhost/docker-sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
scriptdir=`dirname "$BASH_SOURCE"`
sudo nsenter --target $($scriptdir/docker-pid $1) --mount --uts --ipc --net --pid
59 changes: 59 additions & 0 deletions scripts/dockerhost/start-dockerhosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

scriptdir=`dirname "$BASH_SOURCE"`
echo $scriptdir

# Create a linux bridge between containers
brctl addbr br-em1
ip link set br-em1 up

num_nodes=1
if [ -z "$CONTIV_NODES" ];
then
num_nodes=1
else
num_nodes=$CONTIV_NODES
fi
echo $num_nodes

netplugin_path=$(pwd)

cluster=""
first="true"
for i in `seq 1 $num_nodes`;
do
hostname="netplugin-node$i"
echo "Starting $hostname"
sudo docker run -d -i -t --name $hostname --privileged -v /var/lib/docker -v $netplugin_path:/netplugin sachja/ubuntu_netplugin bash -c "/netplugin/scripts/dockerhost/start-service.sh & bash"
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n hostname $hostname
sudo ip link add $i-int type veth peer name $i-ext
sudo brctl addif br-em1 $i-ext
sudo ip link set netns $($scriptdir/docker-pid $hostname) dev $i-int
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n ip link set dev $i-int name eth2
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n ip link set eth2 up
if [ $i -gt "1" ]; then
cluster=$cluster",";
fi
sudo docker exec $hostname service docker start
addr=$($scriptdir/docker-ip $hostname)
cluster=$cluster$hostname"=http://"$addr":2380"
first="false"
done

echo $cluster

for i in `seq 1 $num_nodes`;
do
hostname="netplugin-node$i"
echo "Starting etcd on $hostname"
addr=$($scriptdir/docker-ip $hostname)
sudo docker exec $hostname etcd -name $hostname -data-dir /opt/etcd -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -advertise-client-urls http://$addr:2379,http://$addr:4001 -initial-advertise-peer-urls http://$addr:2380 -listen-peer-urls http://$addr:2380 -initial-cluster $cluster -initial-cluster-state new &
done

for i in `seq 1 $num_nodes`;
do
hostname="netplugin-node$i"
echo "Starting netplugin on $hostname"
sudo docker exec $hostname /netplugin/bin/netplugin -host-label host$i &
done

7 changes: 7 additions & 0 deletions scripts/dockerhost/start-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
/etc/init.d/openvswitch-switch restart
while true
do
echo service is running >> service.log
sleep 10
done