Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
| ... | ... |
@@ -7,9 +7,9 @@ import ( |
| 7 | 7 |
"time" |
| 8 | 8 |
|
| 9 | 9 |
"github.com/docker/docker/api/types" |
| 10 |
- "github.com/docker/docker/api/types/network" |
|
| 11 | 10 |
"github.com/docker/docker/client" |
| 12 | 11 |
"github.com/docker/docker/integration/internal/container" |
| 12 |
+ net "github.com/docker/docker/integration/internal/network" |
|
| 13 | 13 |
n "github.com/docker/docker/integration/network" |
| 14 | 14 |
"github.com/docker/docker/internal/test/daemon" |
| 15 | 15 |
"github.com/gotestyourself/gotestyourself/assert" |
| ... | ... |
@@ -33,16 +33,13 @@ func TestDockerNetworkMacvlanPersistance(t *testing.T) {
|
| 33 | 33 |
client, err := d.NewClient() |
| 34 | 34 |
assert.NilError(t, err) |
| 35 | 35 |
|
| 36 |
- _, err = client.NetworkCreate(context.Background(), "dm-persist", types.NetworkCreate{
|
|
| 37 |
- Driver: "macvlan", |
|
| 38 |
- Options: map[string]string{
|
|
| 39 |
- "parent": "dm-dummy0.60", |
|
| 40 |
- }, |
|
| 41 |
- }) |
|
| 42 |
- assert.NilError(t, err) |
|
| 43 |
- assert.Check(t, n.IsNetworkAvailable(client, "dm-persist")) |
|
| 36 |
+ netName := "dm-persist" |
|
| 37 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 38 |
+ net.WithMacvlan("dm-dummy0.60"),
|
|
| 39 |
+ ) |
|
| 40 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 44 | 41 |
d.Restart(t) |
| 45 |
- assert.Check(t, n.IsNetworkAvailable(client, "dm-persist")) |
|
| 42 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 46 | 43 |
} |
| 47 | 44 |
|
| 48 | 45 |
func TestDockerNetworkMacvlan(t *testing.T) {
|
| ... | ... |
@@ -91,29 +88,25 @@ func testMacvlanOverlapParent(client client.APIClient) func(*testing.T) {
|
| 91 | 91 |
n.CreateMasterDummy(t, master) |
| 92 | 92 |
defer n.DeleteInterface(t, master) |
| 93 | 93 |
|
| 94 |
- _, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
|
|
| 95 |
- Driver: "macvlan", |
|
| 96 |
- Options: map[string]string{
|
|
| 97 |
- "parent": "dm-dummy0.40", |
|
| 98 |
- }, |
|
| 99 |
- }) |
|
| 100 |
- assert.NilError(t, err) |
|
| 101 |
- assert.Check(t, n.IsNetworkAvailable(client, "dm-subinterface")) |
|
| 94 |
+ netName := "dm-subinterface" |
|
| 95 |
+ parentName := "dm-dummy0.40" |
|
| 96 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 97 |
+ net.WithMacvlan(parentName), |
|
| 98 |
+ ) |
|
| 99 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 102 | 100 |
|
| 103 |
- _, err = client.NetworkCreate(context.Background(), "dm-parent-net-overlap", types.NetworkCreate{
|
|
| 104 |
- Driver: "macvlan", |
|
| 105 |
- Options: map[string]string{
|
|
| 106 |
- "parent": "dm-dummy0.40", |
|
| 107 |
- }, |
|
| 108 |
- }) |
|
| 101 |
+ _, err := net.Create(context.Background(), client, "dm-parent-net-overlap", |
|
| 102 |
+ net.WithMacvlan(parentName), |
|
| 103 |
+ ) |
|
| 109 | 104 |
assert.Check(t, err != nil) |
| 105 |
+ |
|
| 110 | 106 |
// delete the network while preserving the parent link |
| 111 |
- err = client.NetworkRemove(context.Background(), "dm-subinterface") |
|
| 107 |
+ err = client.NetworkRemove(context.Background(), netName) |
|
| 112 | 108 |
assert.NilError(t, err) |
| 113 | 109 |
|
| 114 |
- assert.Check(t, n.IsNetworkNotAvailable(client, "dm-subinterface")) |
|
| 110 |
+ assert.Check(t, n.IsNetworkNotAvailable(client, netName)) |
|
| 115 | 111 |
// verify the network delete did not delete the predefined link |
| 116 |
- n.LinkExists(t, "dm-dummy0") |
|
| 112 |
+ n.LinkExists(t, master) |
|
| 117 | 113 |
} |
| 118 | 114 |
} |
| 119 | 115 |
|
| ... | ... |
@@ -121,26 +114,24 @@ func testMacvlanSubinterface(client client.APIClient) func(*testing.T) {
|
| 121 | 121 |
return func(t *testing.T) {
|
| 122 | 122 |
// verify the same parent interface cannot be used if already in use by an existing network |
| 123 | 123 |
master := "dm-dummy0" |
| 124 |
+ parentName := "dm-dummy0.20" |
|
| 124 | 125 |
n.CreateMasterDummy(t, master) |
| 125 | 126 |
defer n.DeleteInterface(t, master) |
| 126 |
- n.CreateVlanInterface(t, master, "dm-dummy0.20", "20") |
|
| 127 |
+ n.CreateVlanInterface(t, master, parentName, "20") |
|
| 127 | 128 |
|
| 128 |
- _, err := client.NetworkCreate(context.Background(), "dm-subinterface", types.NetworkCreate{
|
|
| 129 |
- Driver: "macvlan", |
|
| 130 |
- Options: map[string]string{
|
|
| 131 |
- "parent": "dm-dummy0.20", |
|
| 132 |
- }, |
|
| 133 |
- }) |
|
| 134 |
- assert.NilError(t, err) |
|
| 135 |
- assert.Check(t, n.IsNetworkAvailable(client, "dm-subinterface")) |
|
| 129 |
+ netName := "dm-subinterface" |
|
| 130 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 131 |
+ net.WithMacvlan(parentName), |
|
| 132 |
+ ) |
|
| 133 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 136 | 134 |
|
| 137 | 135 |
// delete the network while preserving the parent link |
| 138 |
- err = client.NetworkRemove(context.Background(), "dm-subinterface") |
|
| 136 |
+ err := client.NetworkRemove(context.Background(), netName) |
|
| 139 | 137 |
assert.NilError(t, err) |
| 140 | 138 |
|
| 141 |
- assert.Check(t, n.IsNetworkNotAvailable(client, "dm-subinterface")) |
|
| 139 |
+ assert.Check(t, n.IsNetworkNotAvailable(client, netName)) |
|
| 142 | 140 |
// verify the network delete did not delete the predefined link |
| 143 |
- n.LinkExists(t, "dm-dummy0.20") |
|
| 141 |
+ n.LinkExists(t, parentName) |
|
| 144 | 142 |
} |
| 145 | 143 |
} |
| 146 | 144 |
|
| ... | ... |
@@ -190,34 +181,17 @@ func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
|
| 190 | 190 |
|
| 191 | 191 |
func testMacvlanMultiSubnet(client client.APIClient) func(*testing.T) {
|
| 192 | 192 |
return func(t *testing.T) {
|
| 193 |
- _, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
|
|
| 194 |
- Driver: "macvlan", |
|
| 195 |
- EnableIPv6: true, |
|
| 196 |
- IPAM: &network.IPAM{
|
|
| 197 |
- Config: []network.IPAMConfig{
|
|
| 198 |
- {
|
|
| 199 |
- Subnet: "172.28.100.0/24", |
|
| 200 |
- AuxAddress: map[string]string{},
|
|
| 201 |
- }, |
|
| 202 |
- {
|
|
| 203 |
- Subnet: "172.28.102.0/24", |
|
| 204 |
- Gateway: "172.28.102.254", |
|
| 205 |
- AuxAddress: map[string]string{},
|
|
| 206 |
- }, |
|
| 207 |
- {
|
|
| 208 |
- Subnet: "2001:db8:abc2::/64", |
|
| 209 |
- AuxAddress: map[string]string{},
|
|
| 210 |
- }, |
|
| 211 |
- {
|
|
| 212 |
- Subnet: "2001:db8:abc4::/64", |
|
| 213 |
- Gateway: "2001:db8:abc4::254", |
|
| 214 |
- AuxAddress: map[string]string{},
|
|
| 215 |
- }, |
|
| 216 |
- }, |
|
| 217 |
- }, |
|
| 218 |
- }) |
|
| 219 |
- assert.NilError(t, err) |
|
| 220 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackbridge")) |
|
| 193 |
+ netName := "dualstackbridge" |
|
| 194 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 195 |
+ net.WithMacvlan(""),
|
|
| 196 |
+ net.WithIPv6(), |
|
| 197 |
+ net.WithIPAM("172.28.100.0/24", ""),
|
|
| 198 |
+ net.WithIPAM("172.28.102.0/24", "172.28.102.254"),
|
|
| 199 |
+ net.WithIPAM("2001:db8:abc2::/64", ""),
|
|
| 200 |
+ net.WithIPAM("2001:db8:abc4::/64", "2001:db8:abc4::254"),
|
|
| 201 |
+ ) |
|
| 202 |
+ |
|
| 203 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 221 | 204 |
|
| 222 | 205 |
// 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 |
| 223 | 206 |
ctx := context.Background() |
| ... | ... |
@@ -276,28 +250,15 @@ func testMacvlanMultiSubnet(client client.APIClient) func(*testing.T) {
|
| 276 | 276 |
func testMacvlanAddressing(client client.APIClient) func(*testing.T) {
|
| 277 | 277 |
return func(t *testing.T) {
|
| 278 | 278 |
// Ensure the default gateways, next-hops and default dev devices are properly set |
| 279 |
- _, err := client.NetworkCreate(context.Background(), "dualstackbridge", types.NetworkCreate{
|
|
| 280 |
- Driver: "macvlan", |
|
| 281 |
- EnableIPv6: true, |
|
| 282 |
- Options: map[string]string{
|
|
| 283 |
- "macvlan_mode": "bridge", |
|
| 284 |
- }, |
|
| 285 |
- IPAM: &network.IPAM{
|
|
| 286 |
- Config: []network.IPAMConfig{
|
|
| 287 |
- {
|
|
| 288 |
- Subnet: "172.28.130.0/24", |
|
| 289 |
- AuxAddress: map[string]string{},
|
|
| 290 |
- }, |
|
| 291 |
- {
|
|
| 292 |
- Subnet: "2001:db8:abca::/64", |
|
| 293 |
- Gateway: "2001:db8:abca::254", |
|
| 294 |
- AuxAddress: map[string]string{},
|
|
| 295 |
- }, |
|
| 296 |
- }, |
|
| 297 |
- }, |
|
| 298 |
- }) |
|
| 299 |
- assert.NilError(t, err) |
|
| 300 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackbridge")) |
|
| 279 |
+ netName := "dualstackbridge" |
|
| 280 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 281 |
+ net.WithMacvlan(""),
|
|
| 282 |
+ net.WithIPv6(), |
|
| 283 |
+ net.WithOption("macvlan_mode", "bridge"),
|
|
| 284 |
+ net.WithIPAM("172.28.130.0/24", ""),
|
|
| 285 |
+ net.WithIPAM("2001:db8:abca::/64", "2001:db8:abca::254"),
|
|
| 286 |
+ ) |
|
| 287 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 301 | 288 |
|
| 302 | 289 |
ctx := context.Background() |
| 303 | 290 |
id1 := container.Run(t, ctx, client, |