github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/create_staticip_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 "time" 6 7 "github.com/containers/podman/v3/pkg/rootless" 8 . "github.com/containers/podman/v3/test/utils" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Podman create with --ip flag", func() { 15 var ( 16 tempdir string 17 err error 18 podmanTest *PodmanTestIntegration 19 ) 20 21 BeforeEach(func() { 22 tempdir, err = CreateTempDirInTempDir() 23 if err != nil { 24 os.Exit(1) 25 } 26 podmanTest = PodmanTestCreate(tempdir) 27 podmanTest.Setup() 28 podmanTest.SeedImages() 29 // Cleanup the CNI networks used by the tests 30 os.RemoveAll("/var/lib/cni/networks/podman") 31 }) 32 33 AfterEach(func() { 34 podmanTest.Cleanup() 35 f := CurrentGinkgoTestDescription() 36 processTestResult(f) 37 38 }) 39 40 It("Podman create --ip with garbage address", func() { 41 result := podmanTest.Podman([]string{"create", "--name", "test", "--ip", "114232346", ALPINE, "ls"}) 42 result.WaitWithDefaultTimeout() 43 Expect(result).To(ExitWithError()) 44 }) 45 46 It("Podman create --ip with v6 address", func() { 47 result := podmanTest.Podman([]string{"create", "--name", "test", "--ip", "2001:db8:bad:beef::1", ALPINE, "ls"}) 48 result.WaitWithDefaultTimeout() 49 Expect(result).To(ExitWithError()) 50 }) 51 52 It("Podman create --ip with non-allocatable IP", func() { 53 SkipIfRootless("--ip not supported without network in rootless mode") 54 result := podmanTest.Podman([]string{"create", "--name", "test", "--ip", "203.0.113.124", ALPINE, "ls"}) 55 result.WaitWithDefaultTimeout() 56 Expect(result).Should(Exit(0)) 57 58 result = podmanTest.Podman([]string{"start", "test"}) 59 result.WaitWithDefaultTimeout() 60 Expect(result).To(ExitWithError()) 61 }) 62 63 It("Podman create with specified static IP has correct IP", func() { 64 // NOTE: we force the k8s-file log driver to make sure the 65 // tests are passing inside a container. 66 ip := GetRandomIPAddress() 67 result := podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test", "--ip", ip, ALPINE, "ip", "addr"}) 68 result.WaitWithDefaultTimeout() 69 // Rootless static ip assignment without network should error 70 if rootless.IsRootless() { 71 Expect(result).Should(Exit(125)) 72 } else { 73 Expect(result).Should(Exit(0)) 74 75 result = podmanTest.Podman([]string{"start", "test"}) 76 result.WaitWithDefaultTimeout() 77 Expect(result).Should(Exit(0)) 78 79 result = podmanTest.Podman([]string{"logs", "test"}) 80 result.WaitWithDefaultTimeout() 81 Expect(result).Should(Exit(0)) 82 Expect(result.OutputToString()).To(ContainSubstring(ip + "/16")) 83 } 84 }) 85 86 It("Podman create two containers with the same IP", func() { 87 SkipIfRootless("--ip not supported without network in rootless mode") 88 ip := GetRandomIPAddress() 89 result := podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test1", "--ip", ip, ALPINE, "sleep", "999"}) 90 result.WaitWithDefaultTimeout() 91 Expect(result).Should(Exit(0)) 92 result = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test2", "--ip", ip, ALPINE, "ip", "addr"}) 93 result.WaitWithDefaultTimeout() 94 Expect(result).Should(Exit(0)) 95 result = podmanTest.Podman([]string{"start", "test1"}) 96 result.WaitWithDefaultTimeout() 97 Expect(result).Should(Exit(0)) 98 99 // race prevention: wait until IP address is assigned 100 for i := 0; i < 5; i++ { 101 result = podmanTest.Podman([]string{"inspect", "--format", "{{.NetworkSettings.IPAddress}}", "test1"}) 102 result.WaitWithDefaultTimeout() 103 Expect(result).Should(Exit(0)) 104 if result.OutputToString() != "" { 105 break 106 } 107 time.Sleep(1 * time.Second) 108 } 109 Expect(result.OutputToString()).To(Equal(ip)) 110 111 // test1 container is running with the given IP. 112 result = podmanTest.Podman([]string{"start", "test2"}) 113 result.WaitWithDefaultTimeout() 114 Expect(result).To(ExitWithError()) 115 Expect(result.ErrorToString()).To(ContainSubstring("requested IP address " + ip + " is not available")) 116 }) 117 })