test/e2e: rework some --expose tests

Stop using iptables to check anything, it does not work rootless and
will no longer work with nftables which will be used in the future.

Also fix up the test that say podman run to actually use podman run and
then just check via inspect that the ports are set correctly.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-07-10 13:13:13 +02:00
parent 9945981afb
commit c4b2015e3a

View File

@ -187,17 +187,6 @@ var _ = Describe("Podman run networking", func() {
Expect(session.OutputToString()).To(ContainSubstring("nameserver 1.1.1.1"))
})
It("podman run network expose port 222", func() {
SkipIfRootless("iptables is not supported for rootless users")
session := podmanTest.Podman([]string{"run", "-dt", "--expose", "222-223", "-P", ALPINE, "/bin/sh"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
results := SystemExec("iptables", []string{"-t", "nat", "-nvL"})
Expect(results).Should(ExitCleanly())
Expect(results.OutputToString()).To(ContainSubstring("222"))
Expect(results.OutputToString()).To(ContainSubstring("223"))
})
It("podman run -p 80", func() {
name := "testctr"
session := podmanTest.Podman([]string{"create", "-t", "-p", "80", "--name", name, ALPINE, "/bin/sh"})
@ -361,7 +350,7 @@ var _ = Describe("Podman run networking", func() {
It("podman run --expose 80 -P", func() {
name := "testctr"
session := podmanTest.Podman([]string{"create", "-t", "--expose", "80", "-P", "--name", name, ALPINE, "/bin/sh"})
session := podmanTest.Podman([]string{"run", "-d", "--expose", "80", "-P", "--name", name, ALPINE, "sleep", "100"})
session.WaitWithDefaultTimeout()
inspectOut := podmanTest.InspectContainer(name)
Expect(inspectOut).To(HaveLen(1))
@ -373,7 +362,7 @@ var _ = Describe("Podman run networking", func() {
It("podman run --expose 80/udp -P", func() {
name := "testctr"
session := podmanTest.Podman([]string{"create", "-t", "--expose", "80/udp", "-P", "--name", name, ALPINE, "/bin/sh"})
session := podmanTest.Podman([]string{"run", "-d", "--expose", "80/udp", "-P", "--name", name, ALPINE, "sleep", "100"})
session.WaitWithDefaultTimeout()
inspectOut := podmanTest.InspectContainer(name)
Expect(inspectOut).To(HaveLen(1))
@ -383,6 +372,22 @@ var _ = Describe("Podman run networking", func() {
Expect(inspectOut[0].NetworkSettings.Ports["80/udp"][0]).To(HaveField("HostIP", "0.0.0.0"))
})
It("podman run --expose port range", func() {
name := "testctr"
session := podmanTest.Podman([]string{"run", "-d", "--expose", "222-223", "-P", "--name", name, ALPINE, "sleep", "100"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
inspectOut := podmanTest.InspectContainer(name)
Expect(inspectOut).To(HaveLen(1))
Expect(inspectOut[0].NetworkSettings.Ports).To(HaveLen(2))
Expect(inspectOut[0].NetworkSettings.Ports["222/tcp"]).To(HaveLen(1))
Expect(inspectOut[0].NetworkSettings.Ports["222/tcp"][0].HostPort).To(Not(Equal("0")))
Expect(inspectOut[0].NetworkSettings.Ports["222/tcp"][0]).To(HaveField("HostIP", "0.0.0.0"))
Expect(inspectOut[0].NetworkSettings.Ports["223/tcp"]).To(HaveLen(1))
Expect(inspectOut[0].NetworkSettings.Ports["223/tcp"][0].HostPort).To(Not(Equal("0")))
Expect(inspectOut[0].NetworkSettings.Ports["223/tcp"][0]).To(HaveField("HostIP", "0.0.0.0"))
})
It("podman run --expose 80 -p 80", func() {
name := "testctr"
session := podmanTest.Podman([]string{"create", "-t", "--expose", "80", "-p", "80", "--name", name, ALPINE, "/bin/sh"})