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

Refactor macvlan tests a bit

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-04-11 11:14:54 +02:00
parent 24f9347511
commit 0ab6116ce8
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3

View file

@ -48,24 +48,53 @@ func TestDockerNetworkMacvlanPersistance(t *testing.T) {
assert.Check(t, isNetworkAvailable(client, "dm-persist"))
}
func TestDockerNetworkMacvlanOverlapParent(t *testing.T) {
// verify the same parent interface cannot be used if already in use by an existing network
func TestDockerNetworkMacvlan(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
for _, tc := range []struct {
name string
test func(client.APIClient) func(*testing.T)
}{
{
name: "Subinterface",
test: testMacvlanSubinterface,
}, {
name: "OverlapParent",
test: testMacvlanOverlapParent,
}, {
name: "NilParent",
test: testMacvlanNilParent,
}, {
name: "InternalMode",
test: testMacvlanInternalMode,
}, {
name: "Addressing",
test: testMacvlanAddressing,
},
} {
d := daemon.New(t)
d.StartWithBusybox(t)
defer d.Stop(t)
master := "dm-dummy0"
createMasterDummy(t, master)
defer deleteInterface(t, master)
client, err := d.NewClient()
assert.NilError(t, err)
_, err = client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
t.Run(tc.name, tc.test(client))
d.Stop(t)
// FIXME(vdemeester) clean network
}
}
func testMacvlanOverlapParent(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// verify the same parent interface cannot be used if already in use by an existing network
master := "dm-dummy0"
createMasterDummy(t, master)
defer deleteInterface(t, master)
_, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.40",
@ -89,26 +118,17 @@ func TestDockerNetworkMacvlanOverlapParent(t *testing.T) {
// verify the network delete did not delete the predefined link
linkExists(t, "dm-dummy0")
}
}
func TestDockerNetworkMacvlanSubinterface(t *testing.T) {
func testMacvlanSubinterface(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// verify the same parent interface cannot be used if already in use by an existing network
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
d := daemon.New(t)
d.StartWithBusybox(t)
defer d.Stop(t)
master := "dm-dummy0"
createMasterDummy(t, master)
defer deleteInterface(t, master)
createVlanInterface(t, master, "dm-dummy0.20", "20")
client, err := d.NewClient()
assert.NilError(t, err)
_, err = client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
_, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.20",
@ -125,48 +145,30 @@ func TestDockerNetworkMacvlanSubinterface(t *testing.T) {
// verify the network delete did not delete the predefined link
linkExists(t, "dm-dummy0.20")
}
}
func TestDockerNetworkMacvlanBridgeNilParent(t *testing.T) {
func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// macvlan bridge mode - dummy parent interface is provisioned dynamically
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
d := daemon.New(t)
d.StartWithBusybox(t)
defer d.Stop(t)
client, err := d.NewClient()
assert.NilError(t, err)
_, err = client.NetworkCreate(context.Background(), "dm-nil-parent", types.NetworkCreate{
_, err := client.NetworkCreate(context.Background(), "dm-nil-parent", types.NetworkCreate{
Driver: "macvlan",
})
assert.NilError(t, err)
assert.Check(t, isNetworkAvailable(client, "dm-nil-parent"))
ctx := context.Background()
container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"), container.WithName(t.Name()+"first"))
id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"), container.WithName(t.Name()+"second"))
id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", t.Name() + "first"})
_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
assert.Check(t, err == nil)
}
}
func TestDockerNetworkMacvlanBridgeInternal(t *testing.T) {
func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// macvlan bridge mode - dummy parent interface is provisioned dynamically
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
d := daemon.New(t)
d.StartWithBusybox(t)
defer d.Stop(t)
client, err := d.NewClient()
assert.NilError(t, err)
t.Log(icmd.RunCommand("ip", "addr").Combined())
_, err = client.NetworkCreate(context.Background(), "dm-internal", types.NetworkCreate{
_, err := client.NetworkCreate(context.Background(), "dm-internal", types.NetworkCreate{
Driver: "macvlan",
Internal: true,
})
@ -174,8 +176,8 @@ func TestDockerNetworkMacvlanBridgeInternal(t *testing.T) {
assert.Check(t, isNetworkAvailable(client, "dm-internal"))
ctx := context.Background()
id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"), container.WithName(t.Name()+"first"))
id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"), container.WithName(t.Name()+"second"))
id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
@ -184,23 +186,15 @@ func TestDockerNetworkMacvlanBridgeInternal(t *testing.T) {
assert.Check(t, err != nil)
assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded)
_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", t.Name() + "first"})
_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
assert.Check(t, err == nil)
}
}
func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
func testMacvlanMultiSubnet(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// t.Skip("Temporarily skipping while investigating sporadic v6 CI issues")
d := daemon.New(t)
d.StartWithBusybox(t)
defer d.Stop(t)
client, err := d.NewClient()
assert.NilError(t, err)
_, err = client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
_, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
Driver: "macvlan",
EnableIPv6: true,
IPAM: &network.IPAM{
@ -211,7 +205,7 @@ func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
},
{
Subnet: "172.28.102.0/24",
Gateway: "172.28.102.54",
Gateway: "172.28.102.254",
AuxAddress: map[string]string{},
},
{
@ -233,13 +227,11 @@ func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
ctx := context.Background()
id1 := container.Run(t, ctx, client,
container.WithNetworkMode("dualstackbridge"),
container.WithName(t.Name()+"first"),
container.WithIPv4("dualstackbridge", "172.28.100.20"),
container.WithIPv6("dualstackbridge", "2001:db8:abc2::20"),
)
id2 := container.Run(t, ctx, client,
container.WithNetworkMode("dualstackbridge"),
container.WithName(t.Name()+"second"),
container.WithIPv4("dualstackbridge", "172.28.100.21"),
container.WithIPv6("dualstackbridge", "2001:db8:abc2::21"),
)
@ -256,13 +248,11 @@ func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
// 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
id3 := container.Run(t, ctx, client,
container.WithNetworkMode("dualstackbridge"),
container.WithName(t.Name()+"third"),
container.WithIPv4("dualstackbridge", "172.28.102.20"),
container.WithIPv6("dualstackbridge", "2001:db8:abc4::20"),
)
id4 := container.Run(t, ctx, client,
container.WithNetworkMode("dualstackbridge"),
container.WithName(t.Name()+"fourth"),
container.WithIPv4("dualstackbridge", "172.28.102.21"),
container.WithIPv6("dualstackbridge", "2001:db8:abc4::21"),
)
@ -285,19 +275,12 @@ func TestDockerNetworkMacvlanMultiSubnet(t *testing.T) {
// Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned
assert.Equal(t, c3.NetworkSettings.Networks["dualstackbridge"].IPv6Gateway, "2001:db8.abc4::254")
}
}
func TestDockerNetworkMacvlanAddressing(t *testing.T) {
func testMacvlanAddressing(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
// Ensure the default gateways, next-hops and default dev devices are properly set
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
skip.If(t, !macvlanKernelSupport(), "Kernel doesn't support macvlan")
d := daemon.New(t, "", "dockerd", daemon.Config{})
d.StartWithBusybox(t)
defer d.Stop(t)
client, err := d.NewClient()
assert.NilError(t, err)
_, err = client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
_, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
Driver: "macvlan",
EnableIPv6: true,
Options: map[string]string{
@ -323,7 +306,6 @@ func TestDockerNetworkMacvlanAddressing(t *testing.T) {
ctx := context.Background()
id1 := container.Run(t, ctx, client,
container.WithNetworkMode("dualstackbridge"),
container.WithName(t.Name()+"first"),
)
// Validate macvlan bridge mode defaults gateway sets the default IPAM next-hop inferred from the subnet
@ -335,6 +317,7 @@ func TestDockerNetworkMacvlanAddressing(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, strings.Contains(result.Combined(), "default via 2001:db8:abca::254 dev eth0"))
}
}
func isNetworkAvailable(c client.NetworkAPIClient, name string) cmp.Comparison {
return func() cmp.Result {