podman

Форк
0
/
run_staticip_test.go 
118 строк · 4.1 Кб
1
package integration
2

3
import (
4
	"fmt"
5
	"net/http"
6
	"time"
7

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"
12
)
13

14
var _ = Describe("Podman run with --ip flag", func() {
15

16
	BeforeEach(func() {
17
		SkipIfRootless("rootless does not support --ip without network")
18
	})
19

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())
24
	})
25

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())
30
	})
31

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())
36
	})
37

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"))
44
	})
45

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())
53

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"))
58
	})
59

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"))
66
	})
67

68
	It("Podman run with --network net:ip=,mac=,interface_name=", func() {
69
		ip := GetSafeIPAddress()
70
		mac := "44:33:22:11:00:99"
71
		intName := "myeth"
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))
78
	})
79

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())
85

86
		// This test should not use a proxy
87
		client := &http.Client{
88
			Transport: &http.Transport{
89
				Proxy: nil,
90
			},
91
		}
92

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 {
96
				break
97
			}
98
			if retries == 1 {
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.")
104
			}
105

106
			if err != nil {
107
				GinkgoWriter.Printf("nginx not ready yet; error=%v; %d retries left...\n", err, retries)
108
			} else {
109
				GinkgoWriter.Printf("nginx not ready yet; response=%v; %d retries left...\n", response.StatusCode, retries)
110
			}
111
			time.Sleep(1 * time.Second)
112
		}
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))
117
	})
118
})
119

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.