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,56 +88,50 @@ func testMacvlanOverlapParent(client client.APIClient) func(*testing.T) {
91
88
n .CreateMasterDummy (t , master )
92
89
defer n .DeleteInterface (t , master )
93
90
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" ))
91
+ netName := "dm-subinterface"
92
+ parentName := "dm-dummy0.40"
93
+ net .CreateNoError (t , context .Background (), client , netName ,
94
+ net .WithMacvlan (parentName ),
95
+ )
96
+ assert .Check (t , n .IsNetworkAvailable (client , netName ))
102
97
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
- })
98
+ _ , err := net .Create (context .Background (), client , "dm-parent-net-overlap" ,
99
+ net .WithMacvlan (parentName ),
100
+ )
109
101
assert .Check (t , err != nil )
102
+
110
103
// delete the network while preserving the parent link
111
- err = client .NetworkRemove (context .Background (), "dm-subinterface" )
104
+ err = client .NetworkRemove (context .Background (), netName )
112
105
assert .NilError (t , err )
113
106
114
- assert .Check (t , n .IsNetworkNotAvailable (client , "dm-subinterface" ))
107
+ assert .Check (t , n .IsNetworkNotAvailable (client , netName ))
115
108
// verify the network delete did not delete the predefined link
116
- n .LinkExists (t , "dm-dummy0" )
109
+ n .LinkExists (t , master )
117
110
}
118
111
}
119
112
120
113
func testMacvlanSubinterface (client client.APIClient ) func (* testing.T ) {
121
114
return func (t * testing.T ) {
122
115
// verify the same parent interface cannot be used if already in use by an existing network
123
116
master := "dm-dummy0"
117
+ parentName := "dm-dummy0.20"
124
118
n .CreateMasterDummy (t , master )
125
119
defer n .DeleteInterface (t , master )
126
- n .CreateVlanInterface (t , master , "dm-dummy0.20" , "20" )
120
+ n .CreateVlanInterface (t , master , parentName , "20" )
127
121
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" ))
122
+ netName := "dm-subinterface"
123
+ net .CreateNoError (t , context .Background (), client , netName ,
124
+ net .WithMacvlan (parentName ),
125
+ )
126
+ assert .Check (t , n .IsNetworkAvailable (client , netName ))
136
127
137
128
// delete the network while preserving the parent link
138
- err = client .NetworkRemove (context .Background (), "dm-subinterface" )
129
+ err : = client .NetworkRemove (context .Background (), netName )
139
130
assert .NilError (t , err )
140
131
141
- assert .Check (t , n .IsNetworkNotAvailable (client , "dm-subinterface" ))
132
+ assert .Check (t , n .IsNetworkNotAvailable (client , netName ))
142
133
// verify the network delete did not delete the predefined link
143
- n .LinkExists (t , "dm-dummy0.20" )
134
+ n .LinkExists (t , parentName )
144
135
}
145
136
}
146
137
@@ -190,34 +181,17 @@ func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
190
181
191
182
func testMacvlanMultiSubnet (client client.APIClient ) func (* testing.T ) {
192
183
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" ))
184
+ netName := "dualstackbridge"
185
+ net .CreateNoError (t , context .Background (), client , netName ,
186
+ net .WithMacvlan ("" ),
187
+ net .WithIPv6 (),
188
+ net .WithIPAM ("172.28.100.0/24" , "" ),
189
+ net .WithIPAM ("172.28.102.0/24" , "172.28.102.254" ),
190
+ net .WithIPAM ("2001:db8:abc2::/64" , "" ),
191
+ net .WithIPAM ("2001:db8:abc4::/64" , "2001:db8:abc4::254" ),
192
+ )
193
+
194
+ assert .Check (t , n .IsNetworkAvailable (client , netName ))
221
195
222
196
// 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
197
ctx := context .Background ()
@@ -276,28 +250,15 @@ func testMacvlanMultiSubnet(client client.APIClient) func(*testing.T) {
276
250
func testMacvlanAddressing (client client.APIClient ) func (* testing.T ) {
277
251
return func (t * testing.T ) {
278
252
// 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" ))
253
+ netName := "dualstackbridge"
254
+ net .CreateNoError (t , context .Background (), client , netName ,
255
+ net .WithMacvlan ("" ),
256
+ net .WithIPv6 (),
257
+ net .WithOption ("macvlan_mode" , "bridge" ),
258
+ net .WithIPAM ("172.28.130.0/24" , "" ),
259
+ net .WithIPAM ("2001:db8:abca::/64" , "2001:db8:abca::254" ),
260
+ )
261
+ assert .Check (t , n .IsNetworkAvailable (client , netName ))
301
262
302
263
ctx := context .Background ()
303
264
id1 := container .Run (t , ctx , client ,
0 commit comments