Browse code

Merge pull request #28721 from dongluochen/attachable_network

Fix network attachable option

Madhu Venugopal authored on 2016/11/30 04:04:49
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 {
... ...
@@ -425,6 +425,34 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) {
425 425
 	waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains), "testnet")
426 426
 }
427 427
 
428
+func (s *DockerSwarmSuite) TestOverlayAttachable(c *check.C) {
429
+	d1 := s.AddDaemon(c, true, true)
430
+	d2 := s.AddDaemon(c, true, false)
431
+
432
+	out, err := d1.Cmd("network", "create", "-d", "overlay", "--attachable", "ovnet")
433
+	c.Assert(err, checker.IsNil, check.Commentf(out))
434
+
435
+	// validate attachable
436
+	out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
437
+	c.Assert(err, checker.IsNil, check.Commentf(out))
438
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
439
+
440
+	// validate containers can attache to this overlay network
441
+	out, err = d1.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "busybox", "top")
442
+	c.Assert(err, checker.IsNil, check.Commentf(out))
443
+	out, err = d2.Cmd("run", "-d", "--network", "ovnet", "--name", "c2", "busybox", "top")
444
+	c.Assert(err, checker.IsNil, check.Commentf(out))
445
+
446
+	// redo validation, there was a bug that the value of attachable changes after
447
+	// containers attach to the network
448
+	out, err = d1.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
449
+	c.Assert(err, checker.IsNil, check.Commentf(out))
450
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
451
+	out, err = d2.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
452
+	c.Assert(err, checker.IsNil, check.Commentf(out))
453
+	c.Assert(strings.TrimSpace(out), checker.Equals, "true")
454
+}
455
+
428 456
 func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) {
429 457
 	d := s.AddDaemon(c, true, true)
430 458