Refactor ipvlan network integration tests to use network package
| ... | ... |
@@ -26,6 +26,13 @@ func WithCheckDuplicate() func(*types.NetworkCreate) {
|
| 26 | 26 |
} |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 |
+// WithInternal sets the Internal flag on the network |
|
| 30 |
+func WithInternal() func(*types.NetworkCreate) {
|
|
| 31 |
+ return func(n *types.NetworkCreate) {
|
|
| 32 |
+ n.Internal = true |
|
| 33 |
+ } |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 29 | 36 |
// WithMacvlan sets the network as macvlan with the specified parent |
| 30 | 37 |
func WithMacvlan(parent string) func(*types.NetworkCreate) {
|
| 31 | 38 |
return func(n *types.NetworkCreate) {
|
| ... | ... |
@@ -38,6 +45,22 @@ func WithMacvlan(parent string) func(*types.NetworkCreate) {
|
| 38 | 38 |
} |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
+// WithIPvlan sets the network as ipvlan with the specified parent and mode |
|
| 42 |
+func WithIPvlan(parent, mode string) func(*types.NetworkCreate) {
|
|
| 43 |
+ return func(n *types.NetworkCreate) {
|
|
| 44 |
+ n.Driver = "ipvlan" |
|
| 45 |
+ if n.Options == nil {
|
|
| 46 |
+ n.Options = map[string]string{}
|
|
| 47 |
+ } |
|
| 48 |
+ if parent != "" {
|
|
| 49 |
+ n.Options["parent"] = parent |
|
| 50 |
+ } |
|
| 51 |
+ if mode != "" {
|
|
| 52 |
+ n.Options["ipvlan_mode"] = mode |
|
| 53 |
+ } |
|
| 54 |
+ } |
|
| 55 |
+} |
|
| 56 |
+ |
|
| 41 | 57 |
// WithOption adds the specified key/value pair to network's options |
| 42 | 58 |
func WithOption(key, value string) func(*types.NetworkCreate) {
|
| 43 | 59 |
return func(n *types.NetworkCreate) {
|
| ... | ... |
@@ -6,10 +6,9 @@ import ( |
| 6 | 6 |
"testing" |
| 7 | 7 |
"time" |
| 8 | 8 |
|
| 9 |
- "github.com/docker/docker/api/types" |
|
| 10 |
- "github.com/docker/docker/api/types/network" |
|
| 11 | 9 |
dclient "github.com/docker/docker/client" |
| 12 | 10 |
"github.com/docker/docker/integration/internal/container" |
| 11 |
+ net "github.com/docker/docker/integration/internal/network" |
|
| 13 | 12 |
n "github.com/docker/docker/integration/network" |
| 14 | 13 |
"github.com/docker/docker/internal/test/daemon" |
| 15 | 14 |
"gotest.tools/assert" |
| ... | ... |
@@ -35,17 +34,15 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) {
|
| 35 | 35 |
assert.NilError(t, err) |
| 36 | 36 |
|
| 37 | 37 |
// create a network specifying the desired sub-interface name |
| 38 |
- _, err = client.NetworkCreate(context.Background(), "di-persist", types.NetworkCreate{
|
|
| 39 |
- Driver: "ipvlan", |
|
| 40 |
- Options: map[string]string{
|
|
| 41 |
- "parent": "di-dummy0.70", |
|
| 42 |
- }, |
|
| 43 |
- }) |
|
| 44 |
- assert.NilError(t, err) |
|
| 45 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-persist")) |
|
| 38 |
+ netName := "di-persist" |
|
| 39 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 40 |
+ net.WithIPvlan("di-dummy0.70", ""),
|
|
| 41 |
+ ) |
|
| 42 |
+ |
|
| 43 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 46 | 44 |
// Restart docker daemon to test the config has persisted to disk |
| 47 | 45 |
d.Restart(t) |
| 48 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-persist")) |
|
| 46 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 49 | 47 |
} |
| 50 | 48 |
|
| 51 | 49 |
func TestDockerNetworkIpvlan(t *testing.T) {
|
| ... | ... |
@@ -105,20 +102,17 @@ func testIpvlanSubinterface(client dclient.APIClient) func(*testing.T) {
|
| 105 | 105 |
n.CreateMasterDummy(t, master) |
| 106 | 106 |
defer n.DeleteInterface(t, master) |
| 107 | 107 |
|
| 108 |
- _, err := client.NetworkCreate(context.Background(), "di-subinterface", types.NetworkCreate{
|
|
| 109 |
- Driver: "ipvlan", |
|
| 110 |
- Options: map[string]string{
|
|
| 111 |
- "parent": "di-dummy0.60", |
|
| 112 |
- }, |
|
| 113 |
- }) |
|
| 114 |
- assert.NilError(t, err) |
|
| 115 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-subinterface")) |
|
| 108 |
+ netName := "di-subinterface" |
|
| 109 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 110 |
+ net.WithIPvlan("di-dummy0.60", ""),
|
|
| 111 |
+ ) |
|
| 112 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 116 | 113 |
|
| 117 | 114 |
// delete the network while preserving the parent link |
| 118 |
- err = client.NetworkRemove(context.Background(), "di-subinterface") |
|
| 115 |
+ err := client.NetworkRemove(context.Background(), netName) |
|
| 119 | 116 |
assert.NilError(t, err) |
| 120 | 117 |
|
| 121 |
- assert.Check(t, n.IsNetworkNotAvailable(client, "di-subinterface")) |
|
| 118 |
+ assert.Check(t, n.IsNetworkNotAvailable(client, netName)) |
|
| 122 | 119 |
// verify the network delete did not delete the predefined link |
| 123 | 120 |
n.LinkExists(t, "di-dummy0") |
| 124 | 121 |
} |
| ... | ... |
@@ -128,25 +122,20 @@ func testIpvlanOverlapParent(client dclient.APIClient) func(*testing.T) {
|
| 128 | 128 |
return func(t *testing.T) {
|
| 129 | 129 |
// verify the same parent interface cannot be used if already in use by an existing network |
| 130 | 130 |
master := "di-dummy0" |
| 131 |
+ parent := master + ".30" |
|
| 131 | 132 |
n.CreateMasterDummy(t, master) |
| 132 | 133 |
defer n.DeleteInterface(t, master) |
| 133 |
- n.CreateVlanInterface(t, master, "di-dummy0.30", "30") |
|
| 134 |
- |
|
| 135 |
- _, err := client.NetworkCreate(context.Background(), "di-subinterface", types.NetworkCreate{
|
|
| 136 |
- Driver: "ipvlan", |
|
| 137 |
- Options: map[string]string{
|
|
| 138 |
- "parent": "di-dummy0.30", |
|
| 139 |
- }, |
|
| 140 |
- }) |
|
| 141 |
- assert.NilError(t, err) |
|
| 142 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-subinterface")) |
|
| 143 |
- |
|
| 144 |
- _, err = client.NetworkCreate(context.Background(), "di-subinterface", types.NetworkCreate{
|
|
| 145 |
- Driver: "ipvlan", |
|
| 146 |
- Options: map[string]string{
|
|
| 147 |
- "parent": "di-dummy0.30", |
|
| 148 |
- }, |
|
| 149 |
- }) |
|
| 134 |
+ n.CreateVlanInterface(t, master, parent, "30") |
|
| 135 |
+ |
|
| 136 |
+ netName := "di-subinterface" |
|
| 137 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 138 |
+ net.WithIPvlan(parent, ""), |
|
| 139 |
+ ) |
|
| 140 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 141 |
+ |
|
| 142 |
+ _, err := net.Create(context.Background(), client, netName, |
|
| 143 |
+ net.WithIPvlan(parent, ""), |
|
| 144 |
+ ) |
|
| 150 | 145 |
// verify that the overlap returns an error |
| 151 | 146 |
assert.Check(t, err != nil) |
| 152 | 147 |
} |
| ... | ... |
@@ -155,37 +144,37 @@ func testIpvlanOverlapParent(client dclient.APIClient) func(*testing.T) {
|
| 155 | 155 |
func testIpvlanL2NilParent(client dclient.APIClient) func(*testing.T) {
|
| 156 | 156 |
return func(t *testing.T) {
|
| 157 | 157 |
// ipvlan l2 mode - dummy parent interface is provisioned dynamically |
| 158 |
- _, err := client.NetworkCreate(context.Background(), "di-nil-parent", types.NetworkCreate{
|
|
| 159 |
- Driver: "ipvlan", |
|
| 160 |
- }) |
|
| 161 |
- assert.NilError(t, err) |
|
| 162 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-nil-parent")) |
|
| 158 |
+ netName := "di-nil-parent" |
|
| 159 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 160 |
+ net.WithIPvlan("", ""),
|
|
| 161 |
+ ) |
|
| 162 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 163 | 163 |
|
| 164 | 164 |
ctx := context.Background() |
| 165 |
- id1 := container.Run(t, ctx, client, container.WithNetworkMode("di-nil-parent"))
|
|
| 166 |
- id2 := container.Run(t, ctx, client, container.WithNetworkMode("di-nil-parent"))
|
|
| 165 |
+ id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName)) |
|
| 166 |
+ id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName)) |
|
| 167 | 167 |
|
| 168 |
- _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
|
|
| 168 |
+ _, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
|
|
| 169 | 169 |
assert.NilError(t, err) |
| 170 | 170 |
} |
| 171 | 171 |
} |
| 172 | 172 |
|
| 173 | 173 |
func testIpvlanL2InternalMode(client dclient.APIClient) func(*testing.T) {
|
| 174 | 174 |
return func(t *testing.T) {
|
| 175 |
- _, err := client.NetworkCreate(context.Background(), "di-internal", types.NetworkCreate{
|
|
| 176 |
- Driver: "ipvlan", |
|
| 177 |
- Internal: true, |
|
| 178 |
- }) |
|
| 179 |
- assert.NilError(t, err) |
|
| 180 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-internal")) |
|
| 175 |
+ netName := "di-internal" |
|
| 176 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 177 |
+ net.WithIPvlan("", ""),
|
|
| 178 |
+ net.WithInternal(), |
|
| 179 |
+ ) |
|
| 180 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 181 | 181 |
|
| 182 | 182 |
ctx := context.Background() |
| 183 |
- id1 := container.Run(t, ctx, client, container.WithNetworkMode("di-internal"))
|
|
| 184 |
- id2 := container.Run(t, ctx, client, container.WithNetworkMode("di-internal"))
|
|
| 183 |
+ id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName)) |
|
| 184 |
+ id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName)) |
|
| 185 | 185 |
|
| 186 | 186 |
timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 187 | 187 |
defer cancel() |
| 188 |
- _, err = container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
|
|
| 188 |
+ _, err := container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
|
|
| 189 | 189 |
// FIXME(vdemeester) check the time of error ? |
| 190 | 190 |
assert.Check(t, err != nil) |
| 191 | 191 |
assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded) |
| ... | ... |
@@ -197,79 +186,53 @@ func testIpvlanL2InternalMode(client dclient.APIClient) func(*testing.T) {
|
| 197 | 197 |
|
| 198 | 198 |
func testIpvlanL3NilParent(client dclient.APIClient) func(*testing.T) {
|
| 199 | 199 |
return func(t *testing.T) {
|
| 200 |
- _, err := client.NetworkCreate(context.Background(), "di-nil-parent-l3", types.NetworkCreate{
|
|
| 201 |
- Driver: "ipvlan", |
|
| 202 |
- Options: map[string]string{
|
|
| 203 |
- "ipvlan_mode": "l3", |
|
| 204 |
- }, |
|
| 205 |
- IPAM: &network.IPAM{
|
|
| 206 |
- Config: []network.IPAMConfig{
|
|
| 207 |
- {
|
|
| 208 |
- Subnet: "172.28.230.0/24", |
|
| 209 |
- AuxAddress: map[string]string{},
|
|
| 210 |
- }, |
|
| 211 |
- {
|
|
| 212 |
- Subnet: "172.28.220.0/24", |
|
| 213 |
- AuxAddress: map[string]string{},
|
|
| 214 |
- }, |
|
| 215 |
- }, |
|
| 216 |
- }, |
|
| 217 |
- }) |
|
| 218 |
- assert.NilError(t, err) |
|
| 219 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-nil-parent-l3")) |
|
| 200 |
+ netName := "di-nil-parent-l3" |
|
| 201 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 202 |
+ net.WithIPvlan("", "l3"),
|
|
| 203 |
+ net.WithIPAM("172.28.230.0/24", ""),
|
|
| 204 |
+ net.WithIPAM("172.28.220.0/24", ""),
|
|
| 205 |
+ ) |
|
| 206 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 220 | 207 |
|
| 221 | 208 |
ctx := context.Background() |
| 222 | 209 |
id1 := container.Run(t, ctx, client, |
| 223 |
- container.WithNetworkMode("di-nil-parent-l3"),
|
|
| 224 |
- container.WithIPv4("di-nil-parent-l3", "172.28.220.10"),
|
|
| 210 |
+ container.WithNetworkMode(netName), |
|
| 211 |
+ container.WithIPv4(netName, "172.28.220.10"), |
|
| 225 | 212 |
) |
| 226 | 213 |
id2 := container.Run(t, ctx, client, |
| 227 |
- container.WithNetworkMode("di-nil-parent-l3"),
|
|
| 228 |
- container.WithIPv4("di-nil-parent-l3", "172.28.230.10"),
|
|
| 214 |
+ container.WithNetworkMode(netName), |
|
| 215 |
+ container.WithIPv4(netName, "172.28.230.10"), |
|
| 229 | 216 |
) |
| 230 | 217 |
|
| 231 |
- _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
|
|
| 218 |
+ _, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
|
|
| 232 | 219 |
assert.NilError(t, err) |
| 233 | 220 |
} |
| 234 | 221 |
} |
| 235 | 222 |
|
| 236 | 223 |
func testIpvlanL3InternalMode(client dclient.APIClient) func(*testing.T) {
|
| 237 | 224 |
return func(t *testing.T) {
|
| 238 |
- _, err := client.NetworkCreate(context.Background(), "di-internal-l3", types.NetworkCreate{
|
|
| 239 |
- Driver: "ipvlan", |
|
| 240 |
- Internal: true, |
|
| 241 |
- Options: map[string]string{
|
|
| 242 |
- "ipvlan_mode": "l3", |
|
| 243 |
- }, |
|
| 244 |
- IPAM: &network.IPAM{
|
|
| 245 |
- Config: []network.IPAMConfig{
|
|
| 246 |
- {
|
|
| 247 |
- Subnet: "172.28.230.0/24", |
|
| 248 |
- AuxAddress: map[string]string{},
|
|
| 249 |
- }, |
|
| 250 |
- {
|
|
| 251 |
- Subnet: "172.28.220.0/24", |
|
| 252 |
- AuxAddress: map[string]string{},
|
|
| 253 |
- }, |
|
| 254 |
- }, |
|
| 255 |
- }, |
|
| 256 |
- }) |
|
| 257 |
- assert.NilError(t, err) |
|
| 258 |
- assert.Check(t, n.IsNetworkAvailable(client, "di-internal-l3")) |
|
| 225 |
+ netName := "di-internal-l3" |
|
| 226 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 227 |
+ net.WithIPvlan("", "l3"),
|
|
| 228 |
+ net.WithInternal(), |
|
| 229 |
+ net.WithIPAM("172.28.230.0/24", ""),
|
|
| 230 |
+ net.WithIPAM("172.28.220.0/24", ""),
|
|
| 231 |
+ ) |
|
| 232 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 259 | 233 |
|
| 260 | 234 |
ctx := context.Background() |
| 261 | 235 |
id1 := container.Run(t, ctx, client, |
| 262 |
- container.WithNetworkMode("di-internal-l3"),
|
|
| 263 |
- container.WithIPv4("di-internal-l3", "172.28.220.10"),
|
|
| 236 |
+ container.WithNetworkMode(netName), |
|
| 237 |
+ container.WithIPv4(netName, "172.28.220.10"), |
|
| 264 | 238 |
) |
| 265 | 239 |
id2 := container.Run(t, ctx, client, |
| 266 |
- container.WithNetworkMode("di-internal-l3"),
|
|
| 267 |
- container.WithIPv4("di-internal-l3", "172.28.230.10"),
|
|
| 240 |
+ container.WithNetworkMode(netName), |
|
| 241 |
+ container.WithIPv4(netName, "172.28.230.10"), |
|
| 268 | 242 |
) |
| 269 | 243 |
|
| 270 | 244 |
timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 271 | 245 |
defer cancel() |
| 272 |
- _, err = container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
|
|
| 246 |
+ _, err := container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
|
|
| 273 | 247 |
// FIXME(vdemeester) check the time of error ? |
| 274 | 248 |
assert.Check(t, err != nil) |
| 275 | 249 |
assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded) |
| ... | ... |
@@ -281,174 +244,135 @@ func testIpvlanL3InternalMode(client dclient.APIClient) func(*testing.T) {
|
| 281 | 281 |
|
| 282 | 282 |
func testIpvlanL2MultiSubnet(client dclient.APIClient) func(*testing.T) {
|
| 283 | 283 |
return func(t *testing.T) {
|
| 284 |
- _, err := client.NetworkCreate(context.Background(), "dualstackl2", types.NetworkCreate{
|
|
| 285 |
- Driver: "ipvlan", |
|
| 286 |
- EnableIPv6: true, |
|
| 287 |
- IPAM: &network.IPAM{
|
|
| 288 |
- Config: []network.IPAMConfig{
|
|
| 289 |
- {
|
|
| 290 |
- Subnet: "172.28.200.0/24", |
|
| 291 |
- AuxAddress: map[string]string{},
|
|
| 292 |
- }, |
|
| 293 |
- {
|
|
| 294 |
- Subnet: "172.28.202.0/24", |
|
| 295 |
- Gateway: "172.28.202.254", |
|
| 296 |
- AuxAddress: map[string]string{},
|
|
| 297 |
- }, |
|
| 298 |
- {
|
|
| 299 |
- Subnet: "2001:db8:abc8::/64", |
|
| 300 |
- AuxAddress: map[string]string{},
|
|
| 301 |
- }, |
|
| 302 |
- {
|
|
| 303 |
- Subnet: "2001:db8:abc6::/64", |
|
| 304 |
- Gateway: "2001:db8:abc6::254", |
|
| 305 |
- AuxAddress: map[string]string{},
|
|
| 306 |
- }, |
|
| 307 |
- }, |
|
| 308 |
- }, |
|
| 309 |
- }) |
|
| 310 |
- assert.NilError(t, err) |
|
| 311 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackl2")) |
|
| 284 |
+ netName := "dualstackl2" |
|
| 285 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 286 |
+ net.WithIPvlan("", ""),
|
|
| 287 |
+ net.WithIPv6(), |
|
| 288 |
+ net.WithIPAM("172.28.200.0/24", ""),
|
|
| 289 |
+ net.WithIPAM("172.28.202.0/24", "172.28.202.254"),
|
|
| 290 |
+ net.WithIPAM("2001:db8:abc8::/64", ""),
|
|
| 291 |
+ net.WithIPAM("2001:db8:abc6::/64", "2001:db8:abc6::254"),
|
|
| 292 |
+ ) |
|
| 293 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 312 | 294 |
|
| 313 | 295 |
// 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 |
| 314 | 296 |
ctx := context.Background() |
| 315 | 297 |
id1 := container.Run(t, ctx, client, |
| 316 |
- container.WithNetworkMode("dualstackl2"),
|
|
| 317 |
- container.WithIPv4("dualstackl2", "172.28.200.20"),
|
|
| 318 |
- container.WithIPv6("dualstackl2", "2001:db8:abc8::20"),
|
|
| 298 |
+ container.WithNetworkMode(netName), |
|
| 299 |
+ container.WithIPv4(netName, "172.28.200.20"), |
|
| 300 |
+ container.WithIPv6(netName, "2001:db8:abc8::20"), |
|
| 319 | 301 |
) |
| 320 | 302 |
id2 := container.Run(t, ctx, client, |
| 321 |
- container.WithNetworkMode("dualstackl2"),
|
|
| 322 |
- container.WithIPv4("dualstackl2", "172.28.200.21"),
|
|
| 323 |
- container.WithIPv6("dualstackl2", "2001:db8:abc8::21"),
|
|
| 303 |
+ container.WithNetworkMode(netName), |
|
| 304 |
+ container.WithIPv4(netName, "172.28.200.21"), |
|
| 305 |
+ container.WithIPv6(netName, "2001:db8:abc8::21"), |
|
| 324 | 306 |
) |
| 325 | 307 |
c1, err := client.ContainerInspect(ctx, id1) |
| 326 | 308 |
assert.NilError(t, err) |
| 327 | 309 |
|
| 328 | 310 |
// verify ipv4 connectivity to the explicit --ipv address second to first |
| 329 |
- _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", c1.NetworkSettings.Networks["dualstackl2"].IPAddress})
|
|
| 311 |
+ _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", c1.NetworkSettings.Networks[netName].IPAddress})
|
|
| 330 | 312 |
assert.NilError(t, err) |
| 331 | 313 |
// verify ipv6 connectivity to the explicit --ipv6 address second to first |
| 332 |
- _, err = container.Exec(ctx, client, id2, []string{"ping6", "-c", "1", c1.NetworkSettings.Networks["dualstackl2"].GlobalIPv6Address})
|
|
| 314 |
+ _, err = container.Exec(ctx, client, id2, []string{"ping6", "-c", "1", c1.NetworkSettings.Networks[netName].GlobalIPv6Address})
|
|
| 333 | 315 |
assert.NilError(t, err) |
| 334 | 316 |
|
| 335 | 317 |
// 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 |
| 336 | 318 |
id3 := container.Run(t, ctx, client, |
| 337 |
- container.WithNetworkMode("dualstackl2"),
|
|
| 338 |
- container.WithIPv4("dualstackl2", "172.28.202.20"),
|
|
| 339 |
- container.WithIPv6("dualstackl2", "2001:db8:abc6::20"),
|
|
| 319 |
+ container.WithNetworkMode(netName), |
|
| 320 |
+ container.WithIPv4(netName, "172.28.202.20"), |
|
| 321 |
+ container.WithIPv6(netName, "2001:db8:abc6::20"), |
|
| 340 | 322 |
) |
| 341 | 323 |
id4 := container.Run(t, ctx, client, |
| 342 |
- container.WithNetworkMode("dualstackl2"),
|
|
| 343 |
- container.WithIPv4("dualstackl2", "172.28.202.21"),
|
|
| 344 |
- container.WithIPv6("dualstackl2", "2001:db8:abc6::21"),
|
|
| 324 |
+ container.WithNetworkMode(netName), |
|
| 325 |
+ container.WithIPv4(netName, "172.28.202.21"), |
|
| 326 |
+ container.WithIPv6(netName, "2001:db8:abc6::21"), |
|
| 345 | 327 |
) |
| 346 | 328 |
c3, err := client.ContainerInspect(ctx, id3) |
| 347 | 329 |
assert.NilError(t, err) |
| 348 | 330 |
|
| 349 | 331 |
// verify ipv4 connectivity to the explicit --ipv address from third to fourth |
| 350 |
- _, err = container.Exec(ctx, client, id4, []string{"ping", "-c", "1", c3.NetworkSettings.Networks["dualstackl2"].IPAddress})
|
|
| 332 |
+ _, err = container.Exec(ctx, client, id4, []string{"ping", "-c", "1", c3.NetworkSettings.Networks[netName].IPAddress})
|
|
| 351 | 333 |
assert.NilError(t, err) |
| 352 | 334 |
// verify ipv6 connectivity to the explicit --ipv6 address from third to fourth |
| 353 |
- _, err = container.Exec(ctx, client, id4, []string{"ping6", "-c", "1", c3.NetworkSettings.Networks["dualstackl2"].GlobalIPv6Address})
|
|
| 335 |
+ _, err = container.Exec(ctx, client, id4, []string{"ping6", "-c", "1", c3.NetworkSettings.Networks[netName].GlobalIPv6Address})
|
|
| 354 | 336 |
assert.NilError(t, err) |
| 355 | 337 |
|
| 356 | 338 |
// Inspect the v4 gateway to ensure the proper default GW was assigned |
| 357 |
- assert.Equal(t, c1.NetworkSettings.Networks["dualstackl2"].Gateway, "172.28.200.1") |
|
| 339 |
+ assert.Equal(t, c1.NetworkSettings.Networks[netName].Gateway, "172.28.200.1") |
|
| 358 | 340 |
// Inspect the v6 gateway to ensure the proper default GW was assigned |
| 359 |
- assert.Equal(t, c1.NetworkSettings.Networks["dualstackl2"].IPv6Gateway, "2001:db8:abc8::1") |
|
| 341 |
+ assert.Equal(t, c1.NetworkSettings.Networks[netName].IPv6Gateway, "2001:db8:abc8::1") |
|
| 360 | 342 |
// Inspect the v4 gateway to ensure the proper explicitly assigned default GW was assigned |
| 361 |
- assert.Equal(t, c3.NetworkSettings.Networks["dualstackl2"].Gateway, "172.28.202.254") |
|
| 343 |
+ assert.Equal(t, c3.NetworkSettings.Networks[netName].Gateway, "172.28.202.254") |
|
| 362 | 344 |
// Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned |
| 363 |
- assert.Equal(t, c3.NetworkSettings.Networks["dualstackl2"].IPv6Gateway, "2001:db8:abc6::254") |
|
| 345 |
+ assert.Equal(t, c3.NetworkSettings.Networks[netName].IPv6Gateway, "2001:db8:abc6::254") |
|
| 364 | 346 |
} |
| 365 | 347 |
} |
| 366 | 348 |
|
| 367 | 349 |
func testIpvlanL3MultiSubnet(client dclient.APIClient) func(*testing.T) {
|
| 368 | 350 |
return func(t *testing.T) {
|
| 369 |
- _, err := client.NetworkCreate(context.Background(), "dualstackl3", types.NetworkCreate{
|
|
| 370 |
- Driver: "ipvlan", |
|
| 371 |
- EnableIPv6: true, |
|
| 372 |
- Options: map[string]string{
|
|
| 373 |
- "ipvlan_mode": "l3", |
|
| 374 |
- }, |
|
| 375 |
- IPAM: &network.IPAM{
|
|
| 376 |
- Config: []network.IPAMConfig{
|
|
| 377 |
- {
|
|
| 378 |
- Subnet: "172.28.10.0/24", |
|
| 379 |
- AuxAddress: map[string]string{},
|
|
| 380 |
- }, |
|
| 381 |
- {
|
|
| 382 |
- Subnet: "172.28.12.0/24", |
|
| 383 |
- Gateway: "172.28.12.254", |
|
| 384 |
- AuxAddress: map[string]string{},
|
|
| 385 |
- }, |
|
| 386 |
- {
|
|
| 387 |
- Subnet: "2001:db8:abc9::/64", |
|
| 388 |
- AuxAddress: map[string]string{},
|
|
| 389 |
- }, |
|
| 390 |
- {
|
|
| 391 |
- Subnet: "2001:db8:abc7::/64", |
|
| 392 |
- Gateway: "2001:db8:abc7::254", |
|
| 393 |
- AuxAddress: map[string]string{},
|
|
| 394 |
- }, |
|
| 395 |
- }, |
|
| 396 |
- }, |
|
| 397 |
- }) |
|
| 398 |
- assert.NilError(t, err) |
|
| 399 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackl3")) |
|
| 351 |
+ netName := "dualstackl3" |
|
| 352 |
+ net.CreateNoError(t, context.Background(), client, netName, |
|
| 353 |
+ net.WithIPvlan("", "l3"),
|
|
| 354 |
+ net.WithIPv6(), |
|
| 355 |
+ net.WithIPAM("172.28.10.0/24", ""),
|
|
| 356 |
+ net.WithIPAM("172.28.12.0/24", "172.28.12.254"),
|
|
| 357 |
+ net.WithIPAM("2001:db8:abc9::/64", ""),
|
|
| 358 |
+ net.WithIPAM("2001:db8:abc7::/64", "2001:db8:abc7::254"),
|
|
| 359 |
+ ) |
|
| 360 |
+ assert.Check(t, n.IsNetworkAvailable(client, netName)) |
|
| 400 | 361 |
|
| 401 | 362 |
// 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 |
| 402 | 363 |
ctx := context.Background() |
| 403 | 364 |
id1 := container.Run(t, ctx, client, |
| 404 |
- container.WithNetworkMode("dualstackl3"),
|
|
| 405 |
- container.WithIPv4("dualstackl3", "172.28.10.20"),
|
|
| 406 |
- container.WithIPv6("dualstackl3", "2001:db8:abc9::20"),
|
|
| 365 |
+ container.WithNetworkMode(netName), |
|
| 366 |
+ container.WithIPv4(netName, "172.28.10.20"), |
|
| 367 |
+ container.WithIPv6(netName, "2001:db8:abc9::20"), |
|
| 407 | 368 |
) |
| 408 | 369 |
id2 := container.Run(t, ctx, client, |
| 409 |
- container.WithNetworkMode("dualstackl3"),
|
|
| 410 |
- container.WithIPv4("dualstackl3", "172.28.10.21"),
|
|
| 411 |
- container.WithIPv6("dualstackl3", "2001:db8:abc9::21"),
|
|
| 370 |
+ container.WithNetworkMode(netName), |
|
| 371 |
+ container.WithIPv4(netName, "172.28.10.21"), |
|
| 372 |
+ container.WithIPv6(netName, "2001:db8:abc9::21"), |
|
| 412 | 373 |
) |
| 413 | 374 |
c1, err := client.ContainerInspect(ctx, id1) |
| 414 | 375 |
assert.NilError(t, err) |
| 415 | 376 |
|
| 416 | 377 |
// verify ipv4 connectivity to the explicit --ipv address second to first |
| 417 |
- _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", c1.NetworkSettings.Networks["dualstackl3"].IPAddress})
|
|
| 378 |
+ _, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", c1.NetworkSettings.Networks[netName].IPAddress})
|
|
| 418 | 379 |
assert.NilError(t, err) |
| 419 | 380 |
// verify ipv6 connectivity to the explicit --ipv6 address second to first |
| 420 |
- _, err = container.Exec(ctx, client, id2, []string{"ping6", "-c", "1", c1.NetworkSettings.Networks["dualstackl3"].GlobalIPv6Address})
|
|
| 381 |
+ _, err = container.Exec(ctx, client, id2, []string{"ping6", "-c", "1", c1.NetworkSettings.Networks[netName].GlobalIPv6Address})
|
|
| 421 | 382 |
assert.NilError(t, err) |
| 422 | 383 |
|
| 423 | 384 |
// 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 |
| 424 | 385 |
id3 := container.Run(t, ctx, client, |
| 425 |
- container.WithNetworkMode("dualstackl3"),
|
|
| 426 |
- container.WithIPv4("dualstackl3", "172.28.12.20"),
|
|
| 427 |
- container.WithIPv6("dualstackl3", "2001:db8:abc7::20"),
|
|
| 386 |
+ container.WithNetworkMode(netName), |
|
| 387 |
+ container.WithIPv4(netName, "172.28.12.20"), |
|
| 388 |
+ container.WithIPv6(netName, "2001:db8:abc7::20"), |
|
| 428 | 389 |
) |
| 429 | 390 |
id4 := container.Run(t, ctx, client, |
| 430 |
- container.WithNetworkMode("dualstackl3"),
|
|
| 431 |
- container.WithIPv4("dualstackl3", "172.28.12.21"),
|
|
| 432 |
- container.WithIPv6("dualstackl3", "2001:db8:abc7::21"),
|
|
| 391 |
+ container.WithNetworkMode(netName), |
|
| 392 |
+ container.WithIPv4(netName, "172.28.12.21"), |
|
| 393 |
+ container.WithIPv6(netName, "2001:db8:abc7::21"), |
|
| 433 | 394 |
) |
| 434 | 395 |
c3, err := client.ContainerInspect(ctx, id3) |
| 435 | 396 |
assert.NilError(t, err) |
| 436 | 397 |
|
| 437 | 398 |
// verify ipv4 connectivity to the explicit --ipv address from third to fourth |
| 438 |
- _, err = container.Exec(ctx, client, id4, []string{"ping", "-c", "1", c3.NetworkSettings.Networks["dualstackl3"].IPAddress})
|
|
| 399 |
+ _, err = container.Exec(ctx, client, id4, []string{"ping", "-c", "1", c3.NetworkSettings.Networks[netName].IPAddress})
|
|
| 439 | 400 |
assert.NilError(t, err) |
| 440 | 401 |
// verify ipv6 connectivity to the explicit --ipv6 address from third to fourth |
| 441 |
- _, err = container.Exec(ctx, client, id4, []string{"ping6", "-c", "1", c3.NetworkSettings.Networks["dualstackl3"].GlobalIPv6Address})
|
|
| 402 |
+ _, err = container.Exec(ctx, client, id4, []string{"ping6", "-c", "1", c3.NetworkSettings.Networks[netName].GlobalIPv6Address})
|
|
| 442 | 403 |
assert.NilError(t, err) |
| 443 | 404 |
|
| 444 | 405 |
// Inspect the v4 gateway to ensure no next hop is assigned in L3 mode |
| 445 |
- assert.Equal(t, c1.NetworkSettings.Networks["dualstackl3"].Gateway, "") |
|
| 406 |
+ assert.Equal(t, c1.NetworkSettings.Networks[netName].Gateway, "") |
|
| 446 | 407 |
// Inspect the v6 gateway to ensure the explicitly specified default GW is ignored per L3 mode enabled |
| 447 |
- assert.Equal(t, c1.NetworkSettings.Networks["dualstackl3"].IPv6Gateway, "") |
|
| 408 |
+ assert.Equal(t, c1.NetworkSettings.Networks[netName].IPv6Gateway, "") |
|
| 448 | 409 |
// Inspect the v4 gateway to ensure no next hop is assigned in L3 mode |
| 449 |
- assert.Equal(t, c3.NetworkSettings.Networks["dualstackl3"].Gateway, "") |
|
| 410 |
+ assert.Equal(t, c3.NetworkSettings.Networks[netName].Gateway, "") |
|
| 450 | 411 |
// Inspect the v6 gateway to ensure the explicitly specified default GW is ignored per L3 mode enabled |
| 451 |
- assert.Equal(t, c3.NetworkSettings.Networks["dualstackl3"].IPv6Gateway, "") |
|
| 412 |
+ assert.Equal(t, c3.NetworkSettings.Networks[netName].IPv6Gateway, "") |
|
| 452 | 413 |
} |
| 453 | 414 |
} |
| 454 | 415 |
|
| ... | ... |
@@ -456,32 +380,18 @@ func testIpvlanAddressing(client dclient.APIClient) func(*testing.T) {
|
| 456 | 456 |
return func(t *testing.T) {
|
| 457 | 457 |
// Verify ipvlan l2 mode sets the proper default gateway routes via netlink |
| 458 | 458 |
// for either an explicitly set route by the user or inferred via default IPAM |
| 459 |
- _, err := client.NetworkCreate(context.Background(), "dualstackl2", types.NetworkCreate{
|
|
| 460 |
- Driver: "ipvlan", |
|
| 461 |
- EnableIPv6: true, |
|
| 462 |
- Options: map[string]string{
|
|
| 463 |
- "ipvlan_mode": "l2", |
|
| 464 |
- }, |
|
| 465 |
- IPAM: &network.IPAM{
|
|
| 466 |
- Config: []network.IPAMConfig{
|
|
| 467 |
- {
|
|
| 468 |
- Subnet: "172.28.140.0/24", |
|
| 469 |
- Gateway: "172.28.140.254", |
|
| 470 |
- AuxAddress: map[string]string{},
|
|
| 471 |
- }, |
|
| 472 |
- {
|
|
| 473 |
- Subnet: "2001:db8:abcb::/64", |
|
| 474 |
- AuxAddress: map[string]string{},
|
|
| 475 |
- }, |
|
| 476 |
- }, |
|
| 477 |
- }, |
|
| 478 |
- }) |
|
| 479 |
- assert.NilError(t, err) |
|
| 480 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackl2")) |
|
| 459 |
+ netNameL2 := "dualstackl2" |
|
| 460 |
+ net.CreateNoError(t, context.Background(), client, netNameL2, |
|
| 461 |
+ net.WithIPvlan("", "l2"),
|
|
| 462 |
+ net.WithIPv6(), |
|
| 463 |
+ net.WithIPAM("172.28.140.0/24", "172.28.140.254"),
|
|
| 464 |
+ net.WithIPAM("2001:db8:abcb::/64", ""),
|
|
| 465 |
+ ) |
|
| 466 |
+ assert.Check(t, n.IsNetworkAvailable(client, netNameL2)) |
|
| 481 | 467 |
|
| 482 | 468 |
ctx := context.Background() |
| 483 | 469 |
id1 := container.Run(t, ctx, client, |
| 484 |
- container.WithNetworkMode("dualstackl2"),
|
|
| 470 |
+ container.WithNetworkMode(netNameL2), |
|
| 485 | 471 |
) |
| 486 | 472 |
// Validate ipvlan l2 mode defaults gateway sets the default IPAM next-hop inferred from the subnet |
| 487 | 473 |
result, err := container.Exec(ctx, client, id1, []string{"ip", "route"})
|
| ... | ... |
@@ -493,32 +403,17 @@ func testIpvlanAddressing(client dclient.APIClient) func(*testing.T) {
|
| 493 | 493 |
assert.Check(t, strings.Contains(result.Combined(), "default via 2001:db8:abcb::1 dev eth0")) |
| 494 | 494 |
|
| 495 | 495 |
// Validate ipvlan l3 mode sets the v4 gateway to dev eth0 and disregards any explicit or inferred next-hops |
| 496 |
- _, err = client.NetworkCreate(context.Background(), "dualstackl3", types.NetworkCreate{
|
|
| 497 |
- Driver: "ipvlan", |
|
| 498 |
- EnableIPv6: true, |
|
| 499 |
- Options: map[string]string{
|
|
| 500 |
- "ipvlan_mode": "l3", |
|
| 501 |
- }, |
|
| 502 |
- IPAM: &network.IPAM{
|
|
| 503 |
- Config: []network.IPAMConfig{
|
|
| 504 |
- {
|
|
| 505 |
- Subnet: "172.28.160.0/24", |
|
| 506 |
- Gateway: "172.28.160.254", |
|
| 507 |
- AuxAddress: map[string]string{},
|
|
| 508 |
- }, |
|
| 509 |
- {
|
|
| 510 |
- Subnet: "2001:db8:abcd::/64", |
|
| 511 |
- Gateway: "2001:db8:abcd::254", |
|
| 512 |
- AuxAddress: map[string]string{},
|
|
| 513 |
- }, |
|
| 514 |
- }, |
|
| 515 |
- }, |
|
| 516 |
- }) |
|
| 517 |
- assert.NilError(t, err) |
|
| 518 |
- assert.Check(t, n.IsNetworkAvailable(client, "dualstackl3")) |
|
| 496 |
+ netNameL3 := "dualstackl3" |
|
| 497 |
+ net.CreateNoError(t, context.Background(), client, netNameL3, |
|
| 498 |
+ net.WithIPvlan("", "l3"),
|
|
| 499 |
+ net.WithIPv6(), |
|
| 500 |
+ net.WithIPAM("172.28.160.0/24", "172.28.160.254"),
|
|
| 501 |
+ net.WithIPAM("2001:db8:abcd::/64", "2001:db8:abcd::254"),
|
|
| 502 |
+ ) |
|
| 503 |
+ assert.Check(t, n.IsNetworkAvailable(client, netNameL3)) |
|
| 519 | 504 |
|
| 520 | 505 |
id2 := container.Run(t, ctx, client, |
| 521 |
- container.WithNetworkMode("dualstackl3"),
|
|
| 506 |
+ container.WithNetworkMode(netNameL3), |
|
| 522 | 507 |
) |
| 523 | 508 |
// Validate ipvlan l3 mode sets the v4 gateway to dev eth0 and disregards any explicit or inferred next-hops |
| 524 | 509 |
result, err = container.Exec(ctx, client, id2, []string{"ip", "route"})
|