Browse code

Fix network attachable option.

Signed-off-by: Dong Chen <dongluo.chen@docker.com>
(cherry picked from commit abcb699ad175859ee192388c001f55df5f88e8cd)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Dong Chen authored on 2016/11/23 04:33:00
Showing 4 changed files
... ...
@@ -172,10 +172,10 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
172 172
 	r.Driver = nw.Type()
173 173
 	r.EnableIPv6 = info.IPv6Enabled()
174 174
 	r.Internal = info.Internal()
175
+	r.Attachable = info.Attachable()
175 176
 	r.Options = info.DriverOptions()
176 177
 	r.Containers = make(map[string]types.EndpointResource)
177 178
 	buildIpamResources(r, info)
178
-	r.Internal = info.Internal()
179 179
 	r.Labels = info.Labels()
180 180
 
181 181
 	peers := info.Peers()
... ...
@@ -571,6 +571,7 @@ func (c *containerConfig) networkCreateRequest(name string) (clustertypes.Networ
571 571
 		Options:        na.Network.DriverState.Options,
572 572
 		Labels:         na.Network.Spec.Annotations.Labels,
573 573
 		Internal:       na.Network.Spec.Internal,
574
+		Attachable:     na.Network.Spec.Attachable,
574 575
 		EnableIPv6:     na.Network.Spec.Ipv6Enabled,
575 576
 		CheckDuplicate: true,
576 577
 	}
... ...
@@ -269,6 +269,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
269 269
 		libnetwork.NetworkOptionEnableIPv6(create.EnableIPv6),
270 270
 		libnetwork.NetworkOptionDriverOpts(create.Options),
271 271
 		libnetwork.NetworkOptionLabels(create.Labels),
272
+		libnetwork.NetworkOptionAttachable(create.Attachable),
272 273
 	}
273 274
 
274 275
 	if create.IPAM != nil {
... ...
@@ -418,6 +418,34 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) {
418 418
 	waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains), "testnet")
419 419
 }
420 420
 
421
+func (s *DockerSwarmSuite) TestOverlayAttachable(c *check.C) {
422
+	d1 := s.AddDaemon(c, true, true)
423
+	d2 := s.AddDaemon(c, true, false)
424
+
425
+	out, err := d1.Cmd("network", "create", "-d", "overlay", "--attachable", "ovnet")
426
+	c.Assert(err, checker.IsNil, check.Commentf(out))
427
+
428
+	// validate attachable
429
+	out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
430
+	c.Assert(err, checker.IsNil, check.Commentf(out))
431
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
432
+
433
+	// validate containers can attache to this overlay network
434
+	out, err = d1.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "busybox", "top")
435
+	c.Assert(err, checker.IsNil, check.Commentf(out))
436
+	out, err = d2.Cmd("run", "-d", "--network", "ovnet", "--name", "c2", "busybox", "top")
437
+	c.Assert(err, checker.IsNil, check.Commentf(out))
438
+
439
+	// redo validation, there was a bug that the value of attachable changes after
440
+	// containers attach to the network
441
+	out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
442
+	c.Assert(err, checker.IsNil, check.Commentf(out))
443
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
444
+	out, err = d2.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
445
+	c.Assert(err, checker.IsNil, check.Commentf(out))
446
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
447
+}
448
+
421 449
 func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) {
422 450
 	d := s.AddDaemon(c, true, true)
423 451