8
. "github.com/containers/podman/v5/test/utils"
9
"github.com/containers/storage/pkg/stringid"
10
. "github.com/onsi/ginkgo/v2"
11
. "github.com/onsi/gomega"
14
var _ = Describe("Podman run with --ip flag", func() {
17
SkipIfRootless("rootless does not support --ip without network")
20
It("Podman run --ip with garbage address", func() {
21
result := podmanTest.Podman([]string{"run", "--ip", "114232346", ALPINE, "ls"})
22
result.WaitWithDefaultTimeout()
23
Expect(result).To(ExitWithError())
26
It("Podman run --ip with v6 address", func() {
27
result := podmanTest.Podman([]string{"run", "--ip", "2001:db8:bad:beef::1", ALPINE, "ls"})
28
result.WaitWithDefaultTimeout()
29
Expect(result).To(ExitWithError())
32
It("Podman run --ip with non-allocatable IP", func() {
33
result := podmanTest.Podman([]string{"run", "--ip", "203.0.113.124", ALPINE, "ls"})
34
result.WaitWithDefaultTimeout()
35
Expect(result).To(ExitWithError())
38
It("Podman run with specified static IP has correct IP", func() {
39
ip := GetSafeIPAddress()
40
result := podmanTest.Podman([]string{"run", "--ip", ip, ALPINE, "ip", "addr"})
41
result.WaitWithDefaultTimeout()
42
Expect(result).Should(ExitCleanly())
43
Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
46
It("Podman run with specified static IPv6 has correct IP", func() {
47
netName := "ipv6-" + stringid.GenerateRandomID()
48
ipv6 := "fd46:db93:aa76:ac37::10"
49
net := podmanTest.Podman([]string{"network", "create", "--subnet", "fd46:db93:aa76:ac37::/64", netName})
50
net.WaitWithDefaultTimeout()
51
defer podmanTest.removeNetwork(netName)
52
Expect(net).To(ExitCleanly())
54
result := podmanTest.Podman([]string{"run", "--network", netName, "--ip6", ipv6, ALPINE, "ip", "addr"})
55
result.WaitWithDefaultTimeout()
56
Expect(result).Should(ExitCleanly())
57
Expect(result.OutputToString()).To(ContainSubstring(ipv6 + "/64"))
60
It("Podman run with --network bridge:ip=", func() {
61
ip := GetSafeIPAddress()
62
result := podmanTest.Podman([]string{"run", "--network", "bridge:ip=" + ip, ALPINE, "ip", "addr"})
63
result.WaitWithDefaultTimeout()
64
Expect(result).Should(ExitCleanly())
65
Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
68
It("Podman run with --network net:ip=,mac=,interface_name=", func() {
69
ip := GetSafeIPAddress()
70
mac := "44:33:22:11:00:99"
72
result := podmanTest.Podman([]string{"run", "--network", "bridge:ip=" + ip + ",mac=" + mac + ",interface_name=" + intName, ALPINE, "ip", "addr"})
73
result.WaitWithDefaultTimeout()
74
Expect(result).Should(ExitCleanly())
75
Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
76
Expect(result.OutputToString()).To(ContainSubstring(mac))
77
Expect(result.OutputToString()).To(ContainSubstring(intName))
80
It("Podman run two containers with the same IP", func() {
81
ip := GetSafeIPAddress()
82
result := podmanTest.Podman([]string{"run", "-d", "--name", "nginx", "--ip", ip, NGINX_IMAGE})
83
result.WaitWithDefaultTimeout()
84
Expect(result).Should(ExitCleanly())
86
// This test should not use a proxy
87
client := &http.Client{
88
Transport: &http.Transport{
93
for retries := 20; retries > 0; retries-- {
94
response, err := client.Get(fmt.Sprintf("http://%s", ip))
95
if err == nil && response.StatusCode == http.StatusOK {
99
logps := podmanTest.Podman([]string{"ps", "-a"})
100
logps.WaitWithDefaultTimeout()
101
logps = podmanTest.Podman([]string{"logs", "nginx"})
102
logps.WaitWithDefaultTimeout()
103
Fail("Timed out waiting for nginx container, see ps & log above.")
107
GinkgoWriter.Printf("nginx not ready yet; error=%v; %d retries left...\n", err, retries)
109
GinkgoWriter.Printf("nginx not ready yet; response=%v; %d retries left...\n", response.StatusCode, retries)
111
time.Sleep(1 * time.Second)
113
result = podmanTest.Podman([]string{"run", "--ip", ip, ALPINE, "ip", "addr"})
114
result.WaitWithDefaultTimeout()
115
Expect(result).To(ExitWithError())
116
Expect(result.ErrorToString()).To(ContainSubstring(" address %s ", ip))