Browse code

Migrate test-integration-cli experimental macvlan test to integration

All `Macvlan` related test on `DockerSuite` and `DockerNetworkSuite`
are migrated to `macvlan_test.go`.

Also, as `macvlan` seems to be out of experimental, this removes
the *skip* when the run is not experimental (and doesn't start a
daemon with experimental either).

The end goal being to remove the `experimental` builds.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2018/03/28 17:47:11
Showing 3 changed files
... ...
@@ -34,25 +34,6 @@ func checkKernelMajorVersionGreaterOrEqualThen(kernelVersion int, majorVersion i
34 34
 	return true
35 35
 }
36 36
 
37
-func (s *DockerNetworkSuite) TestDockerNetworkMacvlanPersistance(c *check.C) {
38
-	// verify the driver automatically provisions the 802.1q link (dm-dummy0.60)
39
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
40
-
41
-	// master dummy interface 'dm' abbreviation represents 'docker macvlan'
42
-	master := "dm-dummy0"
43
-	// simulate the master link the vlan tagged subinterface parent link will use
44
-	createMasterDummy(c, master)
45
-	// cleanup the master interface that also collects the slave dev
46
-	defer deleteInterface(c, master)
47
-	// create a network specifying the desired sub-interface name
48
-	dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.60", "dm-persist")
49
-	assertNwIsAvailable(c, "dm-persist")
50
-	// Restart docker daemon to test the config has persisted to disk
51
-	s.d.Restart(c)
52
-	// verify network is recreated from persistence
53
-	assertNwIsAvailable(c, "dm-persist")
54
-}
55
-
56 37
 func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) {
57 38
 	// verify the driver automatically provisions the 802.1q link (di-dummy0.70)
58 39
 	testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
... ...
@@ -71,20 +52,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) {
71 71
 	assertNwIsAvailable(c, "di-persist")
72 72
 }
73 73
 
74
-func (s *DockerNetworkSuite) TestDockerNetworkMacvlanSubIntCreate(c *check.C) {
75
-	// verify the driver automatically provisions the 802.1q link (dm-dummy0.50)
76
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
77
-	// master dummy interface 'dm' abbreviation represents 'docker macvlan'
78
-	master := "dm-dummy0"
79
-	// simulate the master link the vlan tagged subinterface parent link will use
80
-	createMasterDummy(c, master)
81
-	// cleanup the master interface which also collects the slave dev
82
-	defer deleteInterface(c, master)
83
-	// create a network specifying the desired sub-interface name
84
-	dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.50", "dm-subinterface")
85
-	assertNwIsAvailable(c, "dm-subinterface")
86
-}
87
-
88 74
 func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) {
89 75
 	// verify the driver automatically provisions the 802.1q link (di-dummy0.50)
90 76
 	testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
... ...
@@ -99,24 +66,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) {
99 99
 	assertNwIsAvailable(c, "di-subinterface")
100 100
 }
101 101
 
102
-func (s *DockerNetworkSuite) TestDockerNetworkMacvlanOverlapParent(c *check.C) {
103
-	// verify the same parent interface cannot be used if already in use by an existing network
104
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
105
-	// master dummy interface 'dm' abbreviation represents 'docker macvlan'
106
-	master := "dm-dummy0"
107
-	createMasterDummy(c, master)
108
-	// cleanup the master interface which also collects the slave dev
109
-	defer deleteInterface(c, master)
110
-	createVlanInterface(c, master, "dm-dummy0.40", "40")
111
-	// create a network using an existing parent interface
112
-	dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-subinterface")
113
-	assertNwIsAvailable(c, "dm-subinterface")
114
-	// attempt to create another network using the same parent iface that should fail
115
-	out, _, err := dockerCmdWithError("network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-parent-net-overlap")
116
-	// verify that the overlap returns an error
117
-	c.Assert(err, check.NotNil, check.Commentf(out))
118
-}
119
-
120 102
 func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) {
121 103
 	// verify the same parent interface cannot be used if already in use by an existing network
122 104
 	testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
... ...
@@ -135,61 +84,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) {
135 135
 	c.Assert(err, check.NotNil, check.Commentf(out))
136 136
 }
137 137
 
138
-func (s *DockerNetworkSuite) TestDockerNetworkMacvlanMultiSubnet(c *check.C) {
139
-	// create a dual stack multi-subnet Macvlan bridge mode network and validate connectivity between four containers, two on each subnet
140
-	testRequires(c, DaemonIsLinux, IPv6, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
141
-	dockerCmd(c, "network", "create", "--driver=macvlan", "--ipv6", "--subnet=172.28.100.0/24", "--subnet=172.28.102.0/24", "--gateway=172.28.102.254",
142
-		"--subnet=2001:db8:abc2::/64", "--subnet=2001:db8:abc4::/64", "--gateway=2001:db8:abc4::254", "dualstackbridge")
143
-	// Ensure the network was created
144
-	assertNwIsAvailable(c, "dualstackbridge")
145
-	// start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.100.0/24 and 2001:db8:abc2::/64
146
-	dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=first", "--ip", "172.28.100.20", "--ip6", "2001:db8:abc2::20", "busybox:glibc", "top")
147
-	dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=second", "--ip", "172.28.100.21", "--ip6", "2001:db8:abc2::21", "busybox:glibc", "top")
148
-
149
-	// Inspect and store the v4 address from specified container on the network dualstackbridge
150
-	ip := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.IPAddress")
151
-	// Inspect and store the v6 address from specified container on the network dualstackbridge
152
-	ip6 := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.GlobalIPv6Address")
153
-
154
-	// verify ipv4 connectivity to the explicit --ipv address second to first
155
-	_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", strings.TrimSpace(ip))
156
-	c.Assert(err, check.IsNil)
157
-	// verify ipv6 connectivity to the explicit --ipv6 address second to first
158
-	c.Skip("Temporarily skipping while investigating sporadic v6 CI issues")
159
-	_, _, err = dockerCmdWithError("exec", "second", "ping6", "-c", "1", strings.TrimSpace(ip6))
160
-	c.Assert(err, check.IsNil)
161
-
162
-	// start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.102.0/24 and 2001:db8:abc4::/64
163
-	dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=third", "--ip", "172.28.102.20", "--ip6", "2001:db8:abc4::20", "busybox:glibc", "top")
164
-	dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=fourth", "--ip", "172.28.102.21", "--ip6", "2001:db8:abc4::21", "busybox:glibc", "top")
165
-
166
-	// Inspect and store the v4 address from specified container on the network dualstackbridge
167
-	ip = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.IPAddress")
168
-	// Inspect and store the v6 address from specified container on the network dualstackbridge
169
-	ip6 = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.GlobalIPv6Address")
170
-
171
-	// verify ipv4 connectivity to the explicit --ipv address from third to fourth
172
-	_, _, err = dockerCmdWithError("exec", "fourth", "ping", "-c", "1", strings.TrimSpace(ip))
173
-	c.Assert(err, check.IsNil)
174
-	// verify ipv6 connectivity to the explicit --ipv6 address from third to fourth
175
-	_, _, err = dockerCmdWithError("exec", "fourth", "ping6", "-c", "1", strings.TrimSpace(ip6))
176
-	c.Assert(err, check.IsNil)
177
-
178
-	// Inspect the v4 gateway to ensure the proper default GW was assigned
179
-	ip4gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.Gateway")
180
-	c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.100.1")
181
-	// Inspect the v6 gateway to ensure the proper default GW was assigned
182
-	ip6gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.IPv6Gateway")
183
-	c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc2::1")
184
-
185
-	// Inspect the v4 gateway to ensure the proper explicitly assigned default GW was assigned
186
-	ip4gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.Gateway")
187
-	c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.102.254")
188
-	// Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned
189
-	ip6gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.IPv6Gateway")
190
-	c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc4::254")
191
-}
192
-
193 138
 func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL2MultiSubnet(c *check.C) {
194 139
 	// create a dual stack multi-subnet Ipvlan L2 network and validate connectivity within the subnets, two on each subnet
195 140
 	testRequires(c, DaemonIsLinux, IPv6, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
... ...
@@ -349,45 +243,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanAddressing(c *check.C) {
349 349
 	c.Assert(out, checker.Contains, "default dev eth0")
350 350
 }
351 351
 
352
-func (s *DockerSuite) TestDockerNetworkMacVlanBridgeNilParent(c *check.C) {
353
-	// macvlan bridge mode - dummy parent interface is provisioned dynamically
354
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
355
-	dockerCmd(c, "network", "create", "--driver=macvlan", "dm-nil-parent")
356
-	assertNwIsAvailable(c, "dm-nil-parent")
357
-
358
-	// start two containers on the same subnet
359
-	dockerCmd(c, "run", "-d", "--net=dm-nil-parent", "--name=first", "busybox:glibc", "top")
360
-	c.Assert(waitRun("first"), check.IsNil)
361
-	dockerCmd(c, "run", "-d", "--net=dm-nil-parent", "--name=second", "busybox:glibc", "top")
362
-	c.Assert(waitRun("second"), check.IsNil)
363
-
364
-	// intra-network communications should succeed
365
-	_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
366
-	c.Assert(err, check.IsNil)
367
-}
368
-
369
-func (s *DockerSuite) TestDockerNetworkMacVlanBridgeInternalMode(c *check.C) {
370
-	// macvlan bridge mode --internal containers can communicate inside the network but not externally
371
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
372
-	cli.DockerCmd(c, "network", "create", "--driver=macvlan", "--internal", "dm-internal")
373
-	assertNwIsAvailable(c, "dm-internal")
374
-	nr := getNetworkResource(c, "dm-internal")
375
-	c.Assert(nr.Internal, checker.True)
376
-
377
-	// start two containers on the same subnet
378
-	cli.DockerCmd(c, "run", "-d", "--net=dm-internal", "--name=first", "busybox:glibc", "top")
379
-	c.Assert(waitRun("first"), check.IsNil)
380
-	cli.DockerCmd(c, "run", "-d", "--net=dm-internal", "--name=second", "busybox:glibc", "top")
381
-	c.Assert(waitRun("second"), check.IsNil)
382
-
383
-	// access outside of the network should fail
384
-	result := cli.Docker(cli.Args("exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8"), cli.WithTimeout(time.Second))
385
-	result.Assert(c, icmd.Expected{Timeout: true})
386
-
387
-	// intra-network communications should succeed
388
-	cli.DockerCmd(c, "exec", "second", "ping", "-c", "1", "first")
389
-}
390
-
391 352
 func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) {
392 353
 	// ipvlan l2 mode - dummy parent interface is provisioned dynamically
393 354
 	testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
... ...
@@ -466,54 +321,6 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL3InternalMode(c *check.C) {
466 466
 	cli.DockerCmd(c, "exec", "second", "ping", "-c", "1", "first")
467 467
 }
468 468
 
469
-func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) {
470
-	// macvlan bridge mode - empty parent interface containers can reach each other internally but not externally
471
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
472
-	netName := "dm-parent-exists"
473
-	createMasterDummy(c, "dm-dummy0")
474
-	defer deleteInterface(c, "dm-dummy0")
475
-	//out, err := createVlanInterface(c, "dm-parent", "dm-slave", "macvlan", "bridge")
476
-	// create a network using an existing parent interface
477
-	dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0", netName)
478
-	assertNwIsAvailable(c, netName)
479
-	// delete the network while preserving the parent link
480
-	dockerCmd(c, "network", "rm", netName)
481
-	assertNwNotAvailable(c, netName)
482
-	// verify the network delete did not delete the predefined link
483
-	linkExists(c, "dm-dummy0")
484
-}
485
-
486
-func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) {
487
-	// macvlan bridge mode -  empty parent interface containers can reach each other internally but not externally
488
-	testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
489
-	netName := "dm-subinterface"
490
-	createMasterDummy(c, "dm-dummy0")
491
-	// delete the parent interface which also collects the slave
492
-	defer deleteInterface(c, "dm-dummy0")
493
-	createVlanInterface(c, "dm-dummy0", "dm-dummy0.20", "20")
494
-	// create a network using an existing parent interface
495
-	dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.20", netName)
496
-	assertNwIsAvailable(c, netName)
497
-
498
-	// start containers on 802.1q tagged '-o parent' sub-interface
499
-	dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=first", "busybox:glibc", "top")
500
-	c.Assert(waitRun("first"), check.IsNil)
501
-	dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=second", "busybox:glibc", "top")
502
-	c.Assert(waitRun("second"), check.IsNil)
503
-	// verify containers can communicate
504
-	_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
505
-	c.Assert(err, check.IsNil)
506
-
507
-	// remove the containers
508
-	dockerCmd(c, "rm", "-f", "first")
509
-	dockerCmd(c, "rm", "-f", "second")
510
-	// delete the network while preserving the parent link
511
-	dockerCmd(c, "network", "rm", netName)
512
-	assertNwNotAvailable(c, netName)
513
-	// verify the network delete did not delete the predefined sub-interface
514
-	linkExists(c, "dm-dummy0.20")
515
-}
516
-
517 469
 func createMasterDummy(c *check.C, master string) {
518 470
 	// ip link add <dummy_name> type dummy
519 471
 	icmd.RunCommand("ip", "link", "add", master, "type", "dummy").Assert(c, icmd.Success)
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"fmt"
5 5
 
6 6
 	containertypes "github.com/docker/docker/api/types/container"
7
+	networktypes "github.com/docker/docker/api/types/network"
7 8
 	"github.com/docker/docker/api/types/strslice"
8 9
 	"github.com/docker/go-connections/nat"
9 10
 )
... ...
@@ -83,3 +84,29 @@ func WithBind(src, target string) func(*TestContainerConfig) {
83 83
 		c.HostConfig.Binds = append(c.HostConfig.Binds, fmt.Sprintf("%s:%s", src, target))
84 84
 	}
85 85
 }
86
+
87
+// WithIPv4 sets the specified ip for the specified network of the container
88
+func WithIPv4(network, ip string) func(*TestContainerConfig) {
89
+	return func(c *TestContainerConfig) {
90
+		if v, ok := c.NetworkingConfig.EndpointsConfig[network]; !ok || v == nil {
91
+			c.NetworkingConfig.EndpointsConfig[network] = &networktypes.EndpointSettings{}
92
+		}
93
+		if c.NetworkingConfig.EndpointsConfig[network].IPAMConfig == nil {
94
+			c.NetworkingConfig.EndpointsConfig[network].IPAMConfig = &networktypes.EndpointIPAMConfig{}
95
+		}
96
+		c.NetworkingConfig.EndpointsConfig[network].IPAMConfig.IPv4Address = ip
97
+	}
98
+}
99
+
100
+// WithIPv6 sets the specified ip6 for the specified network of the container
101
+func WithIPv6(network, ip string) func(*TestContainerConfig) {
102
+	return func(c *TestContainerConfig) {
103
+		if v, ok := c.NetworkingConfig.EndpointsConfig[network]; !ok || v == nil {
104
+			c.NetworkingConfig.EndpointsConfig[network] = &networktypes.EndpointSettings{}
105
+		}
106
+		if c.NetworkingConfig.EndpointsConfig[network].IPAMConfig == nil {
107
+			c.NetworkingConfig.EndpointsConfig[network].IPAMConfig = &networktypes.EndpointIPAMConfig{}
108
+		}
109
+		c.NetworkingConfig.EndpointsConfig[network].IPAMConfig.IPv6Address = ip
110
+	}
111
+}
86 112
new file mode 100644
... ...
@@ -0,0 +1,354 @@
0
+package network
1
+
2
+import (
3
+	"context"
4
+	"fmt"
5
+	"testing"
6
+	"time"
7
+
8
+	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/api/types/network"
10
+	"github.com/docker/docker/client"
11
+	"github.com/docker/docker/integration-cli/daemon"
12
+	"github.com/docker/docker/integration/internal/container"
13
+	"github.com/docker/docker/pkg/parsers/kernel"
14
+	"github.com/gotestyourself/gotestyourself/assert"
15
+	"github.com/gotestyourself/gotestyourself/assert/cmp"
16
+	"github.com/gotestyourself/gotestyourself/icmd"
17
+	"github.com/gotestyourself/gotestyourself/skip"
18
+)
19
+
20
+func TestDockerNetworkMacvlanPersistance(t *testing.T) {
21
+	// verify the driver automatically provisions the 802.1q link (dm-dummy0.60)
22
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
23
+	skip.If(t, testEnv.IsRemoteDaemon())
24
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
25
+
26
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
27
+	d.StartWithBusybox(t)
28
+	defer d.Stop(t)
29
+
30
+	master := "dm-dummy0"
31
+	createMasterDummy(t, master)
32
+	defer deleteInterface(t, master)
33
+
34
+	client, err := d.NewClient()
35
+	assert.NilError(t, err)
36
+
37
+	_, err = client.NetworkCreate(context.Background(), "dm-persist", types.NetworkCreate{
38
+		Driver: "macvlan",
39
+		Options: map[string]string{
40
+			"parent": "dm-dummy0.60",
41
+		},
42
+	})
43
+	assert.NilError(t, err)
44
+	assert.Check(t, isNetworkAvailable(client, "dm-persist"))
45
+	d.Restart(t)
46
+	assert.Check(t, isNetworkAvailable(client, "dm-persist"))
47
+}
48
+
49
+func TestDockerNetworkMacvlanOverlapParent(t *testing.T) {
50
+	// verify the same parent interface cannot be used if already in use by an existing network
51
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
52
+	skip.If(t, testEnv.IsRemoteDaemon())
53
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
54
+
55
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
56
+	d.StartWithBusybox(t)
57
+	defer d.Stop(t)
58
+
59
+	master := "dm-dummy0"
60
+	createMasterDummy(t, master)
61
+	defer deleteInterface(t, master)
62
+
63
+	client, err := d.NewClient()
64
+	assert.NilError(t, err)
65
+
66
+	_, err = client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
67
+		Driver: "macvlan",
68
+		Options: map[string]string{
69
+			"parent": "dm-dummy0.40",
70
+		},
71
+	})
72
+	assert.NilError(t, err)
73
+	assert.Check(t, isNetworkAvailable(client, "dm-subinterface"))
74
+
75
+	_, err = client.NetworkCreate(context.Background(), "dm-parent-net-overlap", types.NetworkCreate{
76
+		Driver: "macvlan",
77
+		Options: map[string]string{
78
+			"parent": "dm-dummy0.40",
79
+		},
80
+	})
81
+	assert.Check(t, err != nil)
82
+	// delete the network while preserving the parent link
83
+	err = client.NetworkRemove(context.Background(), "dm-subinterface")
84
+	assert.NilError(t, err)
85
+
86
+	assert.Check(t, isNetworkNotAvailable(client, "dm-subinterface"))
87
+	// verify the network delete did not delete the predefined link
88
+	linkExists(t, "dm-dummy0")
89
+}
90
+
91
+func TestDockerNetworkMacvlanSubinterface(t *testing.T) {
92
+	// verify the same parent interface cannot be used if already in use by an existing network
93
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
94
+	skip.If(t, testEnv.IsRemoteDaemon())
95
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
96
+
97
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
98
+	d.StartWithBusybox(t)
99
+	defer d.Stop(t)
100
+
101
+	master := "dm-dummy0"
102
+	createMasterDummy(t, master)
103
+	defer deleteInterface(t, master)
104
+	createVlanInterface(t, master, "dm-dummy0.20", "20")
105
+
106
+	client, err := d.NewClient()
107
+	assert.NilError(t, err)
108
+
109
+	_, err = client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
110
+		Driver: "macvlan",
111
+		Options: map[string]string{
112
+			"parent": "dm-dummy0.20",
113
+		},
114
+	})
115
+	assert.NilError(t, err)
116
+	assert.Check(t, isNetworkAvailable(client, "dm-subinterface"))
117
+
118
+	// delete the network while preserving the parent link
119
+	err = client.NetworkRemove(context.Background(), "dm-subinterface")
120
+	assert.NilError(t, err)
121
+
122
+	assert.Check(t, isNetworkNotAvailable(client, "dm-subinterface"))
123
+	// verify the network delete did not delete the predefined link
124
+	linkExists(t, "dm-dummy0.20")
125
+}
126
+
127
+func TestDockerNetworkMacvlanBridgeNilParent(t *testing.T) {
128
+	// macvlan bridge mode - dummy parent interface is provisioned dynamically
129
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
130
+	skip.If(t, testEnv.IsRemoteDaemon())
131
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
132
+
133
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
134
+	d.StartWithBusybox(t)
135
+	defer d.Stop(t)
136
+	client, err := d.NewClient()
137
+	assert.NilError(t, err)
138
+
139
+	_, err = client.NetworkCreate(context.Background(), "dm-nil-parent", types.NetworkCreate{
140
+		Driver: "macvlan",
141
+	})
142
+	assert.NilError(t, err)
143
+	assert.Check(t, isNetworkAvailable(client, "dm-nil-parent"))
144
+
145
+	ctx := context.Background()
146
+	container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"), container.WithName(t.Name()+"first"))
147
+	id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"), container.WithName(t.Name()+"second"))
148
+
149
+	_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", t.Name() + "first"})
150
+	assert.Check(t, err == nil)
151
+}
152
+
153
+func TestDockerNetworkMacvlanBridgeInternal(t *testing.T) {
154
+	// macvlan bridge mode - dummy parent interface is provisioned dynamically
155
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
156
+	skip.If(t, testEnv.IsRemoteDaemon())
157
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
158
+
159
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
160
+	d.StartWithBusybox(t)
161
+	defer d.Stop(t)
162
+	client, err := d.NewClient()
163
+	assert.NilError(t, err)
164
+
165
+	_, err = client.NetworkCreate(context.Background(), "dm-internal", types.NetworkCreate{
166
+		Driver:   "macvlan",
167
+		Internal: true,
168
+	})
169
+	assert.NilError(t, err)
170
+	assert.Check(t, isNetworkAvailable(client, "dm-internal"))
171
+
172
+	ctx := context.Background()
173
+	id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"), container.WithName(t.Name()+"first"))
174
+	id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"), container.WithName(t.Name()+"second"))
175
+
176
+	timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
177
+	defer cancel()
178
+	_, err = container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
179
+	// FIXME(vdemeester) check the time of error ?
180
+	assert.Check(t, err != nil)
181
+	assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded)
182
+
183
+	_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", t.Name() + "first"})
184
+	assert.Check(t, err == nil)
185
+}
186
+
187
+func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
188
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
189
+	skip.If(t, testEnv.IsRemoteDaemon())
190
+	skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
191
+	t.Skip("Temporarily skipping while investigating sporadic v6 CI issues")
192
+
193
+	d := daemon.New(t, "", "dockerd", daemon.Config{})
194
+	d.StartWithBusybox(t)
195
+	defer d.Stop(t)
196
+	client, err := d.NewClient()
197
+	assert.NilError(t, err)
198
+
199
+	_, err = client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
200
+		Driver:     "macvlan",
201
+		EnableIPv6: true,
202
+		IPAM: &network.IPAM{
203
+			Config: []network.IPAMConfig{
204
+				{
205
+					Subnet:     "172.28.100.0/24",
206
+					AuxAddress: map[string]string{},
207
+				},
208
+				{
209
+					Subnet:     "172.28.102.0/24",
210
+					Gateway:    "172.28.102.54",
211
+					AuxAddress: map[string]string{},
212
+				},
213
+				{
214
+					Subnet:     "2001:db8:abc2::/64",
215
+					AuxAddress: map[string]string{},
216
+				},
217
+				{
218
+					Subnet:     "2001:db8:abc4::/64",
219
+					Gateway:    "2001:db8:abc4::254",
220
+					AuxAddress: map[string]string{},
221
+				},
222
+			},
223
+		},
224
+	})
225
+	assert.NilError(t, err)
226
+	assert.Check(t, isNetworkAvailable(client, "dualstackbridge"))
227
+
228
+	// start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.100.0/24 and 2001:db8:abc2::/64
229
+	ctx := context.Background()
230
+	id1 := container.Run(t, ctx, client,
231
+		container.WithNetworkMode("dualstackbridge"),
232
+		container.WithName(t.Name()+"first"),
233
+		container.WithIPv4("dualstackbridge", "172.28.100.20"),
234
+		container.WithIPv6("dualstackbridge", "2001:db8:abc2::20"),
235
+	)
236
+	id2 := container.Run(t, ctx, client,
237
+		container.WithNetworkMode("dualstackbridge"),
238
+		container.WithName(t.Name()+"second"),
239
+		container.WithIPv4("dualstackbridge", "172.28.100.21"),
240
+		container.WithIPv6("dualstackbridge", "2001:db8:abc2::21"),
241
+	)
242
+	c1, err := client.ContainerInspect(ctx, id1)
243
+	assert.NilError(t, err)
244
+
245
+	// verify ipv4 connectivity to the explicit --ipv address second to first
246
+	_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", c1.NetworkSettings.Networks["dualstackbridge"].IPAddress})
247
+	assert.NilError(t, err)
248
+	// verify ipv6 connectivity to the explicit --ipv6 address second to first
249
+	_, err = container.Exec(ctx, client, id2, []string{"ping6", "-c", "1", c1.NetworkSettings.Networks["dualstackbridge"].GlobalIPv6Address})
250
+	assert.NilError(t, err)
251
+
252
+	// start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.102.0/24 and 2001:db8:abc4::/64
253
+	id3 := container.Run(t, ctx, client,
254
+		container.WithNetworkMode("dualstackbridge"),
255
+		container.WithName(t.Name()+"third"),
256
+		container.WithIPv4("dualstackbridge", "172.28.102.20"),
257
+		container.WithIPv6("dualstackbridge", "2001:db8:abc4::20"),
258
+	)
259
+	id4 := container.Run(t, ctx, client,
260
+		container.WithNetworkMode("dualstackbridge"),
261
+		container.WithName(t.Name()+"fourth"),
262
+		container.WithIPv4("dualstackbridge", "172.28.102.21"),
263
+		container.WithIPv6("dualstackbridge", "2001:db8:abc4::21"),
264
+	)
265
+	c3, err := client.ContainerInspect(ctx, id3)
266
+	assert.NilError(t, err)
267
+
268
+	// verify ipv4 connectivity to the explicit --ipv address from third to fourth
269
+	_, err = container.Exec(ctx, client, id4, []string{"ping", "-c", "1", c3.NetworkSettings.Networks["dualstackbridge"].IPAddress})
270
+	assert.NilError(t, err)
271
+	// verify ipv6 connectivity to the explicit --ipv6 address from third to fourth
272
+	_, err = container.Exec(ctx, client, id4, []string{"ping6", "-c", "1", c3.NetworkSettings.Networks["dualstackbridge"].GlobalIPv6Address})
273
+	assert.NilError(t, err)
274
+
275
+	// Inspect the v4 gateway to ensure the proper default GW was assigned
276
+	assert.Equal(t, c1.NetworkSettings.Networks["dualstackbridge"].Gateway, "172.28.100.1")
277
+	// Inspect the v6 gateway to ensure the proper default GW was assigned
278
+	assert.Equal(t, c1.NetworkSettings.Networks["dualstackbridge"].IPv6Gateway, "2001:db8:abc2::1")
279
+	// Inspect the v4 gateway to ensure the proper explicitly assigned default GW was assigned
280
+	assert.Equal(t, c3.NetworkSettings.Networks["dualstackbridge"].Gateway, "172.28.102.254")
281
+	// Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned
282
+	assert.Equal(t, c3.NetworkSettings.Networks["dualstackbridge"].IPv6Gateway, "2001:db8.abc4::254")
283
+}
284
+
285
+func isNetworkAvailable(c client.NetworkAPIClient, name string) cmp.Comparison {
286
+	return func() cmp.Result {
287
+		networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{})
288
+		if err != nil {
289
+			return cmp.ResultFromError(err)
290
+		}
291
+		for _, network := range networks {
292
+			if network.Name == name {
293
+				return cmp.ResultSuccess
294
+			}
295
+		}
296
+		return cmp.ResultFailure(fmt.Sprintf("could not find network %s", name))
297
+	}
298
+}
299
+
300
+func isNetworkNotAvailable(c client.NetworkAPIClient, name string) cmp.Comparison {
301
+	return func() cmp.Result {
302
+		networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{})
303
+		if err != nil {
304
+			return cmp.ResultFromError(err)
305
+		}
306
+		for _, network := range networks {
307
+			if network.Name == name {
308
+				return cmp.ResultFailure(fmt.Sprintf("network %s is still present", name))
309
+			}
310
+		}
311
+		return cmp.ResultSuccess
312
+	}
313
+}
314
+
315
+func createMasterDummy(t *testing.T, master string) {
316
+	// ip link add <dummy_name> type dummy
317
+	icmd.RunCommand("ip", "link", "add", master, "type", "dummy").Assert(t, icmd.Success)
318
+	icmd.RunCommand("ip", "link", "set", master, "up").Assert(t, icmd.Success)
319
+}
320
+
321
+func createVlanInterface(t *testing.T, master, slave, id string) {
322
+	// ip link add link <master> name <master>.<VID> type vlan id <VID>
323
+	icmd.RunCommand("ip", "link", "add", "link", master, "name", slave, "type", "vlan", "id", id).Assert(t, icmd.Success)
324
+	// ip link set <sub_interface_name> up
325
+	icmd.RunCommand("ip", "link", "set", slave, "up").Assert(t, icmd.Success)
326
+}
327
+
328
+func deleteInterface(t *testing.T, ifName string) {
329
+	icmd.RunCommand("ip", "link", "delete", ifName).Assert(t, icmd.Success)
330
+	icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(t, icmd.Success)
331
+	icmd.RunCommand("iptables", "--flush").Assert(t, icmd.Success)
332
+}
333
+
334
+func linkExists(t *testing.T, master string) {
335
+	// verify the specified link exists, ip link show <link_name>
336
+	icmd.RunCommand("ip", "link", "show", master).Assert(t, icmd.Success)
337
+}
338
+
339
+// ensure Kernel version is >= v3.9 for macvlan support
340
+func macvlanKernelSupport() bool {
341
+	return checkKernelMajorVersionGreaterOrEqualThen(3, 9)
342
+}
343
+
344
+func checkKernelMajorVersionGreaterOrEqualThen(kernelVersion int, majorVersion int) bool {
345
+	kv, err := kernel.GetKernelVersion()
346
+	if err != nil {
347
+		return false
348
+	}
349
+	if kv.Kernel < kernelVersion || (kv.Kernel == kernelVersion && kv.Major < majorVersion) {
350
+		return false
351
+	}
352
+	return true
353
+}