github.com/containers/podman/v5@v5.1.0-rc1/test/e2e/run_aardvark_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	. "github.com/containers/podman/v5/test/utils"
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Podman run networking", func() {
    13  
    14  	BeforeEach(func() {
    15  		SkipIfCNI(podmanTest)
    16  	})
    17  
    18  	It("Aardvark Test 1: One container", func() {
    19  		netName := createNetworkName("Test")
    20  		session := podmanTest.Podman([]string{"network", "create", netName})
    21  		session.WaitWithDefaultTimeout()
    22  		defer podmanTest.removeNetwork(netName)
    23  		Expect(session).Should(ExitCleanly())
    24  
    25  		ctrID := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, NGINX_IMAGE})
    26  		ctrID.WaitWithDefaultTimeout()
    27  		Expect(ctrID).Should(ExitCleanly())
    28  		cid := ctrID.OutputToString()
    29  
    30  		ctrIP := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid})
    31  		ctrIP.WaitWithDefaultTimeout()
    32  		Expect(ctrIP).Should(ExitCleanly())
    33  		cip := ctrIP.OutputToString()
    34  		Expect(cip).To(MatchRegexp(IPRegex))
    35  
    36  		digShort(cid, "aone", cip, podmanTest)
    37  
    38  		reverseLookup := podmanTest.Podman([]string{"exec", cid, "dig", "+short", "-x", cip})
    39  		reverseLookup.WaitWithDefaultTimeout()
    40  		Expect(reverseLookup).Should(ExitCleanly())
    41  		revListArray := reverseLookup.OutputToStringArray()
    42  		Expect(revListArray).Should(HaveLen(2))
    43  		Expect(strings.TrimRight(revListArray[0], ".")).To(Equal("aone"))
    44  		Expect(strings.TrimRight(revListArray[1], ".")).To(Equal(cid[:12]))
    45  
    46  	})
    47  
    48  	It("Aardvark Test 2: Two containers, same subnet", func() {
    49  		netName := createNetworkName("Test")
    50  		session := podmanTest.Podman([]string{"network", "create", netName})
    51  		session.WaitWithDefaultTimeout()
    52  		defer podmanTest.removeNetwork(netName)
    53  		Expect(session).Should(ExitCleanly())
    54  
    55  		ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, NGINX_IMAGE})
    56  		ctr1.WaitWithDefaultTimeout()
    57  		Expect(ctr1).Should(ExitCleanly())
    58  		cid1 := ctr1.OutputToString()
    59  
    60  		ctrIP1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid1})
    61  		ctrIP1.WaitWithDefaultTimeout()
    62  		Expect(ctrIP1).Should(ExitCleanly())
    63  		cip1 := ctrIP1.OutputToString()
    64  		Expect(cip1).To(MatchRegexp(IPRegex))
    65  
    66  		ctr2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwo", "--network", netName, NGINX_IMAGE})
    67  		ctr2.WaitWithDefaultTimeout()
    68  		Expect(ctr2).Should(ExitCleanly())
    69  		cid2 := ctr2.OutputToString()
    70  
    71  		ctrIP2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), cid2})
    72  		ctrIP2.WaitWithDefaultTimeout()
    73  		Expect(ctrIP2).Should(ExitCleanly())
    74  		cip2 := ctrIP2.OutputToString()
    75  		Expect(cip2).To(MatchRegexp(IPRegex))
    76  
    77  		digShort("aone", "atwo", cip2, podmanTest)
    78  
    79  		digShort("atwo", "aone", cip1, podmanTest)
    80  
    81  		reverseLookup12 := podmanTest.Podman([]string{"exec", cid1, "dig", "+short", "-x", cip2})
    82  		reverseLookup12.WaitWithDefaultTimeout()
    83  		Expect(reverseLookup12).Should(ExitCleanly())
    84  		revListArray12 := reverseLookup12.OutputToStringArray()
    85  		Expect(revListArray12).Should(HaveLen(2))
    86  		Expect(strings.TrimRight(revListArray12[0], ".")).To(Equal("atwo"))
    87  		Expect(strings.TrimRight(revListArray12[1], ".")).To(Equal(cid2[:12]))
    88  
    89  		reverseLookup21 := podmanTest.Podman([]string{"exec", cid2, "dig", "+short", "-x", cip1})
    90  		reverseLookup21.WaitWithDefaultTimeout()
    91  		Expect(reverseLookup21).Should(ExitCleanly())
    92  		revListArray21 := reverseLookup21.OutputToStringArray()
    93  		Expect(revListArray21).Should(HaveLen(2))
    94  		Expect(strings.TrimRight(revListArray21[0], ".")).To(Equal("aone"))
    95  		Expect(strings.TrimRight(revListArray21[1], ".")).To(Equal(cid1[:12]))
    96  
    97  	})
    98  
    99  	It("Aardvark Test 3: Two containers, same subnet w/aliases", func() {
   100  		netName := createNetworkName("Test")
   101  		session := podmanTest.Podman([]string{"network", "create", netName})
   102  		session.WaitWithDefaultTimeout()
   103  		defer podmanTest.removeNetwork(netName)
   104  		Expect(session).Should(ExitCleanly())
   105  
   106  		ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netName, "--network-alias", "alias_a1,alias_1a", NGINX_IMAGE})
   107  		ctr1.WaitWithDefaultTimeout()
   108  		Expect(ctr1).Should(ExitCleanly())
   109  
   110  		ctrIP1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), "aone"})
   111  		ctrIP1.WaitWithDefaultTimeout()
   112  		Expect(ctrIP1).Should(ExitCleanly())
   113  		cip1 := ctrIP1.OutputToString()
   114  		Expect(cip1).To(MatchRegexp(IPRegex))
   115  
   116  		ctr2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwo", "--network", netName, "--network-alias", "alias_a2,alias_2a", NGINX_IMAGE})
   117  		ctr2.WaitWithDefaultTimeout()
   118  		Expect(ctr2).Should(ExitCleanly())
   119  
   120  		ctrIP2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netName), "atwo"})
   121  		ctrIP2.WaitWithDefaultTimeout()
   122  		Expect(ctrIP2).Should(ExitCleanly())
   123  		cip2 := ctrIP2.OutputToString()
   124  		Expect(cip2).To(MatchRegexp(IPRegex))
   125  
   126  		digShort("aone", "atwo", cip2, podmanTest)
   127  
   128  		digShort("aone", "alias_a2", cip2, podmanTest)
   129  
   130  		digShort("aone", "alias_2a", cip2, podmanTest)
   131  
   132  		digShort("atwo", "aone", cip1, podmanTest)
   133  
   134  		digShort("atwo", "alias_a1", cip1, podmanTest)
   135  
   136  		digShort("atwo", "alias_1a", cip1, podmanTest)
   137  
   138  	})
   139  
   140  	It("Aardvark Test 4: Two containers, different subnets", func() {
   141  		netNameA := createNetworkName("TestA")
   142  		sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
   143  		sessionA.WaitWithDefaultTimeout()
   144  		defer podmanTest.removeNetwork(netNameA)
   145  		Expect(sessionA).Should(ExitCleanly())
   146  
   147  		netNameB := createNetworkName("TestB")
   148  		sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
   149  		sessionB.WaitWithDefaultTimeout()
   150  		defer podmanTest.removeNetwork(netNameB)
   151  		Expect(sessionB).Should(ExitCleanly())
   152  
   153  		ctrA1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, NGINX_IMAGE})
   154  		ctrA1.WaitWithDefaultTimeout()
   155  		cidA1 := ctrA1.OutputToString()
   156  
   157  		ctrB1 := podmanTest.Podman([]string{"run", "-dt", "--name", "bone", "--network", netNameB, NGINX_IMAGE})
   158  		ctrB1.WaitWithDefaultTimeout()
   159  		cidB1 := ctrB1.OutputToString()
   160  
   161  		ctrIPA1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA1})
   162  		ctrIPA1.WaitWithDefaultTimeout()
   163  		Expect(ctrIPA1).Should(ExitCleanly())
   164  		cipA1 := ctrIPA1.OutputToString()
   165  		Expect(cipA1).To(MatchRegexp(IPRegex))
   166  
   167  		ctrIPB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidB1})
   168  		ctrIPB1.WaitWithDefaultTimeout()
   169  		Expect(ctrIPB1).Should(ExitCleanly())
   170  		cipB1 := ctrIPB1.OutputToString()
   171  		Expect(cipB1).To(MatchRegexp(IPRegex))
   172  
   173  		resA1B1 := podmanTest.Podman([]string{"exec", "aone", "dig", "+short", "bone"})
   174  		resA1B1.WaitWithDefaultTimeout()
   175  		Expect(resA1B1).Should(ExitCleanly())
   176  		Expect(resA1B1.OutputToString()).To(Equal(""))
   177  
   178  		resB1A1 := podmanTest.Podman([]string{"exec", "bone", "dig", "+short", "aone"})
   179  		resB1A1.WaitWithDefaultTimeout()
   180  		Expect(resB1A1).Should(ExitCleanly())
   181  		Expect(resB1A1.OutputToString()).To(Equal(""))
   182  	})
   183  
   184  	It("Aardvark Test 5: Two containers on their own subnets, one container on both", func() {
   185  		netNameA := createNetworkName("TestA")
   186  		sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
   187  		sessionA.WaitWithDefaultTimeout()
   188  		defer podmanTest.removeNetwork(netNameA)
   189  		Expect(sessionA).Should(ExitCleanly())
   190  
   191  		netNameB := createNetworkName("TestB")
   192  		sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
   193  		sessionB.WaitWithDefaultTimeout()
   194  		defer podmanTest.removeNetwork(netNameB)
   195  		Expect(sessionB).Should(ExitCleanly())
   196  
   197  		ctrA1 := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, NGINX_IMAGE})
   198  		ctrA1.WaitWithDefaultTimeout()
   199  		cidA1 := ctrA1.OutputToString()
   200  
   201  		ctrIPA1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA1})
   202  		ctrIPA1.WaitWithDefaultTimeout()
   203  		Expect(ctrIPA1).Should(ExitCleanly())
   204  		cipA1 := ctrIPA1.OutputToString()
   205  		Expect(cipA1).To(MatchRegexp(IPRegex))
   206  
   207  		ctrB1 := podmanTest.Podman([]string{"run", "-dt", "--name", "bone", "--network", netNameB, NGINX_IMAGE})
   208  		ctrB1.WaitWithDefaultTimeout()
   209  		cidB1 := ctrB1.OutputToString()
   210  
   211  		ctrIPB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidB1})
   212  		ctrIPB1.WaitWithDefaultTimeout()
   213  		Expect(ctrIPB1).Should(ExitCleanly())
   214  		cipB1 := ctrIPB1.OutputToString()
   215  		Expect(cipB1).To(MatchRegexp(IPRegex))
   216  
   217  		ctrA2B2 := podmanTest.Podman([]string{"run", "-dt", "--name", "atwobtwo", "--network", netNameA, "--network", netNameB, NGINX_IMAGE})
   218  		ctrA2B2.WaitWithDefaultTimeout()
   219  		cidA2B2 := ctrA2B2.OutputToString()
   220  
   221  		ctrIPA2B21 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameA), cidA2B2})
   222  		ctrIPA2B21.WaitWithDefaultTimeout()
   223  		Expect(ctrIPA2B21).Should(ExitCleanly())
   224  		cipA2B21 := ctrIPA2B21.OutputToString()
   225  		Expect(cipA2B21).To(MatchRegexp(IPRegex))
   226  
   227  		ctrIPA2B22 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), cidA2B2})
   228  		ctrIPA2B22.WaitWithDefaultTimeout()
   229  		Expect(ctrIPA2B22).Should(ExitCleanly())
   230  		cipA2B22 := ctrIPA2B22.OutputToString()
   231  		Expect(cipA2B22).To(MatchRegexp(IPRegex))
   232  
   233  		digShort("aone", "atwobtwo", cipA2B21, podmanTest)
   234  
   235  		digShort("bone", "atwobtwo", cipA2B22, podmanTest)
   236  
   237  		digShort("atwobtwo", "aone", cipA1, podmanTest)
   238  
   239  		digShort("atwobtwo", "bone", cipB1, podmanTest)
   240  	})
   241  
   242  	It("Aardvark Test 6: Three subnets, first container on 1/2 and second on 2/3, w/ network aliases", func() {
   243  		netNameA := createNetworkName("TestA")
   244  		sessionA := podmanTest.Podman([]string{"network", "create", netNameA})
   245  		sessionA.WaitWithDefaultTimeout()
   246  		defer podmanTest.removeNetwork(netNameA)
   247  		Expect(sessionA).Should(ExitCleanly())
   248  
   249  		netNameB := createNetworkName("TestB")
   250  		sessionB := podmanTest.Podman([]string{"network", "create", netNameB})
   251  		sessionB.WaitWithDefaultTimeout()
   252  		defer podmanTest.removeNetwork(netNameB)
   253  		Expect(sessionB).Should(ExitCleanly())
   254  
   255  		netNameC := createNetworkName("TestC")
   256  		sessionC := podmanTest.Podman([]string{"network", "create", netNameC})
   257  		sessionC.WaitWithDefaultTimeout()
   258  		defer podmanTest.removeNetwork(netNameC)
   259  		Expect(sessionC).Should(ExitCleanly())
   260  
   261  		ctrA := podmanTest.Podman([]string{"run", "-dt", "--name", "aone", "--network", netNameA, NGINX_IMAGE})
   262  		ctrA.WaitWithDefaultTimeout()
   263  		Expect(ctrA).Should(ExitCleanly())
   264  
   265  		ctrC := podmanTest.Podman([]string{"run", "-dt", "--name", "cone", "--network", netNameC, NGINX_IMAGE})
   266  		ctrC.WaitWithDefaultTimeout()
   267  		Expect(ctrC).Should(ExitCleanly())
   268  
   269  		ctrnetAB1 := podmanTest.Podman([]string{"network", "connect", "--alias", "testB1_nw", netNameB, "aone"})
   270  		ctrnetAB1.WaitWithDefaultTimeout()
   271  		Expect(ctrnetAB1).Should(ExitCleanly())
   272  
   273  		ctrIPAB1 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), "aone"})
   274  		ctrIPAB1.WaitWithDefaultTimeout()
   275  		Expect(ctrIPAB1).Should(ExitCleanly())
   276  		cipAB1 := ctrIPAB1.OutputToString()
   277  
   278  		ctrnetCB2 := podmanTest.Podman([]string{"network", "connect", "--alias", "testB2_nw", netNameB, "cone"})
   279  		ctrnetCB2.WaitWithDefaultTimeout()
   280  		Expect(ctrnetCB2).Should(ExitCleanly())
   281  
   282  		ctrIPCB2 := podmanTest.Podman([]string{"inspect", "--format", fmt.Sprintf(`{{.NetworkSettings.Networks.%s.IPAddress}}`, netNameB), "cone"})
   283  		ctrIPCB2.WaitWithDefaultTimeout()
   284  		Expect(ctrIPCB2).Should(ExitCleanly())
   285  		cipCB2 := ctrIPCB2.OutputToString()
   286  
   287  		digShort("aone", "testB2_nw", cipCB2, podmanTest)
   288  
   289  		digShort("cone", "testB1_nw", cipAB1, podmanTest)
   290  	})
   291  
   292  })