Use InspectNetwork helper in e2e tests

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
This commit is contained in:
Jan Rodák
2025-12-15 17:15:57 +01:00
parent 6acfd58026
commit 1ccded76ce
3 changed files with 81 additions and 178 deletions

View File

@@ -3,11 +3,10 @@
package integration
import (
"encoding/json"
"fmt"
"net"
"strings"
"github.com/containers/podman/v6/pkg/domain/entities"
. "github.com/containers/podman/v6/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@@ -29,14 +28,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -80,14 +72,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -119,14 +104,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -160,14 +138,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -203,14 +174,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -242,14 +206,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -271,14 +228,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -310,14 +260,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))
@@ -343,13 +286,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect = podmanTest.Podman([]string{"network", "inspect", netName2})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
err = json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results = podmanTest.InspectNetwork(netName2)
Expect(results).To(HaveLen(1))
result = results[0]
Expect(result).To(HaveField("Name", netName2))
@@ -396,11 +333,22 @@ var _ = Describe("Podman network create", func() {
Expect(nc).To(ExitCleanly())
defer podmanTest.removeNetwork(name)
nc = podmanTest.Podman([]string{"network", "inspect", name})
nc.WaitWithDefaultTimeout()
Expect(nc).To(ExitCleanly())
Expect(nc.OutputToString()).To(ContainSubstring(`::/64`))
Expect(nc.OutputToString()).To(ContainSubstring(`10.11.14.0/24`))
results := podmanTest.InspectNetwork(name)
Expect(results).To(HaveLen(1))
Expect(results[0].Subnets).To(HaveLen(2))
// Check for both IPv4 and IPv6 subnets
hasIPv4 := false
hasIPv6 := false
for _, subnet := range results[0].Subnets {
if subnet.Subnet.String() == "10.11.14.0/24" {
hasIPv4 = true
}
if strings.HasSuffix(subnet.Subnet.String(), "::/64") {
hasIPv6 = true
}
}
Expect(hasIPv4).To(BeTrue())
Expect(hasIPv6).To(BeTrue())
})
It("podman network create with empty subnet and ipv6 flag", func() {
@@ -410,11 +358,22 @@ var _ = Describe("Podman network create", func() {
Expect(nc).To(ExitCleanly())
defer podmanTest.removeNetwork(name)
nc = podmanTest.Podman([]string{"network", "inspect", name})
nc.WaitWithDefaultTimeout()
Expect(nc).To(ExitCleanly())
Expect(nc.OutputToString()).To(ContainSubstring(`::/64`))
Expect(nc.OutputToString()).To(ContainSubstring(`.0/24`))
results := podmanTest.InspectNetwork(name)
Expect(results).To(HaveLen(1))
Expect(results[0].Subnets).To(HaveLen(2))
// Check for both IPv4 and IPv6 subnets
hasIPv4 := false
hasIPv6 := false
for _, subnet := range results[0].Subnets {
if strings.HasSuffix(subnet.Subnet.String(), ".0/24") {
hasIPv4 = true
}
if strings.HasSuffix(subnet.Subnet.String(), "::/64") {
hasIPv6 = true
}
}
Expect(hasIPv4).To(BeTrue())
Expect(hasIPv6).To(BeTrue())
})
It("podman network create with invalid IP arguments", func() {
@@ -490,10 +449,9 @@ var _ = Describe("Podman network create", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
nc = podmanTest.Podman([]string{"network", "inspect", net})
nc.WaitWithDefaultTimeout()
Expect(nc).Should(ExitCleanly())
Expect(nc.OutputToString()).To(ContainSubstring(`"mtu": "9000"`))
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
Expect(results[0].Options).To(HaveKeyWithValue("mtu", "9000"))
})
It("podman network create with vlan option", func() {
@@ -503,10 +461,9 @@ var _ = Describe("Podman network create", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
nc = podmanTest.Podman([]string{"network", "inspect", net})
nc.WaitWithDefaultTimeout()
Expect(nc).Should(ExitCleanly())
Expect(nc.OutputToString()).To(ContainSubstring(`"vlan": "9"`))
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
Expect(results[0].Options).To(HaveKeyWithValue("vlan", "9"))
})
It("podman network create with invalid option", func() {
@@ -528,10 +485,9 @@ var _ = Describe("Podman network create", func() {
if !IsRemote() {
Expect(nc.ErrorToString()).To(BeEmpty())
}
nc = podmanTest.Podman([]string{"network", "inspect", net})
nc.WaitWithDefaultTimeout()
Expect(nc).Should(ExitCleanly())
Expect(nc.OutputToString()).To(ContainSubstring(`"dns_enabled": true`))
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
Expect(results[0].DNSEnabled).To(BeTrue())
})
It("podman network create with invalid name", func() {
@@ -552,12 +508,12 @@ var _ = Describe("Podman network create", func() {
Expect(nc).To(ExitCleanly())
Expect(nc.OutputToString()).To(Equal(name))
inspect := podmanTest.Podman([]string{"network", "inspect", name})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitCleanly())
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet1))
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet2))
Expect(inspect.OutputToString()).To(ContainSubstring(`"ipv6_enabled": false`))
results := podmanTest.InspectNetwork(name)
Expect(results).To(HaveLen(1))
Expect(results[0].Subnets).To(HaveLen(2))
Expect(results[0].Subnets[0].Subnet.String()).To(Equal(subnet1))
Expect(results[0].Subnets[1].Subnet.String()).To(Equal(subnet2))
Expect(results[0].IPv6Enabled).To(BeFalse())
})
It("podman network create with multiple subnets dual stack", func() {
@@ -570,12 +526,12 @@ var _ = Describe("Podman network create", func() {
Expect(nc).To(ExitCleanly())
Expect(nc.OutputToString()).To(Equal(name))
inspect := podmanTest.Podman([]string{"network", "inspect", name})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitCleanly())
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet1))
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet2))
Expect(inspect.OutputToString()).To(ContainSubstring(`"ipv6_enabled": true`))
results := podmanTest.InspectNetwork(name)
Expect(results).To(HaveLen(1))
Expect(results[0].Subnets).To(HaveLen(2))
Expect(results[0].Subnets[0].Subnet.String()).To(Equal(subnet1))
Expect(results[0].Subnets[1].Subnet.String()).To(Equal(subnet2))
Expect(results[0].IPv6Enabled).To(BeTrue())
})
It("podman network create with multiple subnets dual stack with gateway and range", func() {
@@ -591,16 +547,16 @@ var _ = Describe("Podman network create", func() {
Expect(nc).To(ExitCleanly())
Expect(nc.OutputToString()).To(Equal(name))
inspect := podmanTest.Podman([]string{"network", "inspect", name})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitCleanly())
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet1))
Expect(inspect.OutputToString()).To(ContainSubstring(`"gateway": "` + gw1))
Expect(inspect.OutputToString()).To(ContainSubstring(`"start_ip": "10.10.3.1",`))
Expect(inspect.OutputToString()).To(ContainSubstring(`"end_ip": "10.10.3.63"`))
Expect(inspect.OutputToString()).To(ContainSubstring(`"subnet": "` + subnet2))
Expect(inspect.OutputToString()).To(ContainSubstring(`"gateway": "` + gw2))
Expect(inspect.OutputToString()).To(ContainSubstring(`"ipv6_enabled": true`))
results := podmanTest.InspectNetwork(name)
Expect(results).To(HaveLen(1))
Expect(results[0].Subnets).To(HaveLen(2))
Expect(results[0].Subnets[0].Subnet.String()).To(Equal(subnet1))
Expect(results[0].Subnets[0].Gateway.String()).To(Equal(gw1))
Expect(results[0].Subnets[0].LeaseRange.StartIP.String()).To(Equal("10.10.3.1"))
Expect(results[0].Subnets[0].LeaseRange.EndIP.String()).To(Equal("10.10.3.63"))
Expect(results[0].Subnets[1].Subnet.String()).To(Equal(subnet2))
Expect(results[0].Subnets[1].Gateway.String()).To(Equal(gw2))
Expect(results[0].IPv6Enabled).To(BeTrue())
})
It("podman network create invalid options with multiple subnets", func() {
@@ -683,14 +639,7 @@ var _ = Describe("Podman network create", func() {
Expect(nc).Should(ExitCleanly())
// Inspect the network configuration
inspect := podmanTest.Podman([]string{"network", "inspect", netName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(netName)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("Name", netName))

View File

@@ -3,12 +3,10 @@
package integration
import (
"encoding/json"
"fmt"
"net"
"time"
"github.com/containers/podman/v6/pkg/domain/entities"
. "github.com/containers/podman/v6/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@@ -542,14 +540,7 @@ var _ = Describe("Podman network", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
inspect := podmanTest.Podman([]string{"network", "inspect", net})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
// JSON the network configuration into something usable
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result).To(HaveField("NetworkInterface", ""))
@@ -568,13 +559,7 @@ var _ = Describe("Podman network", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
inspect := podmanTest.Podman([]string{"network", "inspect", net})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]
@@ -596,13 +581,7 @@ var _ = Describe("Podman network", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
inspect := podmanTest.Podman([]string{"network", "inspect", net})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]
@@ -639,13 +618,7 @@ var _ = Describe("Podman network", func() {
defer podmanTest.removeNetwork(net)
Expect(nc).Should(ExitCleanly())
inspect := podmanTest.Podman([]string{"network", "inspect", net})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(inspect.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]

View File

@@ -3,7 +3,6 @@
package integration
import (
"encoding/json"
"fmt"
"io"
"math/rand"
@@ -15,7 +14,6 @@ import (
"syscall"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/podman/v6/pkg/domain/entities"
. "github.com/containers/podman/v6/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@@ -35,13 +33,7 @@ var _ = Describe("Podman run networking", func() {
defer podmanTest.removeNetwork(net)
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"network", "inspect", net})
session.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net)
Expect(session).Should(ExitCleanly())
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(session.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result.Subnets).To(HaveLen(1))
@@ -81,13 +73,7 @@ var _ = Describe("Podman run networking", func() {
defer podmanTest.removeNetwork(net)
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"network", "inspect", net})
session.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net)
Expect(session).Should(ExitCleanly())
var results []entities.NetworkInspectReport
err := json.Unmarshal([]byte(session.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results := podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
result := results[0]
Expect(result.Subnets).To(HaveLen(1))
@@ -111,12 +97,7 @@ var _ = Describe("Podman run networking", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"network", "inspect", net})
session.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net)
Expect(session).Should(ExitCleanly())
err = json.Unmarshal([]byte(session.OutputToString()), &results)
Expect(err).ToNot(HaveOccurred())
results = podmanTest.InspectNetwork(net)
Expect(results).To(HaveLen(1))
Expect(results[0].NetworkDNSServers).To(Equal([]string{"127.0.0.253", "127.0.0.254", "127.0.0.255"}))