9
"github.com/containers/podman/v5/pkg/domain/entities"
10
. "github.com/containers/podman/v5/test/utils"
11
"github.com/containers/storage/pkg/stringid"
12
. "github.com/onsi/ginkgo/v2"
13
. "github.com/onsi/gomega"
14
. "github.com/onsi/gomega/gexec"
17
var _ = Describe("Podman network", func() {
19
It("podman --cni-config-dir backwards compat", func() {
20
SkipIfRemote("--cni-config-dir only works locally")
21
netDir := filepath.Join(podmanTest.TempDir, "networks123")
22
session := podmanTest.Podman([]string{"--cni-config-dir", netDir, "network", "ls", "--noheading"})
23
session.WaitWithDefaultTimeout()
24
Expect(session).Should(ExitCleanly())
25
// default network always exists
26
Expect(session.OutputToStringArray()).To(HaveLen(1))
29
It("podman network list", func() {
30
name, path := generateNetworkConfig(podmanTest)
31
defer removeConf(path)
33
session := podmanTest.Podman([]string{"network", "ls"})
34
session.WaitWithDefaultTimeout()
35
Expect(session).Should(ExitCleanly())
36
Expect(session.OutputToString()).To(ContainSubstring(name))
39
It("podman network list -q", func() {
40
name, path := generateNetworkConfig(podmanTest)
41
defer removeConf(path)
43
session := podmanTest.Podman([]string{"network", "ls", "--quiet"})
44
session.WaitWithDefaultTimeout()
45
Expect(session).Should(ExitCleanly())
46
Expect(session.OutputToString()).To(ContainSubstring(name))
49
It("podman network list --filter success", func() {
50
name, path := generateNetworkConfig(podmanTest)
51
defer removeConf(path)
53
session := podmanTest.Podman([]string{"network", "ls", "--filter", "driver=bridge"})
54
session.WaitWithDefaultTimeout()
55
// Cannot ExitCleanly(): "stat ~/.config/.../*.conflist: ENOENT"
56
Expect(session).Should(Exit(0))
57
Expect(session.OutputToString()).To(ContainSubstring(name))
60
It("podman network list --filter driver and name", func() {
61
name, path := generateNetworkConfig(podmanTest)
62
defer removeConf(path)
64
session := podmanTest.Podman([]string{"network", "ls", "--filter", "driver=bridge", "--filter", "name=" + name})
65
session.WaitWithDefaultTimeout()
66
Expect(session).Should(ExitCleanly())
67
Expect(session.OutputToString()).To(ContainSubstring(name))
70
It("podman network list --filter two names", func() {
71
name1, path1 := generateNetworkConfig(podmanTest)
72
defer removeConf(path1)
74
name2, path2 := generateNetworkConfig(podmanTest)
75
defer removeConf(path2)
77
session := podmanTest.Podman([]string{"network", "ls", "--filter", "name=" + name1, "--filter", "name=" + name2})
78
session.WaitWithDefaultTimeout()
79
Expect(session).Should(ExitCleanly())
80
Expect(session.OutputToString()).To(ContainSubstring(name1))
81
Expect(session.OutputToString()).To(ContainSubstring(name2))
84
It("podman network list --filter labels", func() {
85
net1 := "labelnet" + stringid.GenerateRandomID()
86
label1 := "testlabel1=abc"
88
session := podmanTest.Podman([]string{"network", "create", "--label", label1, net1})
89
session.WaitWithDefaultTimeout()
90
defer podmanTest.removeNetwork(net1)
91
Expect(session).Should(ExitCleanly())
93
net2 := "labelnet" + stringid.GenerateRandomID()
94
session = podmanTest.Podman([]string{"network", "create", "--label", label1, "--label", label2, net2})
95
session.WaitWithDefaultTimeout()
96
defer podmanTest.removeNetwork(net2)
97
Expect(session).Should(ExitCleanly())
99
session = podmanTest.Podman([]string{"network", "ls", "--filter", "label=" + label1})
100
session.WaitWithDefaultTimeout()
101
Expect(session).Should(ExitCleanly())
102
Expect(session.OutputToString()).To(ContainSubstring(net1))
103
Expect(session.OutputToString()).To(ContainSubstring(net2))
105
session = podmanTest.Podman([]string{"network", "ls", "--filter", "label=" + label1, "--filter", "label=" + label2})
106
session.WaitWithDefaultTimeout()
107
Expect(session).Should(ExitCleanly())
108
Expect(session.OutputToString()).ToNot(ContainSubstring(net1))
109
Expect(session.OutputToString()).To(ContainSubstring(net2))
112
It("podman network list --filter invalid value", func() {
113
net := "net" + stringid.GenerateRandomID()
114
session := podmanTest.Podman([]string{"network", "create", net})
115
session.WaitWithDefaultTimeout()
116
defer podmanTest.removeNetwork(net)
117
Expect(session).Should(ExitCleanly())
119
session = podmanTest.Podman([]string{"network", "ls", "--filter", "namr=ab"})
120
session.WaitWithDefaultTimeout()
121
Expect(session).To(ExitWithError())
122
Expect(session.ErrorToString()).To(ContainSubstring(`invalid filter "namr"`))
125
It("podman network list --filter failure", func() {
126
name, path := generateNetworkConfig(podmanTest)
127
defer removeConf(path)
129
session := podmanTest.Podman([]string{"network", "ls", "--filter", "label=abc"})
130
session.WaitWithDefaultTimeout()
131
Expect(session).Should(ExitCleanly())
132
Expect(session.OutputToString()).To(Not(ContainSubstring(name)))
135
It("podman network list --filter dangling", func() {
136
name, path := generateNetworkConfig(podmanTest)
137
defer removeConf(path)
139
session := podmanTest.Podman([]string{"network", "ls", "--filter", "dangling=true"})
140
session.WaitWithDefaultTimeout()
141
Expect(session).Should(ExitCleanly())
142
Expect(session.OutputToString()).To(ContainSubstring(name))
144
session = podmanTest.Podman([]string{"network", "ls", "--filter", "dangling=false"})
145
session.WaitWithDefaultTimeout()
146
Expect(session).Should(ExitCleanly())
147
Expect(session.OutputToString()).NotTo(ContainSubstring(name))
149
session = podmanTest.Podman([]string{"network", "ls", "--filter", "dangling=foo"})
150
session.WaitWithDefaultTimeout()
151
Expect(session).To(ExitWithError())
152
Expect(session.ErrorToString()).To(ContainSubstring(`invalid dangling filter value "foo"`))
155
It("podman network ID test", func() {
156
net := "networkIDTest"
157
// the network id should be the sha256 hash of the network name
158
netID := "6073aefe03cdf8f29be5b23ea9795c431868a3a22066a6290b187691614fee84"
159
session := podmanTest.Podman([]string{"network", "create", net})
160
session.WaitWithDefaultTimeout()
161
defer podmanTest.removeNetwork(net)
162
Expect(session).Should(ExitCleanly())
164
if podmanTest.NetworkBackend == Netavark {
165
// netavark uses a different algo for determining the id and it is not repeatable
166
getid := podmanTest.Podman([]string{"network", "inspect", net, "--format", "{{.ID}}"})
167
getid.WaitWithDefaultTimeout()
168
Expect(getid).Should(ExitCleanly())
169
netID = getid.OutputToString()
171
// Tests Default Table Output
172
session = podmanTest.Podman([]string{"network", "ls", "--filter", "id=" + netID})
173
session.WaitWithDefaultTimeout()
174
Expect(session).Should(ExitCleanly())
175
expectedTable := "NETWORK ID NAME DRIVER"
176
Expect(session.OutputToString()).To(ContainSubstring(expectedTable))
178
session = podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}} {{.ID}}", "--filter", "id=" + netID})
179
session.WaitWithDefaultTimeout()
180
Expect(session).Should(ExitCleanly())
181
Expect(session.OutputToString()).To(ContainSubstring(net + " " + netID[:12]))
183
session = podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}} {{.ID}}", "--filter", "id=" + netID[:50], "--no-trunc"})
184
session.WaitWithDefaultTimeout()
185
Expect(session).Should(ExitCleanly())
186
Expect(session.OutputToString()).To(ContainSubstring(net + " " + netID))
188
session = podmanTest.Podman([]string{"network", "inspect", netID[:40]})
189
session.WaitWithDefaultTimeout()
190
Expect(session).Should(ExitCleanly())
191
Expect(session.OutputToString()).To(ContainSubstring(net))
193
session = podmanTest.Podman([]string{"network", "inspect", netID[1:]})
194
session.WaitWithDefaultTimeout()
195
Expect(session).Should(ExitWithError())
196
Expect(session.ErrorToString()).To(ContainSubstring("network not found"))
198
session = podmanTest.Podman([]string{"network", "rm", netID})
199
session.WaitWithDefaultTimeout()
200
Expect(session).Should(ExitCleanly())
203
rmFunc := func(rm string) {
204
It(fmt.Sprintf("podman network %s no args", rm), func() {
205
session := podmanTest.Podman([]string{"network", rm})
206
session.WaitWithDefaultTimeout()
207
Expect(session).Should(ExitWithError())
211
It(fmt.Sprintf("podman network %s", rm), func() {
212
name, path := generateNetworkConfig(podmanTest)
213
defer removeConf(path)
215
session := podmanTest.Podman([]string{"network", "ls", "--quiet"})
216
session.WaitWithDefaultTimeout()
217
Expect(session).Should(ExitCleanly())
218
Expect(session.OutputToString()).To(ContainSubstring(name))
220
rm := podmanTest.Podman([]string{"network", rm, name})
221
rm.WaitWithDefaultTimeout()
222
Expect(rm).Should(ExitCleanly())
224
results := podmanTest.Podman([]string{"network", "ls", "--quiet"})
225
results.WaitWithDefaultTimeout()
226
Expect(results).Should(ExitCleanly())
227
Expect(results.OutputToString()).To(Not(ContainSubstring(name)))
234
It("podman network inspect no args", func() {
235
session := podmanTest.Podman([]string{"network", "inspect"})
236
session.WaitWithDefaultTimeout()
237
Expect(session).Should(ExitWithError())
240
It("podman network inspect", func() {
241
name, path := generateNetworkConfig(podmanTest)
242
defer removeConf(path)
244
expectedNetworks := []string{name}
246
// rootful image contains "podman/cni/87-podman-bridge.conflist" for "podman" network
247
expectedNetworks = append(expectedNetworks, "podman")
249
session := podmanTest.Podman(append([]string{"network", "inspect"}, expectedNetworks...))
250
session.WaitWithDefaultTimeout()
251
Expect(session).Should(ExitCleanly())
252
Expect(session.OutputToString()).To(BeValidJSON())
255
It("podman network inspect", func() {
256
name, path := generateNetworkConfig(podmanTest)
257
defer removeConf(path)
259
session := podmanTest.Podman([]string{"network", "inspect", name, "--format", "{{.Driver}}"})
260
session.WaitWithDefaultTimeout()
261
Expect(session).Should(ExitCleanly())
262
Expect(session.OutputToString()).To(ContainSubstring("bridge"))
265
It("podman inspect container single CNI network", func() {
266
netName := "net-" + stringid.GenerateRandomID()
267
network := podmanTest.Podman([]string{"network", "create", "--subnet", "10.50.50.0/24", netName})
268
network.WaitWithDefaultTimeout()
269
defer podmanTest.removeNetwork(netName)
270
Expect(network).Should(ExitCleanly())
273
container := podmanTest.Podman([]string{"run", "-dt", "--network", netName, "--name", ctrName, ALPINE, "top"})
274
container.WaitWithDefaultTimeout()
275
Expect(container).Should(ExitCleanly())
277
inspect := podmanTest.Podman([]string{"inspect", ctrName})
278
inspect.WaitWithDefaultTimeout()
279
Expect(inspect).Should(ExitCleanly())
280
conData := inspect.InspectContainerToJSON()
281
Expect(conData).To(HaveLen(1))
282
Expect(conData[0].NetworkSettings.Networks).To(HaveLen(1))
283
Expect(conData[0].NetworkSettings.Networks).To(HaveKey(netName))
284
net := conData[0].NetworkSettings.Networks[netName]
285
Expect(net).To(HaveField("NetworkID", netName))
286
Expect(net).To(HaveField("IPPrefixLen", 24))
287
Expect(net.IPAddress).To(HavePrefix("10.50.50."))
289
// Necessary to ensure the CNI network is removed cleanly
290
rmAll := podmanTest.Podman([]string{"rm", "-t", "0", "-f", ctrName})
291
rmAll.WaitWithDefaultTimeout()
292
Expect(rmAll).Should(ExitCleanly())
295
It("podman inspect container two CNI networks (container not running)", func() {
296
netName1 := "net1-" + stringid.GenerateRandomID()
297
network1 := podmanTest.Podman([]string{"network", "create", netName1})
298
network1.WaitWithDefaultTimeout()
299
defer podmanTest.removeNetwork(netName1)
300
Expect(network1).Should(ExitCleanly())
302
netName2 := "net2-" + stringid.GenerateRandomID()
303
network2 := podmanTest.Podman([]string{"network", "create", netName2})
304
network2.WaitWithDefaultTimeout()
305
defer podmanTest.removeNetwork(netName2)
306
Expect(network2).Should(ExitCleanly())
309
container := podmanTest.Podman([]string{"create", "--network", fmt.Sprintf("%s,%s", netName1, netName2), "--name", ctrName, ALPINE, "top"})
310
container.WaitWithDefaultTimeout()
311
Expect(container).Should(ExitCleanly())
313
inspect := podmanTest.Podman([]string{"inspect", ctrName})
314
inspect.WaitWithDefaultTimeout()
315
Expect(inspect).Should(ExitCleanly())
316
conData := inspect.InspectContainerToJSON()
317
Expect(conData).To(HaveLen(1))
318
Expect(conData[0].NetworkSettings.Networks).To(HaveLen(2))
319
Expect(conData[0].NetworkSettings.Networks).To(HaveKey(netName1))
320
Expect(conData[0].NetworkSettings.Networks).To(HaveKey(netName2))
321
net1 := conData[0].NetworkSettings.Networks[netName1]
322
Expect(net1).To(HaveField("NetworkID", netName1))
323
net2 := conData[0].NetworkSettings.Networks[netName2]
324
Expect(net2).To(HaveField("NetworkID", netName2))
326
// Necessary to ensure the CNI network is removed cleanly
327
rmAll := podmanTest.Podman([]string{"rm", "-t", "0", "-f", ctrName})
328
rmAll.WaitWithDefaultTimeout()
329
Expect(rmAll).Should(ExitCleanly())
332
It("podman inspect container two CNI networks", func() {
333
netName1 := "net1-" + stringid.GenerateRandomID()
334
network1 := podmanTest.Podman([]string{"network", "create", "--subnet", "10.50.51.0/25", netName1})
335
network1.WaitWithDefaultTimeout()
336
defer podmanTest.removeNetwork(netName1)
337
Expect(network1).Should(ExitCleanly())
339
netName2 := "net2-" + stringid.GenerateRandomID()
340
network2 := podmanTest.Podman([]string{"network", "create", "--subnet", "10.50.51.128/26", netName2})
341
network2.WaitWithDefaultTimeout()
342
defer podmanTest.removeNetwork(netName2)
343
Expect(network2).Should(ExitCleanly())
346
container := podmanTest.Podman([]string{"run", "-dt", "--network", fmt.Sprintf("%s,%s", netName1, netName2), "--name", ctrName, ALPINE, "top"})
347
container.WaitWithDefaultTimeout()
348
Expect(container).Should(ExitCleanly())
350
inspect := podmanTest.Podman([]string{"inspect", ctrName})
351
inspect.WaitWithDefaultTimeout()
352
Expect(inspect).Should(ExitCleanly())
353
conData := inspect.InspectContainerToJSON()
354
Expect(conData).To(HaveLen(1))
355
Expect(conData[0].NetworkSettings.Networks).To(HaveLen(2))
356
Expect(conData[0].NetworkSettings.Networks).To(HaveKey(netName1))
357
Expect(conData[0].NetworkSettings.Networks).To(HaveKey(netName2))
358
net1 := conData[0].NetworkSettings.Networks[netName1]
359
Expect(net1).To(HaveField("NetworkID", netName1))
360
Expect(net1).To(HaveField("IPPrefixLen", 25))
361
Expect(net1.IPAddress).To(HavePrefix("10.50.51."))
362
net2 := conData[0].NetworkSettings.Networks[netName2]
363
Expect(net2).To(HaveField("NetworkID", netName2))
364
Expect(net2).To(HaveField("IPPrefixLen", 26))
365
Expect(net2.IPAddress).To(HavePrefix("10.50.51."))
367
// Necessary to ensure the CNI network is removed cleanly
368
rmAll := podmanTest.Podman([]string{"rm", "-t", "0", "-f", ctrName})
369
rmAll.WaitWithDefaultTimeout()
370
Expect(rmAll).Should(ExitCleanly())
373
It("podman network remove after disconnect when container initially created with the network", func() {
375
network := "foo" + stringid.GenerateRandomID()
377
session := podmanTest.Podman([]string{"network", "create", network})
378
session.WaitWithDefaultTimeout()
379
defer podmanTest.removeNetwork(network)
380
Expect(session).Should(ExitCleanly())
382
session = podmanTest.Podman([]string{"run", "--name", container, "--network", network, "-d", ALPINE, "top"})
383
session.WaitWithDefaultTimeout()
384
Expect(session).Should(ExitCleanly())
386
session = podmanTest.Podman([]string{"network", "disconnect", network, container})
387
session.WaitWithDefaultTimeout()
388
Expect(session).Should(ExitCleanly())
390
session = podmanTest.Podman([]string{"network", "rm", network})
391
session.WaitWithDefaultTimeout()
392
Expect(session).Should(ExitCleanly())
395
It("podman network remove bogus", func() {
396
session := podmanTest.Podman([]string{"network", "rm", "bogus"})
397
session.WaitWithDefaultTimeout()
398
Expect(session).Should(Exit(1))
401
It("podman network remove --force with pod", func() {
402
netName := "net-" + stringid.GenerateRandomID()
403
session := podmanTest.Podman([]string{"network", "create", netName})
404
session.WaitWithDefaultTimeout()
405
defer podmanTest.removeNetwork(netName)
406
Expect(session).Should(ExitCleanly())
408
session = podmanTest.Podman([]string{"pod", "create", "--network", netName})
409
session.WaitWithDefaultTimeout()
410
Expect(session).Should(ExitCleanly())
411
podID := session.OutputToString()
413
session = podmanTest.Podman([]string{"create", "--pod", podID, ALPINE})
414
session.WaitWithDefaultTimeout()
415
Expect(session).Should(ExitCleanly())
417
session = podmanTest.Podman([]string{"network", "rm", netName})
418
session.WaitWithDefaultTimeout()
419
Expect(session).Should(Exit(2))
421
session = podmanTest.Podman([]string{"network", "rm", "-t", "0", "--force", netName})
422
session.WaitWithDefaultTimeout()
423
Expect(session).Should(ExitCleanly())
425
// check if pod is deleted
426
session = podmanTest.Podman([]string{"pod", "exists", podID})
427
session.WaitWithDefaultTimeout()
428
Expect(session).Should(Exit(1))
430
// check if net is deleted
431
session = podmanTest.Podman([]string{"network", "ls"})
432
session.WaitWithDefaultTimeout()
433
Expect(session).Should(ExitCleanly())
434
Expect(session.OutputToString()).To(Not(ContainSubstring(netName)))
437
It("podman network remove with two networks", func() {
438
netName1 := "net1-" + stringid.GenerateRandomID()
439
session := podmanTest.Podman([]string{"network", "create", netName1})
440
session.WaitWithDefaultTimeout()
441
defer podmanTest.removeNetwork(netName1)
442
Expect(session).Should(ExitCleanly())
444
netName2 := "net2-" + stringid.GenerateRandomID()
445
session = podmanTest.Podman([]string{"network", "create", netName2})
446
session.WaitWithDefaultTimeout()
447
defer podmanTest.removeNetwork(netName2)
448
Expect(session).Should(ExitCleanly())
450
session = podmanTest.Podman([]string{"network", "rm", netName1, netName2})
451
session.WaitWithDefaultTimeout()
452
Expect(session).Should(ExitCleanly())
453
lines := session.OutputToStringArray()
454
Expect(lines[0]).To(Equal(netName1))
455
Expect(lines[1]).To(Equal(netName2))
458
It("podman network with multiple aliases", func() {
460
netName := createNetworkName("aliasTest")
461
session := podmanTest.Podman([]string{"network", "create", netName})
462
session.WaitWithDefaultTimeout()
463
defer podmanTest.removeNetwork(netName)
464
Expect(session).Should(ExitCleanly())
466
interval := 250 * time.Millisecond
467
for i := 0; i < 6; i++ {
468
n := podmanTest.Podman([]string{"network", "exists", netName})
469
n.WaitWithDefaultTimeout()
470
worked = n.ExitCode() == 0
478
top := podmanTest.Podman([]string{"run", "-dt", "--name=web", "--network=" + netName, "--network-alias=web1", "--network-alias=web2", NGINX_IMAGE})
479
top.WaitWithDefaultTimeout()
480
Expect(top).Should(ExitCleanly())
481
interval = 250 * time.Millisecond
482
// Wait for the nginx service to be running
483
for i := 0; i < 6; i++ {
484
// Test curl against the container's name
485
c1 := podmanTest.Podman([]string{"run", "--dns-search", "dns.podman", "--network=" + netName, NGINX_IMAGE, "curl", "web"})
486
c1.WaitWithDefaultTimeout()
487
worked = c1.ExitCode() == 0
494
Expect(worked).To(BeTrue(), "nginx came up")
496
// Nginx is now running so no need to do a loop
497
// Test against the first alias
498
c2 := podmanTest.Podman([]string{"run", "--dns-search", "dns.podman", "--network=" + netName, NGINX_IMAGE, "curl", "-s", "web1"})
499
c2.WaitWithDefaultTimeout()
500
Expect(c2).Should(ExitCleanly())
502
// Test against the second alias
503
c3 := podmanTest.Podman([]string{"run", "--dns-search", "dns.podman", "--network=" + netName, NGINX_IMAGE, "curl", "-s", "web2"})
504
c3.WaitWithDefaultTimeout()
505
Expect(c3).Should(ExitCleanly())
508
It("podman network create/remove macvlan", func() {
509
net := "macvlan" + stringid.GenerateRandomID()
510
nc := podmanTest.Podman([]string{"network", "create", "--macvlan", "lo", net})
511
nc.WaitWithDefaultTimeout()
512
defer podmanTest.removeNetwork(net)
513
// Cannot ExitCleanly(): "The --macvlan option is deprecated..."
514
Expect(nc).Should(Exit(0))
516
nc = podmanTest.Podman([]string{"network", "rm", net})
517
nc.WaitWithDefaultTimeout()
518
Expect(nc).Should(ExitCleanly())
521
It("podman network create/remove macvlan as driver (-d) no device name", func() {
522
net := "macvlan" + stringid.GenerateRandomID()
523
nc := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", net})
524
nc.WaitWithDefaultTimeout()
525
defer podmanTest.removeNetwork(net)
526
Expect(nc).Should(ExitCleanly())
528
inspect := podmanTest.Podman([]string{"network", "inspect", net})
529
inspect.WaitWithDefaultTimeout()
530
Expect(inspect).Should(ExitCleanly())
532
// JSON the network configuration into something usable
533
var results []entities.NetworkInspectReport
534
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
535
Expect(err).ToNot(HaveOccurred())
536
Expect(results).To(HaveLen(1))
538
Expect(result).To(HaveField("NetworkInterface", ""))
539
Expect(result.IPAMOptions).To(HaveKeyWithValue("driver", "dhcp"))
541
nc = podmanTest.Podman([]string{"network", "rm", net})
542
nc.WaitWithDefaultTimeout()
543
Expect(nc).Should(ExitCleanly())
546
for _, opt := range []string{"-o=parent=lo", "--interface-name=lo"} {
548
It(fmt.Sprintf("podman network create/remove macvlan as driver (-d) with %s", opt), func() {
549
net := "macvlan" + stringid.GenerateRandomID()
550
nc := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", opt, net})
551
nc.WaitWithDefaultTimeout()
552
defer podmanTest.removeNetwork(net)
553
Expect(nc).Should(ExitCleanly())
555
inspect := podmanTest.Podman([]string{"network", "inspect", net})
556
inspect.WaitWithDefaultTimeout()
557
Expect(inspect).Should(ExitCleanly())
559
var results []entities.NetworkInspectReport
560
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
561
Expect(err).ToNot(HaveOccurred())
562
Expect(results).To(HaveLen(1))
565
Expect(result).To(HaveField("Driver", "macvlan"))
566
Expect(result).To(HaveField("NetworkInterface", "lo"))
567
Expect(result.IPAMOptions).To(HaveKeyWithValue("driver", "dhcp"))
568
Expect(result.Subnets).To(BeEmpty())
570
nc = podmanTest.Podman([]string{"network", "rm", net})
571
nc.WaitWithDefaultTimeout()
572
Expect(nc).Should(ExitCleanly())
576
It("podman network create/remove ipvlan as driver (-d) with device name", func() {
577
net := "ipvlan" + stringid.GenerateRandomID()
578
nc := podmanTest.Podman([]string{"network", "create", "-d", "ipvlan", "-o", "parent=lo", "--subnet", "10.0.2.0/24", net})
579
nc.WaitWithDefaultTimeout()
580
defer podmanTest.removeNetwork(net)
581
Expect(nc).Should(ExitCleanly())
583
inspect := podmanTest.Podman([]string{"network", "inspect", net})
584
inspect.WaitWithDefaultTimeout()
585
Expect(inspect).Should(ExitCleanly())
587
var results []entities.NetworkInspectReport
588
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
589
Expect(err).ToNot(HaveOccurred())
590
Expect(results).To(HaveLen(1))
593
Expect(result).To(HaveField("Driver", "ipvlan"))
594
Expect(result).To(HaveField("NetworkInterface", "lo"))
595
Expect(result.IPAMOptions).To(HaveKeyWithValue("driver", "host-local"))
596
Expect(result.Subnets).To(HaveLen(1))
598
nc = podmanTest.Podman([]string{"network", "rm", net})
599
nc.WaitWithDefaultTimeout()
600
Expect(nc).Should(ExitCleanly())
603
It("podman network exists", func() {
604
net := "net" + stringid.GenerateRandomID()
605
session := podmanTest.Podman([]string{"network", "create", net})
606
session.WaitWithDefaultTimeout()
607
defer podmanTest.removeNetwork(net)
608
Expect(session).Should(ExitCleanly())
610
session = podmanTest.Podman([]string{"network", "exists", net})
611
session.WaitWithDefaultTimeout()
612
Expect(session).Should(ExitCleanly())
614
session = podmanTest.Podman([]string{"network", "exists", stringid.GenerateRandomID()})
615
session.WaitWithDefaultTimeout()
616
Expect(session).Should(Exit(1))
619
It("podman network create macvlan with network info and options", func() {
620
net := "macvlan" + stringid.GenerateRandomID()
621
nc := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", "-o", "parent=lo", "-o", "mtu=1500", "--gateway", "192.168.1.254", "--subnet", "192.168.1.0/24", net})
622
nc.WaitWithDefaultTimeout()
623
defer podmanTest.removeNetwork(net)
624
Expect(nc).Should(ExitCleanly())
626
inspect := podmanTest.Podman([]string{"network", "inspect", net})
627
inspect.WaitWithDefaultTimeout()
628
Expect(inspect).Should(ExitCleanly())
630
var results []entities.NetworkInspectReport
631
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
632
Expect(err).ToNot(HaveOccurred())
633
Expect(results).To(HaveLen(1))
636
Expect(result.Options).To(HaveKeyWithValue("mtu", "1500"))
637
Expect(result).To(HaveField("Driver", "macvlan"))
638
Expect(result).To(HaveField("NetworkInterface", "lo"))
639
Expect(result.IPAMOptions).To(HaveKeyWithValue("driver", "host-local"))
641
Expect(result.Subnets).To(HaveLen(1))
642
Expect(result.Subnets[0].Subnet.String()).To(Equal("192.168.1.0/24"))
643
Expect(result.Subnets[0].Gateway.String()).To(Equal("192.168.1.254"))
645
nc = podmanTest.Podman([]string{"network", "rm", net})
646
nc.WaitWithDefaultTimeout()
647
Expect(nc).Should(ExitCleanly())
650
It("podman network prune --filter", func() {
651
useCustomNetworkDir(podmanTest, tempdir)
652
net1 := "macvlan" + stringid.GenerateRandomID() + "net1"
654
nc := podmanTest.Podman([]string{"network", "create", net1})
655
nc.WaitWithDefaultTimeout()
656
defer podmanTest.removeNetwork(net1)
657
Expect(nc).Should(ExitCleanly())
659
list := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
660
list.WaitWithDefaultTimeout()
661
Expect(list).Should(ExitCleanly())
662
Expect(list.OutputToStringArray()).Should(HaveLen(2))
664
Expect(list.OutputToStringArray()).Should(ContainElement(net1))
665
Expect(list.OutputToStringArray()).Should(ContainElement("podman"))
667
// -f needed only to skip y/n question
668
prune := podmanTest.Podman([]string{"network", "prune", "-f", "--filter", "until=50"})
669
prune.WaitWithDefaultTimeout()
670
Expect(prune).Should(ExitCleanly())
672
listAgain := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
673
listAgain.WaitWithDefaultTimeout()
674
Expect(listAgain).Should(ExitCleanly())
675
Expect(listAgain.OutputToStringArray()).Should(HaveLen(2))
677
Expect(listAgain.OutputToStringArray()).Should(ContainElement(net1))
678
Expect(listAgain.OutputToStringArray()).Should(ContainElement("podman"))
680
// -f needed only to skip y/n question
681
prune = podmanTest.Podman([]string{"network", "prune", "-f", "--filter", "until=5000000000000"})
682
prune.WaitWithDefaultTimeout()
683
Expect(prune).Should(ExitCleanly())
685
listAgain = podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
686
listAgain.WaitWithDefaultTimeout()
687
Expect(listAgain).Should(ExitCleanly())
688
Expect(listAgain.OutputToStringArray()).Should(HaveLen(1))
690
Expect(listAgain.OutputToStringArray()).ShouldNot(ContainElement(net1))
691
Expect(listAgain.OutputToStringArray()).Should(ContainElement("podman"))
694
It("podman network prune", func() {
695
useCustomNetworkDir(podmanTest, tempdir)
696
// Create two networks
697
// Check they are there
698
// Run a container on one of them
700
// Check that one has been pruned, other remains
701
net := "macvlan" + stringid.GenerateRandomID()
704
nc := podmanTest.Podman([]string{"network", "create", net1})
705
nc.WaitWithDefaultTimeout()
706
defer podmanTest.removeNetwork(net1)
707
Expect(nc).Should(ExitCleanly())
709
nc2 := podmanTest.Podman([]string{"network", "create", net2})
710
nc2.WaitWithDefaultTimeout()
711
defer podmanTest.removeNetwork(net2)
712
Expect(nc2).Should(ExitCleanly())
714
list := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
715
list.WaitWithDefaultTimeout()
716
Expect(list.OutputToStringArray()).Should(HaveLen(3))
718
Expect(list.OutputToStringArray()).Should(ContainElement(net1))
719
Expect(list.OutputToStringArray()).Should(ContainElement(net2))
720
Expect(list.OutputToStringArray()).Should(ContainElement("podman"))
722
session := podmanTest.Podman([]string{"run", "-dt", "--net", net2, ALPINE, "top"})
723
session.WaitWithDefaultTimeout()
724
Expect(session).Should(ExitCleanly())
726
prune := podmanTest.Podman([]string{"network", "prune", "-f"})
727
prune.WaitWithDefaultTimeout()
728
Expect(prune).Should(ExitCleanly())
730
listAgain := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
731
listAgain.WaitWithDefaultTimeout()
732
Expect(listAgain).Should(ExitCleanly())
733
Expect(listAgain.OutputToStringArray()).Should(HaveLen(2))
735
Expect(listAgain.OutputToStringArray()).ShouldNot(ContainElement(net1))
736
Expect(listAgain.OutputToStringArray()).Should(ContainElement(net2))
737
Expect(listAgain.OutputToStringArray()).Should(ContainElement("podman"))