Skip to content

Commit

Permalink
refactored integration tests under integration/network/macvlan to use…
Browse files Browse the repository at this point in the history
… network.Create

Signed-off-by: Arash Deshmeh <[email protected]>
  • Loading branch information
adshmh committed Jun 5, 2018
1 parent 0e3012c commit 0418893
Showing 1 changed file with 50 additions and 89 deletions.
139 changes: 50 additions & 89 deletions integration/network/macvlan/macvlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/container"
net "github.com/docker/docker/integration/internal/network"
n "github.com/docker/docker/integration/network"
"github.com/docker/docker/internal/test/daemon"
"github.com/gotestyourself/gotestyourself/assert"
Expand All @@ -33,16 +33,13 @@ func TestDockerNetworkMacvlanPersistance(t *testing.T) {
client, err := d.NewClient()
assert.NilError(t, err)

_, err = client.NetworkCreate(context.Background(), "dm-persist", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.60",
},
})
assert.NilError(t, err)
assert.Check(t, n.IsNetworkAvailable(client, "dm-persist"))
netName := "dm-persist"
net.CreateNoError(t, context.Background(), client, netName,
net.WithMacvlan("dm-dummy0.60"),
)
assert.Check(t, n.IsNetworkAvailable(client, netName))
d.Restart(t)
assert.Check(t, n.IsNetworkAvailable(client, "dm-persist"))
assert.Check(t, n.IsNetworkAvailable(client, netName))
}

func TestDockerNetworkMacvlan(t *testing.T) {
Expand Down Expand Up @@ -91,56 +88,50 @@ func testMacvlanOverlapParent(client client.APIClient) func(*testing.T) {
n.CreateMasterDummy(t, master)
defer n.DeleteInterface(t, master)

_, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.40",
},
})
assert.NilError(t, err)
assert.Check(t, n.IsNetworkAvailable(client, "dm-subinterface"))
netName := "dm-subinterface"
parentName := "dm-dummy0.40"
net.CreateNoError(t, context.Background(), client, netName,
net.WithMacvlan(parentName),
)
assert.Check(t, n.IsNetworkAvailable(client, netName))

_, err = client.NetworkCreate(context.Background(), "dm-parent-net-overlap", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.40",
},
})
_, err := net.Create(context.Background(), client, "dm-parent-net-overlap",
net.WithMacvlan(parentName),
)
assert.Check(t, err != nil)

// delete the network while preserving the parent link
err = client.NetworkRemove(context.Background(), "dm-subinterface")
err = client.NetworkRemove(context.Background(), netName)
assert.NilError(t, err)

assert.Check(t, n.IsNetworkNotAvailable(client, "dm-subinterface"))
assert.Check(t, n.IsNetworkNotAvailable(client, netName))
// verify the network delete did not delete the predefined link
n.LinkExists(t, "dm-dummy0")
n.LinkExists(t, master)
}
}

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
master := "dm-dummy0"
parentName := "dm-dummy0.20"
n.CreateMasterDummy(t, master)
defer n.DeleteInterface(t, master)
n.CreateVlanInterface(t, master, "dm-dummy0.20", "20")
n.CreateVlanInterface(t, master, parentName, "20")

_, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
Driver: "macvlan",
Options: map[string]string{
"parent": "dm-dummy0.20",
},
})
assert.NilError(t, err)
assert.Check(t, n.IsNetworkAvailable(client, "dm-subinterface"))
netName := "dm-subinterface"
net.CreateNoError(t, context.Background(), client, netName,
net.WithMacvlan(parentName),
)
assert.Check(t, n.IsNetworkAvailable(client, netName))

// delete the network while preserving the parent link
err = client.NetworkRemove(context.Background(), "dm-subinterface")
err := client.NetworkRemove(context.Background(), netName)
assert.NilError(t, err)

assert.Check(t, n.IsNetworkNotAvailable(client, "dm-subinterface"))
assert.Check(t, n.IsNetworkNotAvailable(client, netName))
// verify the network delete did not delete the predefined link
n.LinkExists(t, "dm-dummy0.20")
n.LinkExists(t, parentName)
}
}

Expand Down Expand Up @@ -190,34 +181,17 @@ func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {

func testMacvlanMultiSubnet(client client.APIClient) func(*testing.T) {
return func(t *testing.T) {
_, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
Driver: "macvlan",
EnableIPv6: true,
IPAM: &network.IPAM{
Config: []network.IPAMConfig{
{
Subnet: "172.28.100.0/24",
AuxAddress: map[string]string{},
},
{
Subnet: "172.28.102.0/24",
Gateway: "172.28.102.254",
AuxAddress: map[string]string{},
},
{
Subnet: "2001:db8:abc2::/64",
AuxAddress: map[string]string{},
},
{
Subnet: "2001:db8:abc4::/64",
Gateway: "2001:db8:abc4::254",
AuxAddress: map[string]string{},
},
},
},
})
assert.NilError(t, err)
assert.Check(t, n.IsNetworkAvailable(client, "dualstackbridge"))
netName := "dualstackbridge"
net.CreateNoError(t, context.Background(), client, netName,
net.WithMacvlan(""),
net.WithIPv6(),
net.WithIPAM("172.28.100.0/24", ""),
net.WithIPAM("172.28.102.0/24", "172.28.102.254"),
net.WithIPAM("2001:db8:abc2::/64", ""),
net.WithIPAM("2001:db8:abc4::/64", "2001:db8:abc4::254"),
)

assert.Check(t, n.IsNetworkAvailable(client, netName))

// 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
ctx := context.Background()
Expand Down Expand Up @@ -276,28 +250,15 @@ func testMacvlanMultiSubnet(client client.APIClient) func(*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
_, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
Driver: "macvlan",
EnableIPv6: true,
Options: map[string]string{
"macvlan_mode": "bridge",
},
IPAM: &network.IPAM{
Config: []network.IPAMConfig{
{
Subnet: "172.28.130.0/24",
AuxAddress: map[string]string{},
},
{
Subnet: "2001:db8:abca::/64",
Gateway: "2001:db8:abca::254",
AuxAddress: map[string]string{},
},
},
},
})
assert.NilError(t, err)
assert.Check(t, n.IsNetworkAvailable(client, "dualstackbridge"))
netName := "dualstackbridge"
net.CreateNoError(t, context.Background(), client, netName,
net.WithMacvlan(""),
net.WithIPv6(),
net.WithOption("macvlan_mode", "bridge"),
net.WithIPAM("172.28.130.0/24", ""),
net.WithIPAM("2001:db8:abca::/64", "2001:db8:abca::254"),
)
assert.Check(t, n.IsNetworkAvailable(client, netName))

ctx := context.Background()
id1 := container.Run(t, ctx, client,
Expand Down

0 comments on commit 0418893

Please sign in to comment.