github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/run_staticip_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"os"
     7  	"time"
     8  
     9  	. "github.com/containers/podman/v3/test/utils"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("Podman run with --ip flag", func() {
    16  	var (
    17  		tempdir    string
    18  		err        error
    19  		podmanTest *PodmanTestIntegration
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		SkipIfRootless("rootless does not support --ip without network")
    24  		tempdir, err = CreateTempDirInTempDir()
    25  		if err != nil {
    26  			os.Exit(1)
    27  		}
    28  		podmanTest = PodmanTestCreate(tempdir)
    29  		podmanTest.Setup()
    30  		podmanTest.SeedImages()
    31  		// Cleanup the CNI networks used by the tests
    32  		os.RemoveAll("/var/lib/cni/networks/podman")
    33  	})
    34  
    35  	AfterEach(func() {
    36  		podmanTest.Cleanup()
    37  		f := CurrentGinkgoTestDescription()
    38  		processTestResult(f)
    39  
    40  	})
    41  
    42  	It("Podman run --ip with garbage address", func() {
    43  		result := podmanTest.Podman([]string{"run", "-ti", "--ip", "114232346", ALPINE, "ls"})
    44  		result.WaitWithDefaultTimeout()
    45  		Expect(result).To(ExitWithError())
    46  	})
    47  
    48  	It("Podman run --ip with v6 address", func() {
    49  		result := podmanTest.Podman([]string{"run", "-ti", "--ip", "2001:db8:bad:beef::1", ALPINE, "ls"})
    50  		result.WaitWithDefaultTimeout()
    51  		Expect(result).To(ExitWithError())
    52  	})
    53  
    54  	It("Podman run --ip with non-allocatable IP", func() {
    55  		result := podmanTest.Podman([]string{"run", "-ti", "--ip", "203.0.113.124", ALPINE, "ls"})
    56  		result.WaitWithDefaultTimeout()
    57  		Expect(result).To(ExitWithError())
    58  	})
    59  
    60  	It("Podman run with specified static IP has correct IP", func() {
    61  		ip := GetRandomIPAddress()
    62  		result := podmanTest.Podman([]string{"run", "-ti", "--ip", ip, ALPINE, "ip", "addr"})
    63  		result.WaitWithDefaultTimeout()
    64  		Expect(result).Should(Exit(0))
    65  		Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
    66  	})
    67  
    68  	It("Podman run two containers with the same IP", func() {
    69  		ip := GetRandomIPAddress()
    70  		result := podmanTest.Podman([]string{"run", "-dt", "--ip", ip, nginx})
    71  		result.WaitWithDefaultTimeout()
    72  		Expect(result).Should(Exit(0))
    73  		for i := 0; i < 10; i++ {
    74  			fmt.Println("Waiting for nginx", err)
    75  			time.Sleep(1 * time.Second)
    76  			response, err := http.Get(fmt.Sprintf("http://%s", ip))
    77  			if err != nil {
    78  				continue
    79  			}
    80  			if response.StatusCode == http.StatusOK {
    81  				break
    82  			}
    83  		}
    84  		result = podmanTest.Podman([]string{"run", "-ti", "--ip", ip, ALPINE, "ip", "addr"})
    85  		result.WaitWithDefaultTimeout()
    86  		Expect(result).To(ExitWithError())
    87  	})
    88  })