summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-03-15 06:34:07 -0400
committerGitHub <noreply@github.com>2022-03-15 06:34:07 -0400
commit68ce83fe919f2d37762b8b746a73495f45e550f3 (patch)
treec9da0cb1cb807837ab220eb98360f05aa6dea687 /test
parent758f2c7a094a3654af98d9365b7f975b7bd12ff4 (diff)
parent8cfdddf5092b5d3fc0c154b241325ecbf4480825 (diff)
downloadpodman-68ce83fe919f2d37762b8b746a73495f45e550f3.tar.gz
podman-68ce83fe919f2d37762b8b746a73495f45e550f3.tar.bz2
podman-68ce83fe919f2d37762b8b746a73495f45e550f3.zip
Merge pull request #13238 from lsm5/e2e-aardvark
test/e2e: add aardvark specific tests
Diffstat (limited to 'test')
-rw-r--r--test/e2e/common_test.go26
-rw-r--r--test/e2e/run_aardvark_test.go314
2 files changed, 339 insertions, 1 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index b1cd76d27..bc6d89fad 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -896,7 +896,7 @@ func removeConf(confPath string) {
}
}
-// generateNetworkConfig generates a cni config with a random name
+// generateNetworkConfig generates a CNI or Netavark config with a random name
// it returns the network name and the filepath
func generateNetworkConfig(p *PodmanTestIntegration) (string, string) {
var (
@@ -1042,3 +1042,27 @@ func ncz(port int) bool {
func createNetworkName(name string) string {
return name + stringid.GenerateNonCryptoID()[:10]
}
+
+var IPRegex = `(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`
+
+// digShort execs into the given container and does a dig lookup with a timeout
+// backoff. If it gets a response, it ensures that the output is in the correct
+// format and iterates a string array for match
+func digShort(container, lookupName string, matchNames []string, p *PodmanTestIntegration) string {
+ digInterval := time.Millisecond * 250
+ for i := 0; i < 6; i++ {
+ time.Sleep(digInterval * time.Duration(i))
+ dig := p.Podman([]string{"exec", container, "dig", "+short", lookupName})
+ dig.WaitWithDefaultTimeout()
+ if dig.ExitCode() == 0 {
+ output := dig.OutputToString()
+ Expect(output).To(MatchRegexp(IPRegex))
+ for _, name := range matchNames {
+ Expect(output).To(Equal(name))
+ }
+ return output
+ }
+ }
+ Fail("dns is not responding")
+ return ""
+}
diff --git a/test/e2e/run_aardvark_test.go b/test/e2e/run_aardvark_test.go
new file mode 100644
index 000000000..c82f614a6
--- /dev/null
+++ b/test/e2e/run_aardvark_test.go
@@ -0,0 +1,314 @@
+package integration
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ . "github.com/containers/podman/v4/test/utils"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
+)
+
+var _ = Describe("Podman run networking", func() {
+ var (
+ tempdir string
+ err error
+ podmanTest *PodmanTestIntegration
+ )
+
+ BeforeEach(func() {
+ tempdir, err = CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest = PodmanTestCreate(tempdir)
+ podmanTest.Setup()
+ podmanTest.SeedImages()
+ SkipIfCNI(podmanTest)
+ })
+
+ AfterEach(func() {
+ podmanTest.Cleanup()
+ f := CurrentGinkgoTestDescription()
+ processTestResult(f)
+
+ })
+
+ It("Aardvark Test 1: One container", func() {
+ netName := createNetworkName("Test")
+ session := podmanTest.Podman([]string{"network", "create", netName})
+ session.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netName)
+ Expect(session).Should(Exit(0))
+
+ ctrID := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, nginx})
+ ctrID.WaitWithDefaultTimeout()
+ Expect(ctrID).Should(Exit(0))
+ cid := ctrID.OutputToString()
+
+ ctrIP := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid})
+ ctrIP.WaitWithDefaultTimeout()
+ Expect(ctrIP).Should(Exit(0))
+ cip := ctrIP.OutputToString()
+ Expect(cip).To(MatchRegexp(IPRegex))
+
+ _ = digShort(cid, "aone", []string{cip}, podmanTest)
+
+ reverseLookup := podmanTest.Podman([]string{"exec", cid, "dig", "+short", "-x", cip})
+ reverseLookup.WaitWithDefaultTimeout()
+ Expect(reverseLookup).Should(Exit(0))
+ revListArray := reverseLookup.OutputToStringArray()
+ Expect(revListArray).Should(HaveLen(2))
+ Expect(strings.TrimRight(revListArray[0], ".")).To(Equal("aone"))
+ Expect(strings.TrimRight(revListArray[1], ".")).To(Equal(cid[:12]))
+
+ })
+
+ It("Aardvark Test 2: Two containers, same subnet", func() {
+ netName := createNetworkName("Test")
+ session := podmanTest.Podman([]string{"network", "create", netName})
+ session.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netName)
+ Expect(session).Should(Exit(0))
+
+ ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, nginx})
+ ctr1.WaitWithDefaultTimeout()
+ Expect(ctr1).Should(Exit(0))
+ cid1 := ctr1.OutputToString()
+
+ ctrIP1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid1})
+ ctrIP1.WaitWithDefaultTimeout()
+ Expect(ctrIP1).Should(Exit(0))
+ cip1 := ctrIP1.OutputToString()
+ Expect(cip1).To(MatchRegexp(IPRegex))
+
+ ctr2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwo", "--network", netName, nginx})
+ ctr2.WaitWithDefaultTimeout()
+ Expect(ctr2).Should(Exit(0))
+ cid2 := ctr2.OutputToString()
+
+ ctrIP2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid2})
+ ctrIP2.WaitWithDefaultTimeout()
+ Expect(ctrIP2).Should(Exit(0))
+ cip2 := ctrIP2.OutputToString()
+ Expect(cip2).To(MatchRegexp(IPRegex))
+
+ _ = digShort("aone", "atwo", []string{cip2}, podmanTest)
+
+ _ = digShort("atwo", "aone", []string{cip1}, podmanTest)
+
+ reverseLookup12 := podmanTest.Podman([]string{"exec", cid1, "dig", "+short", "-x", cip2})
+ reverseLookup12.WaitWithDefaultTimeout()
+ Expect(reverseLookup12).Should(Exit(0))
+ revListArray12 := reverseLookup12.OutputToStringArray()
+ Expect(revListArray12).Should(HaveLen(2))
+ Expect(strings.TrimRight(revListArray12[0], ".")).To(Equal("atwo"))
+ Expect(strings.TrimRight(revListArray12[1], ".")).To(Equal(cid2[:12]))
+
+ reverseLookup21 := podmanTest.Podman([]string{"exec", cid2, "dig", "+short", "-x", cip1})
+ reverseLookup21.WaitWithDefaultTimeout()
+ Expect(reverseLookup21).Should(Exit(0))
+ revListArray21 := reverseLookup21.OutputToStringArray()
+ Expect(revListArray21).Should(HaveLen(2))
+ Expect(strings.TrimRight(revListArray21[0], ".")).To(Equal("aone"))
+ Expect(strings.TrimRight(revListArray21[1], ".")).To(Equal(cid1[:12]))
+
+ })
+
+ It("Aardvark Test 3: Two containers, same subnet w/aliases", func() {
+ netName := createNetworkName("Test")
+ session := podmanTest.Podman([]string{"network", "create", netName})
+ session.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netName)
+ Expect(session).Should(Exit(0))
+
+ ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, "--network-alias", "alias_a1,alias_1a", nginx})
+ ctr1.WaitWithDefaultTimeout()
+ Expect(ctr1).Should(Exit(0))
+
+ ctrIP1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), "aone"})
+ ctrIP1.WaitWithDefaultTimeout()
+ Expect(ctrIP1).Should(Exit(0))
+ cip1 := ctrIP1.OutputToString()
+ Expect(cip1).To(MatchRegexp(IPRegex))
+
+ ctr2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwo", "--network", netName, "--network-alias", "alias_a2,alias_2a", nginx})
+ ctr2.WaitWithDefaultTimeout()
+ Expect(ctr2).Should(Exit(0))
+
+ ctrIP2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), "atwo"})
+ ctrIP2.WaitWithDefaultTimeout()
+ Expect(ctrIP2).Should(Exit(0))
+ cip2 := ctrIP2.OutputToString()
+ Expect(cip2).To(MatchRegexp(IPRegex))
+
+ _ = digShort("aone", "atwo", []string{cip2}, podmanTest)
+
+ _ = digShort("aone", "alias_a2", []string{cip2}, podmanTest)
+
+ _ = digShort("aone", "alias_2a", []string{cip2}, podmanTest)
+
+ _ = digShort("atwo", "aone", []string{cip1}, podmanTest)
+
+ _ = digShort("atwo", "alias_a1", []string{cip1}, podmanTest)
+
+ _ = digShort("atwo", "alias_1a", []string{cip1}, podmanTest)
+
+ })
+
+ It("Aardvark Test 4: Two containers, different subnets", func() {
+ netNameA := createNetworkName("TestA")
+ sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
+ sessionA.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameA)
+ Expect(sessionA).Should(Exit(0))
+
+ netNameB := createNetworkName("TestB")
+ sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
+ sessionB.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameB)
+ Expect(sessionB).Should(Exit(0))
+
+ ctrA1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, nginx})
+ ctrA1.WaitWithDefaultTimeout()
+ cidA1 := ctrA1.OutputToString()
+
+ ctrB1 := podmanTest.Podman([]string{"run", "-dt", "--name", "bone", "--network", netNameB, nginx})
+ ctrB1.WaitWithDefaultTimeout()
+ cidB1 := ctrB1.OutputToString()
+
+ ctrIPA1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA1})
+ ctrIPA1.WaitWithDefaultTimeout()
+ Expect(ctrIPA1).Should(Exit(0))
+ cipA1 := ctrIPA1.OutputToString()
+ Expect(cipA1).To(MatchRegexp(IPRegex))
+
+ ctrIPB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidB1})
+ ctrIPB1.WaitWithDefaultTimeout()
+ Expect(ctrIPB1).Should(Exit(0))
+ cipB1 := ctrIPB1.OutputToString()
+ Expect(cipB1).To(MatchRegexp(IPRegex))
+
+ resA1B1 := podmanTest.Podman([]string{"exec", "aone", "dig", "+short", "bone"})
+ resA1B1.WaitWithDefaultTimeout()
+ Expect(resA1B1).Should(Exit(0))
+ Expect(resA1B1.OutputToString()).To(Equal(""))
+
+ resB1A1 := podmanTest.Podman([]string{"exec", "bone", "dig", "+short", "aone"})
+ resB1A1.WaitWithDefaultTimeout()
+ Expect(resB1A1).Should(Exit(0))
+ Expect(resB1A1.OutputToString()).To(Equal(""))
+ })
+
+ It("Aardvark Test 5: Two containers on their own subnets, one container on both", func() {
+ netNameA := createNetworkName("TestA")
+ sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
+ sessionA.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameA)
+ Expect(sessionA).Should(Exit(0))
+
+ netNameB := createNetworkName("TestB")
+ sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
+ sessionB.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameB)
+ Expect(sessionB).Should(Exit(0))
+
+ ctrA1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, nginx})
+ ctrA1.WaitWithDefaultTimeout()
+ cidA1 := ctrA1.OutputToString()
+
+ ctrIPA1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA1})
+ ctrIPA1.WaitWithDefaultTimeout()
+ Expect(ctrIPA1).Should(Exit(0))
+ cipA1 := ctrIPA1.OutputToString()
+ Expect(cipA1).To(MatchRegexp(IPRegex))
+
+ ctrB1 := podmanTest.Podman([]string{"run", "-dt", "--name", "bone", "--network", netNameB, nginx})
+ ctrB1.WaitWithDefaultTimeout()
+ cidB1 := ctrB1.OutputToString()
+
+ ctrIPB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidB1})
+ ctrIPB1.WaitWithDefaultTimeout()
+ Expect(ctrIPB1).Should(Exit(0))
+ cipB1 := ctrIPB1.OutputToString()
+ Expect(cipB1).To(MatchRegexp(IPRegex))
+
+ ctrA2B2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwobtwo", "--network", netNameA, "--network", netNameB, nginx})
+ ctrA2B2.WaitWithDefaultTimeout()
+ cidA2B2 := ctrA2B2.OutputToString()
+
+ ctrIPA2B21 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA2B2})
+ ctrIPA2B21.WaitWithDefaultTimeout()
+ Expect(ctrIPA2B21).Should(Exit(0))
+ cipA2B21 := ctrIPA2B21.OutputToString()
+ Expect(cipA2B21).To(MatchRegexp(IPRegex))
+
+ ctrIPA2B22 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidA2B2})
+ ctrIPA2B22.WaitWithDefaultTimeout()
+ Expect(ctrIPA2B22).Should(Exit(0))
+ cipA2B22 := ctrIPA2B22.OutputToString()
+ Expect(cipA2B22).To(MatchRegexp(IPRegex))
+
+ _ = digShort("aone", "atwobtwo", []string{cipA2B21}, podmanTest)
+
+ _ = digShort("bone", "atwobtwo", []string{cipA2B22}, podmanTest)
+
+ _ = digShort("atwobtwo", "aone", []string{cipA1}, podmanTest)
+
+ _ = digShort("atwobtwo", "bone", []string{cipB1}, podmanTest)
+ })
+
+ It("Aardvark Test 6: Three subnets, first container on 1/2 and second on 2/3, w/ network aliases", func() {
+ netNameA := createNetworkName("TestA")
+ sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
+ sessionA.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameA)
+ Expect(sessionA).Should(Exit(0))
+
+ netNameB := createNetworkName("TestB")
+ sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
+ sessionB.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameB)
+ Expect(sessionB).Should(Exit(0))
+
+ netNameC := createNetworkName("TestC")
+ sessionC := podmanTest.Podman([]string{"network", "create", netNameC})
+ sessionC.WaitWithDefaultTimeout()
+ defer podmanTest.removeNetwork(netNameC)
+ Expect(sessionC).Should(Exit(0))
+
+ ctrA := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, nginx})
+ ctrA.WaitWithDefaultTimeout()
+ Expect(ctrA).Should(Exit(0))
+
+ ctrC := podmanTest.Podman([]string{"run", "-dt", "--name", "cone", "--network", netNameC, nginx})
+ ctrC.WaitWithDefaultTimeout()
+ Expect(ctrC).Should(Exit(0))
+
+ ctrnetAB1 := podmanTest.Podman([]string{"network", "connect", "--alias", "testB1_nw", netNameB, "aone"})
+ ctrnetAB1.WaitWithDefaultTimeout()
+ Expect(ctrnetAB1).Should(Exit(0))
+
+ ctrIPAB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), "aone"})
+ ctrIPAB1.WaitWithDefaultTimeout()
+ Expect(ctrIPAB1).Should(Exit(0))
+ cipAB1 := ctrIPAB1.OutputToString()
+
+ ctrnetCB2 := podmanTest.Podman([]string{"network", "connect", "--alias", "testB2_nw", netNameB, "cone"})
+ ctrnetCB2.WaitWithDefaultTimeout()
+ Expect(ctrnetCB2).Should(Exit(0))
+
+ ctrIPCB2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), "cone"})
+ ctrIPCB2.WaitWithDefaultTimeout()
+ Expect(ctrIPCB2).Should(Exit(0))
+ cipCB2 := ctrIPCB2.OutputToString()
+
+ _ = digShort("aone", "testB2_nw", []string{cipCB2}, podmanTest)
+
+ _ = digShort("cone", "testB1_nw", []string{cipAB1}, podmanTest)
+
+ })
+
+})