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

Dnet agent mode support and IT

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2016-04-01 10:26:57 -07:00
parent 0580043718
commit bd74df7b41
8 changed files with 224 additions and 36 deletions

View file

@ -307,7 +307,17 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
if len(create.DriverOpts) > 0 {
options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
}
nw, err := c.NewNetwork(create.NetworkType, create.Name, "", options...)
if len(create.IPv4Conf) > 0 {
ipamV4Conf := &libnetwork.IpamConf{
PreferredPool: create.IPv4Conf[0].PreferredPool,
SubPool: create.IPv4Conf[0].SubPool,
}
options = append(options, libnetwork.NetworkOptionIpam("default", "", []*libnetwork.IpamConf{ipamV4Conf}, nil, nil))
}
nw, err := c.NewNetwork(create.NetworkType, create.Name, create.ID, options...)
if err != nil {
return nil, convertNetworkError(err)
}
@ -697,6 +707,7 @@ func procAttachBackend(c libnetwork.NetworkController, vars map[string]string, b
if err != nil {
return nil, convertNetworkError(err)
}
return sb.Key(), &successResponse
}

View file

@ -32,10 +32,19 @@ type sandboxResource struct {
Body types
************/
type ipamConf struct {
PreferredPool string
SubPool string
Gateway string
AuxAddresses map[string]string
}
// networkCreate is the expected body of the "create network" http request message
type networkCreate struct {
Name string `json:"name"`
ID string `json:"id"`
NetworkType string `json:"network_type"`
IPv4Conf []ipamConf `json:"ipv4_configuration"`
DriverOpts map[string]string `json:"driver_opts"`
NetworkOpts map[string]string `json:"network_opts"`
}

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
"text/tabwriter"
flag "github.com/docker/docker/pkg/mflag"
@ -42,8 +43,13 @@ func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error {
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
flID := cmd.String([]string{"-id"}, "", "Network ID string")
flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
flRange := cmd.String([]string{"-ip-range"}, "", "Range option")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
@ -56,9 +62,30 @@ func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
if *flIPv6 {
networkOpts[netlabel.EnableIPv6] = "true"
}
driverOpts := make(map[string]string)
if *flOpts != "" {
opts := strings.Split(*flOpts, ",")
for _, opt := range opts {
driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
}
}
var icList []ipamConf
if *flSubnet != "" {
ic := ipamConf{
PreferredPool: *flSubnet,
}
if *flRange != "" {
ic.SubPool = *flRange
}
icList = append(icList, ic)
}
// Construct network create request body
var driverOpts []string
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts, NetworkOpts: networkOpts}
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
if err != nil {
return err

View file

@ -31,12 +31,20 @@ type SandboxResource struct {
/***********
Body types
************/
type ipamConf struct {
PreferredPool string
SubPool string
Gateway string
AuxAddresses map[string]string
}
// networkCreate is the expected body of the "create network" http request message
type networkCreate struct {
Name string `json:"name"`
ID string `json:"id"`
NetworkType string `json:"network_type"`
DriverOpts []string `json:"driver_opts"`
IPv4Conf []ipamConf `json:"ipv4_configuration"`
DriverOpts map[string]string `json:"driver_opts"`
NetworkOpts map[string]string `json:"network_opts"`
}

View file

@ -91,6 +91,15 @@ func processConfig(cfg *config.Config) []config.Option {
dd = cfg.Daemon.DefaultDriver
}
options = append(options, config.OptionDefaultDriver(dd))
if cfg.Daemon.IsAgent {
options = append(options, config.OptionAgent())
}
if cfg.Daemon.Bind != "" {
options = append(options, config.OptionBind(cfg.Daemon.Bind))
}
options = append(options, config.OptionNeighbors(cfg.Daemon.Neighbors))
if cfg.Daemon.Labels != nil {
options = append(options, config.OptionLabels(cfg.Daemon.Labels))

View file

@ -10,6 +10,10 @@ 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
@ -18,17 +22,17 @@ function get_sbox_id() {
}
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}
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() {
@ -107,7 +111,7 @@ function parse_discovery_str() {
}
function start_dnet() {
local inst suffix name hport cport hopt store bridge_ip labels tomlfile
local inst suffix name hport cport hopt store bridge_ip labels tomlfile nip
local discovery provider address
inst=$1
@ -115,13 +119,16 @@ function start_dnet() {
suffix=$1
shift
stop_dnet ${inst} ${suffix}
name=$(dnet_container_name ${inst} ${suffix})
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=""
store=${suffix}
while [ -n "$1" ]
do
@ -138,21 +145,32 @@ function start_dnet() {
bridge_ip=$(get_docker_bridge_ip)
echo "start_dnet parsed values: " ${inst} ${suffix} ${name} ${hport} ${cport} ${hopt} ${store} ${labels}
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 [ "$store" = "zookeeper" ]; then
read discovery provider address < <(parse_discovery_str zk://${bridge_ip}:2182)
elif [ "$store" = "etcd" ]; then
read discovery provider address < <(parse_discovery_str etcd://${bridge_ip}:42000/custom_prefix)
else
elif [ "$store" = "consul" ]; then
read discovery provider address < <(parse_discovery_str consul://${bridge_ip}:8500/custom_prefix)
else
if [ "$nip" != "" ]; then
neighbors="neighbors = [\"${nip}:7946\"]"
fi
discovery=""
provider=""
address=""
fi
cat > ${tomlfile} <<EOF
if [ "$discovery" != "" ]; then
cat > ${tomlfile} <<EOF
title = "LibNetwork Configuration file for ${name}"
[daemon]
@ -166,9 +184,22 @@ title = "LibNetwork Configuration file for ${name}"
provider = "${provider}"
address = "${address}"
EOF
else
cat > ${tomlfile} <<EOF
title = "LibNetwork Configuration file for ${name}"
[daemon]
debug = false
isagent = true
bind = "eth0"
${neighbors}
EOF
fi
cat ${tomlfile}
docker run \
-d \
--hostname=${name} \
--name=${name} \
--privileged \
-p ${hport}:${cport} \
@ -183,6 +214,19 @@ EOF
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 skip_for_circleci() {
if [ -n "$CIRCLECI" ]; then
skip
@ -289,7 +333,7 @@ function test_overlay() {
end=3
# Setup overlay network and connect containers ot it
if [ -z "${2}" -o "${2}" != "skip_add" ]; then
if [ -z "${2}" -o "${2}" != "internal" ]; 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
@ -307,7 +351,7 @@ function test_overlay() {
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"
"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" = "" ]
@ -324,33 +368,33 @@ function test_overlay() {
# Setup bridge network and connect containers ot it
if [ -z "${2}" -o "${2}" != "skip_add" ]; then
if [ -z "${2}" -o "${2}" != "internal" ]; 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
# Make sure external connectivity works
runc $(dnet_container_name ${start} $dnet_suffix) $(get_sbox_id ${start} container_${start}) \
"ping -c 1 www.google.com"
"ping -c 1 www.google.com"
net_disconnect ${start} container_${start} br1
net_disconnect ${start} container_${start} br2
# Make sure external connectivity works
# Make sure external connectivity works
runc $(dnet_container_name ${start} $dnet_suffix) $(get_sbox_id ${start} container_${start}) \
"ping -c 1 www.google.com"
"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
# Disconnect from overlay network
net_disconnect ${start} container_${start} multihost
# Connect to overlay network again
net_connect ${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"
# 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

View file

@ -0,0 +1,58 @@
# -*- 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" {
skip_for_circleci
test_overlay_local local
}
#"ping -c 1 10.1.${j}.1"

View file

@ -34,6 +34,28 @@ function run_bridge_tests() {
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_overlay_consul_tests() {
## Test overlay network with consul
## Setup