Merge pull request #16684 from sstosh/e2e-proxy

e2e: fix e2e tests in proxy environment
This commit is contained in:
OpenShift Merge Robot 2022-12-06 19:57:10 -05:00 committed by GitHub
commit 1b62e9049e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 17 deletions

View File

@ -434,7 +434,8 @@ func (p *PodmanTestIntegration) RunTopContainer(name string) *PodmanSessionInteg
// RunTopContainerWithArgs runs a simple container in the background that // RunTopContainerWithArgs runs a simple container in the background that
// runs top. If the name passed != "", it will have a name, command args can also be passed in // runs top. If the name passed != "", it will have a name, command args can also be passed in
func (p *PodmanTestIntegration) RunTopContainerWithArgs(name string, args []string) *PodmanSessionIntegration { func (p *PodmanTestIntegration) RunTopContainerWithArgs(name string, args []string) *PodmanSessionIntegration {
var podmanArgs = []string{"run"} // In proxy environment, some tests need to the --http-proxy=false option (#16684)
var podmanArgs = []string{"run", "--http-proxy=false"}
if name != "" { if name != "" {
podmanArgs = append(podmanArgs, "--name", name) podmanArgs = append(podmanArgs, "--name", name)
} }
@ -476,6 +477,17 @@ func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSes
return session, session.OutputToString() return session, session.OutputToString()
} }
// RunContainerWithNetworkTest runs the fedoraMinimal curl with the specified network mode.
func (p *PodmanTestIntegration) RunContainerWithNetworkTest(mode string) *PodmanSessionIntegration {
var podmanArgs = []string{"run"}
if mode != "" {
podmanArgs = append(podmanArgs, "--network", mode)
}
podmanArgs = append(podmanArgs, fedoraMinimal, "curl", "-k", "-o", "/dev/null", "http://www.podman.io:80")
session := p.Podman(podmanArgs)
return session
}
func (p *PodmanTestIntegration) RunLsContainerInPod(name, pod string) (*PodmanSessionIntegration, int, string) { func (p *PodmanTestIntegration) RunLsContainerInPod(name, pod string) (*PodmanSessionIntegration, int, string) {
var podmanArgs = []string{"run", "--pod", pod} var podmanArgs = []string{"run", "--pod", pod}
if name != "" { if name != "" {

View File

@ -1251,7 +1251,8 @@ USER test1`
ctrName := "gen-kube-env-ctr" ctrName := "gen-kube-env-ctr"
podName := "gen-kube-env" podName := "gen-kube-env"
session1 := podmanTest.Podman([]string{"run", "-d", "--pod", "new:" + podName, "--name", ctrName, // In proxy environment, this test needs to the --http-proxy=false option (#16684)
session1 := podmanTest.Podman([]string{"run", "-d", "--http-proxy=false", "--pod", "new:" + podName, "--name", ctrName,
"-e", "FOO=bar", "-e", "FOO=bar",
"-e", "HELLO=WORLD", "-e", "HELLO=WORLD",
"alpine", "top"}) "alpine", "top"})

View File

@ -42,38 +42,37 @@ var _ = Describe("Podman run networking", func() {
}) })
It("podman run network connection with default bridge", func() { It("podman run network connection with default bridge", func() {
session := podmanTest.Podman([]string{"run", "-dt", ALPINE, "wget", "www.podman.io"}) session := podmanTest.RunContainerWithNetworkTest("")
session.Wait(90) session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })
It("podman run network connection with host", func() { It("podman run network connection with host", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--network", "host", ALPINE, "wget", "www.podman.io"}) session := podmanTest.RunContainerWithNetworkTest("host")
session.Wait(90) session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })
It("podman run network connection with default", func() { It("podman run network connection with default", func() {
session := podmanTest.Podman([]string{"run", "--network", "default", ALPINE, "wget", "www.podman.io"}) session := podmanTest.RunContainerWithNetworkTest("default")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })
It("podman run network connection with none", func() { It("podman run network connection with none", func() {
session := podmanTest.Podman([]string{"run", "--network", "none", ALPINE, "wget", "www.podman.io"}) session := podmanTest.RunContainerWithNetworkTest("none")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1)) if _, found := os.LookupEnv("http_proxy"); found {
Expect(session.ErrorToString()).To(ContainSubstring("wget: bad address 'www.podman.io'")) Expect(session).Should(Exit(5))
Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve proxy:"))
} else {
Expect(session).Should(Exit(6))
Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve host: www.podman.io"))
}
}) })
It("podman run network connection with private", func() { It("podman run network connection with private", func() {
session := podmanTest.Podman([]string{"run", "--network", "private", ALPINE, "wget", "www.podman.io"}) session := podmanTest.RunContainerWithNetworkTest("private")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
It("podman run network connection with loopback", func() {
session := podmanTest.Podman([]string{"run", "--network", "host", ALPINE, "wget", "www.podman.io"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })

View File

@ -65,6 +65,8 @@ var _ = Describe("Systemd activate", func() {
addr := net.JoinHostPort(host, strconv.Itoa(port)) addr := net.JoinHostPort(host, strconv.Itoa(port))
activateSession := testUtils.StartSystemExec(activate, []string{ activateSession := testUtils.StartSystemExec(activate, []string{
"-E", "http_proxy", "-E", "https_proxy", "-E", "no_proxy",
"-E", "HTTP_PROXY", "-E", "HTTPS_PROXY", "-E", "NO_PROXY",
"--listen", addr, "--listen", addr,
podmanTest.PodmanBinary, podmanTest.PodmanBinary,
"--root=" + filepath.Join(tempDir, "server_root"), "--root=" + filepath.Join(tempDir, "server_root"),