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

Add tests for internal network

Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
Chun Chen 2015-12-22 09:31:50 +08:00
parent 186a32acab
commit 59e1e42ce7
6 changed files with 35 additions and 8 deletions

View file

@ -8,6 +8,7 @@ import (
"strings"
"github.com/docker/libnetwork"
"github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/types"
"github.com/gorilla/mux"
)
@ -279,6 +280,11 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
processCreateDefaults(c, &create)
options := []libnetwork.NetworkOption{}
if len(create.NetworkOpts) > 0 {
if _, ok := create.NetworkOpts[netlabel.Internal]; ok {
options = append(options, libnetwork.NetworkOptionInternalNetwork())
}
}
if len(create.DriverOpts) > 0 {
options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
}

View file

@ -37,6 +37,7 @@ type networkCreate struct {
Name string `json:"name"`
NetworkType string `json:"network_type"`
DriverOpts map[string]string `json:"driver_opts"`
NetworkOpts map[string]string `json:"network_opts"`
}
// endpointCreate represents the body of the "create endpoint" http request message

View file

@ -9,6 +9,7 @@ import (
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/libnetwork/netlabel"
)
type command struct {
@ -41,15 +42,19 @@ 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")
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
networkOpts := make(map[string]string)
if *flInternal {
networkOpts[netlabel.Internal] = "true"
}
// Construct network create request body
var driverOpts []string
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts}
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts, NetworkOpts: networkOpts}
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
if err != nil {
return err

View file

@ -34,9 +34,10 @@ type SandboxResource struct {
// networkCreate is the expected body of the "create network" http request message
type networkCreate struct {
Name string `json:"name"`
NetworkType string `json:"network_type"`
DriverOpts []string `json:"driver_opts"`
Name string `json:"name"`
NetworkType string `json:"network_type"`
DriverOpts []string `json:"driver_opts"`
NetworkOpts map[string]string `json:"network_opts"`
}
// serviceCreate represents the body of the "publish service" http request message

View file

@ -280,7 +280,11 @@ function test_overlay() {
end=3
# Setup overlay network and connect containers ot it
if [ -z "${2}" -o "${2}" != "skip_add" ]; then
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
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}`;
@ -292,8 +296,13 @@ function test_overlay() {
# Now test connectivity between all the containers using service names
for i in `seq ${start} ${end}`;
do
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) \
"ping -c 1 www.google.com"
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

View file

@ -29,3 +29,8 @@ load helpers
wait_for_dnet $(inst_id2port 3) dnet-3-consul
test_overlay consul skip_add
}
@test "Test overlay network internal network with consul" {
skip_for_circleci
test_overlay consul internal
}