github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/pod_create_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	. "github.com/containers/libpod/test/utils"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Podman pod create", func() {
    14  	var (
    15  		tempdir    string
    16  		err        error
    17  		podmanTest *PodmanTestIntegration
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		tempdir, err = CreateTempDirInTempDir()
    22  		if err != nil {
    23  			os.Exit(1)
    24  		}
    25  		podmanTest = PodmanTestCreate(tempdir)
    26  		podmanTest.Setup()
    27  		podmanTest.SeedImages()
    28  	})
    29  
    30  	AfterEach(func() {
    31  		podmanTest.CleanupPod()
    32  		f := CurrentGinkgoTestDescription()
    33  		processTestResult(f)
    34  
    35  	})
    36  
    37  	It("podman create pod", func() {
    38  		_, ec, podID := podmanTest.CreatePod("")
    39  		Expect(ec).To(Equal(0))
    40  
    41  		check := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
    42  		check.WaitWithDefaultTimeout()
    43  		match, _ := check.GrepString(podID)
    44  		Expect(match).To(BeTrue())
    45  		Expect(len(check.OutputToStringArray())).To(Equal(1))
    46  	})
    47  
    48  	It("podman create pod with name", func() {
    49  		name := "test"
    50  		_, ec, _ := podmanTest.CreatePod(name)
    51  		Expect(ec).To(Equal(0))
    52  
    53  		check := podmanTest.Podman([]string{"pod", "ps", "--no-trunc"})
    54  		check.WaitWithDefaultTimeout()
    55  		match, _ := check.GrepString(name)
    56  		Expect(match).To(BeTrue())
    57  	})
    58  
    59  	It("podman create pod with doubled name", func() {
    60  		name := "test"
    61  		_, ec, _ := podmanTest.CreatePod(name)
    62  		Expect(ec).To(Equal(0))
    63  
    64  		_, ec2, _ := podmanTest.CreatePod(name)
    65  		Expect(ec2).To(Not(Equal(0)))
    66  
    67  		check := podmanTest.Podman([]string{"pod", "ps", "-q"})
    68  		check.WaitWithDefaultTimeout()
    69  		Expect(len(check.OutputToStringArray())).To(Equal(1))
    70  	})
    71  
    72  	It("podman create pod with same name as ctr", func() {
    73  		name := "test"
    74  		session := podmanTest.Podman([]string{"create", "--name", name, ALPINE, "ls"})
    75  		session.WaitWithDefaultTimeout()
    76  		Expect(session.ExitCode()).To(Equal(0))
    77  
    78  		_, ec, _ := podmanTest.CreatePod(name)
    79  		Expect(ec).To(Not(Equal(0)))
    80  
    81  		check := podmanTest.Podman([]string{"pod", "ps", "-q"})
    82  		check.WaitWithDefaultTimeout()
    83  		Expect(len(check.OutputToStringArray())).To(Equal(0))
    84  	})
    85  
    86  	It("podman create pod without network portbindings", func() {
    87  		name := "test"
    88  		session := podmanTest.Podman([]string{"pod", "create", "--name", name})
    89  		session.WaitWithDefaultTimeout()
    90  		Expect(session.ExitCode()).To(Equal(0))
    91  		pod := session.OutputToString()
    92  
    93  		webserver := podmanTest.Podman([]string{"run", "--pod", pod, "-dt", nginx})
    94  		webserver.WaitWithDefaultTimeout()
    95  		Expect(webserver.ExitCode()).To(Equal(0))
    96  
    97  		check := SystemExec("nc", []string{"-z", "localhost", "80"})
    98  		Expect(check.ExitCode()).To(Equal(1))
    99  	})
   100  
   101  	It("podman create pod with network portbindings", func() {
   102  		name := "test"
   103  		session := podmanTest.Podman([]string{"pod", "create", "--name", name, "-p", "8080:80"})
   104  		session.WaitWithDefaultTimeout()
   105  		Expect(session.ExitCode()).To(Equal(0))
   106  		pod := session.OutputToString()
   107  
   108  		webserver := podmanTest.Podman([]string{"run", "--pod", pod, "-dt", nginx})
   109  		webserver.WaitWithDefaultTimeout()
   110  		Expect(webserver.ExitCode()).To(Equal(0))
   111  
   112  		check := SystemExec("nc", []string{"-z", "localhost", "8080"})
   113  		Expect(check.ExitCode()).To(Equal(0))
   114  	})
   115  
   116  	It("podman create pod with no infra but portbindings should fail", func() {
   117  		name := "test"
   118  		session := podmanTest.Podman([]string{"pod", "create", "--infra=false", "--name", name, "-p", "80:80"})
   119  		session.WaitWithDefaultTimeout()
   120  		Expect(session.ExitCode()).To(Equal(125))
   121  	})
   122  
   123  	It("podman create pod with --no-hosts", func() {
   124  		SkipIfRemote()
   125  		name := "test"
   126  		podCreate := podmanTest.Podman([]string{"pod", "create", "--no-hosts", "--name", name})
   127  		podCreate.WaitWithDefaultTimeout()
   128  		Expect(podCreate.ExitCode()).To(Equal(0))
   129  
   130  		alpineResolvConf := podmanTest.Podman([]string{"run", "-ti", "--rm", "--no-hosts", ALPINE, "cat", "/etc/hosts"})
   131  		alpineResolvConf.WaitWithDefaultTimeout()
   132  		Expect(alpineResolvConf.ExitCode()).To(Equal(0))
   133  
   134  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/hosts"})
   135  		podResolvConf.WaitWithDefaultTimeout()
   136  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   137  		Expect(podResolvConf.OutputToString()).To(Equal(alpineResolvConf.OutputToString()))
   138  	})
   139  
   140  	It("podman create pod with --no-hosts and no infra should fail", func() {
   141  		SkipIfRemote()
   142  		name := "test"
   143  		podCreate := podmanTest.Podman([]string{"pod", "create", "--no-hosts", "--name", name, "--infra=false"})
   144  		podCreate.WaitWithDefaultTimeout()
   145  		Expect(podCreate.ExitCode()).To(Equal(125))
   146  	})
   147  
   148  	It("podman create pod with --add-host", func() {
   149  		SkipIfRemote()
   150  		name := "test"
   151  		podCreate := podmanTest.Podman([]string{"pod", "create", "--add-host", "test.example.com:12.34.56.78", "--name", name})
   152  		podCreate.WaitWithDefaultTimeout()
   153  		Expect(podCreate.ExitCode()).To(Equal(0))
   154  
   155  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/hosts"})
   156  		podResolvConf.WaitWithDefaultTimeout()
   157  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   158  		Expect(strings.Contains(podResolvConf.OutputToString(), "12.34.56.78 test.example.com")).To(BeTrue())
   159  	})
   160  
   161  	It("podman create pod with --add-host and no infra should fail", func() {
   162  		SkipIfRemote()
   163  		name := "test"
   164  		podCreate := podmanTest.Podman([]string{"pod", "create", "--add-host", "test.example.com:12.34.56.78", "--name", name, "--infra=false"})
   165  		podCreate.WaitWithDefaultTimeout()
   166  		Expect(podCreate.ExitCode()).To(Equal(125))
   167  	})
   168  
   169  	It("podman create pod with DNS server set", func() {
   170  		SkipIfRemote()
   171  		name := "test"
   172  		server := "12.34.56.78"
   173  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns", server, "--name", name})
   174  		podCreate.WaitWithDefaultTimeout()
   175  		Expect(podCreate.ExitCode()).To(Equal(0))
   176  
   177  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
   178  		podResolvConf.WaitWithDefaultTimeout()
   179  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   180  		Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("nameserver %s", server))).To(BeTrue())
   181  	})
   182  
   183  	It("podman create pod with DNS server set and no infra should fail", func() {
   184  		SkipIfRemote()
   185  		name := "test"
   186  		server := "12.34.56.78"
   187  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns", server, "--name", name, "--infra=false"})
   188  		podCreate.WaitWithDefaultTimeout()
   189  		Expect(podCreate.ExitCode()).To(Equal(125))
   190  	})
   191  
   192  	It("podman create pod with DNS option set", func() {
   193  		SkipIfRemote()
   194  		name := "test"
   195  		option := "attempts:5"
   196  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-opt", option, "--name", name})
   197  		podCreate.WaitWithDefaultTimeout()
   198  		Expect(podCreate.ExitCode()).To(Equal(0))
   199  
   200  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
   201  		podResolvConf.WaitWithDefaultTimeout()
   202  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   203  		Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("options %s", option))).To(BeTrue())
   204  	})
   205  
   206  	It("podman create pod with DNS option set and no infra should fail", func() {
   207  		SkipIfRemote()
   208  		name := "test"
   209  		option := "attempts:5"
   210  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-opt", option, "--name", name, "--infra=false"})
   211  		podCreate.WaitWithDefaultTimeout()
   212  		Expect(podCreate.ExitCode()).To(Equal(125))
   213  	})
   214  
   215  	It("podman create pod with DNS search domain set", func() {
   216  		SkipIfRemote()
   217  		name := "test"
   218  		search := "example.com"
   219  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-search", search, "--name", name})
   220  		podCreate.WaitWithDefaultTimeout()
   221  		Expect(podCreate.ExitCode()).To(Equal(0))
   222  
   223  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
   224  		podResolvConf.WaitWithDefaultTimeout()
   225  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   226  		Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("search %s", search))).To(BeTrue())
   227  	})
   228  
   229  	It("podman create pod with DNS search domain set and no infra should fail", func() {
   230  		SkipIfRemote()
   231  		name := "test"
   232  		search := "example.com"
   233  		podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-search", search, "--name", name, "--infra=false"})
   234  		podCreate.WaitWithDefaultTimeout()
   235  		Expect(podCreate.ExitCode()).To(Equal(125))
   236  	})
   237  
   238  	It("podman create pod with IP address", func() {
   239  		SkipIfRemote()
   240  		SkipIfRootless()
   241  		name := "test"
   242  		ip := GetRandomIPAddress()
   243  		podCreate := podmanTest.Podman([]string{"pod", "create", "--ip", ip, "--name", name})
   244  		podCreate.WaitWithDefaultTimeout()
   245  		Expect(podCreate.ExitCode()).To(Equal(0))
   246  
   247  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"})
   248  		podResolvConf.WaitWithDefaultTimeout()
   249  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   250  		Expect(strings.Contains(podResolvConf.OutputToString(), ip)).To(BeTrue())
   251  	})
   252  
   253  	It("podman create pod with IP address and no infra should fail", func() {
   254  		SkipIfRemote()
   255  		name := "test"
   256  		ip := GetRandomIPAddress()
   257  		podCreate := podmanTest.Podman([]string{"pod", "create", "--ip", ip, "--name", name, "--infra=false"})
   258  		podCreate.WaitWithDefaultTimeout()
   259  		Expect(podCreate.ExitCode()).To(Equal(125))
   260  	})
   261  
   262  	It("podman create pod with MAC address", func() {
   263  		SkipIfRemote()
   264  		SkipIfRootless()
   265  		name := "test"
   266  		mac := "92:d0:c6:0a:29:35"
   267  		podCreate := podmanTest.Podman([]string{"pod", "create", "--mac-address", mac, "--name", name})
   268  		podCreate.WaitWithDefaultTimeout()
   269  		Expect(podCreate.ExitCode()).To(Equal(0))
   270  
   271  		podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"})
   272  		podResolvConf.WaitWithDefaultTimeout()
   273  		Expect(podResolvConf.ExitCode()).To(Equal(0))
   274  		Expect(strings.Contains(podResolvConf.OutputToString(), mac)).To(BeTrue())
   275  	})
   276  
   277  	It("podman create pod with MAC address and no infra should fail", func() {
   278  		SkipIfRemote()
   279  		name := "test"
   280  		mac := "92:d0:c6:0a:29:35"
   281  		podCreate := podmanTest.Podman([]string{"pod", "create", "--mac-address", mac, "--name", name, "--infra=false"})
   282  		podCreate.WaitWithDefaultTimeout()
   283  		Expect(podCreate.ExitCode()).To(Equal(125))
   284  	})
   285  })