From 0e6be54ce96b0f02b1acac903d2a464e18f1273a Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Tue, 22 Nov 2016 11:33:00 -0800 Subject: [PATCH] Fix network attachable option. Signed-off-by: Dong Chen Upstream-commit: abcb699ad175859ee192388c001f55df5f88e8cd Component: engine --- .../server/router/network/network_routes.go | 2 +- .../cluster/executor/container/container.go | 1 + components/engine/daemon/network.go | 1 + .../integration-cli/docker_cli_swarm_test.go | 28 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/components/engine/api/server/router/network/network_routes.go b/components/engine/api/server/router/network/network_routes.go index 3feb2d8a44..39b45e58bc 100644 --- a/components/engine/api/server/router/network/network_routes.go +++ b/components/engine/api/server/router/network/network_routes.go @@ -172,10 +172,10 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo r.Driver = nw.Type() r.EnableIPv6 = info.IPv6Enabled() r.Internal = info.Internal() + r.Attachable = info.Attachable() r.Options = info.DriverOptions() r.Containers = make(map[string]types.EndpointResource) buildIpamResources(r, info) - r.Internal = info.Internal() r.Labels = info.Labels() peers := info.Peers() diff --git a/components/engine/daemon/cluster/executor/container/container.go b/components/engine/daemon/cluster/executor/container/container.go index 112ecf262a..d44ae2945b 100644 --- a/components/engine/daemon/cluster/executor/container/container.go +++ b/components/engine/daemon/cluster/executor/container/container.go @@ -571,6 +571,7 @@ func (c *containerConfig) networkCreateRequest(name string) (clustertypes.Networ Options: na.Network.DriverState.Options, Labels: na.Network.Spec.Annotations.Labels, Internal: na.Network.Spec.Internal, + Attachable: na.Network.Spec.Attachable, EnableIPv6: na.Network.Spec.Ipv6Enabled, CheckDuplicate: true, } diff --git a/components/engine/daemon/network.go b/components/engine/daemon/network.go index 8cb0c2f813..e1acf7e2e6 100644 --- a/components/engine/daemon/network.go +++ b/components/engine/daemon/network.go @@ -269,6 +269,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string libnetwork.NetworkOptionEnableIPv6(create.EnableIPv6), libnetwork.NetworkOptionDriverOpts(create.Options), libnetwork.NetworkOptionLabels(create.Labels), + libnetwork.NetworkOptionAttachable(create.Attachable), } if create.IPAM != nil { diff --git a/components/engine/integration-cli/docker_cli_swarm_test.go b/components/engine/integration-cli/docker_cli_swarm_test.go index c38a707aec..47c715c749 100644 --- a/components/engine/integration-cli/docker_cli_swarm_test.go +++ b/components/engine/integration-cli/docker_cli_swarm_test.go @@ -418,6 +418,34 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) { waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains), "testnet") } +func (s *DockerSwarmSuite) TestOverlayAttachable(c *check.C) { + d1 := s.AddDaemon(c, true, true) + d2 := s.AddDaemon(c, true, false) + + out, err := d1.Cmd("network", "create", "-d", "overlay", "--attachable", "ovnet") + c.Assert(err, checker.IsNil, check.Commentf(out)) + + // validate attachable + out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet") + c.Assert(err, checker.IsNil, check.Commentf(out)) + c.Assert(strings.TrimSpace(out), checker.Equals, "true") + + // validate containers can attache to this overlay network + out, err = d1.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "busybox", "top") + c.Assert(err, checker.IsNil, check.Commentf(out)) + out, err = d2.Cmd("run", "-d", "--network", "ovnet", "--name", "c2", "busybox", "top") + c.Assert(err, checker.IsNil, check.Commentf(out)) + + // redo validation, there was a bug that the value of attachable changes after + // containers attach to the network + out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet") + c.Assert(err, checker.IsNil, check.Commentf(out)) + c.Assert(strings.TrimSpace(out), checker.Equals, "true") + out, err = d2.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet") + c.Assert(err, checker.IsNil, check.Commentf(out)) + c.Assert(strings.TrimSpace(out), checker.Equals, "true") +} + func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) { d := s.AddDaemon(c, true, true)