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

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/containers/podman/v5/test/utils"
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Podman pod clone", func() {
    12  
    13  	hostname, _ := os.Hostname()
    14  
    15  	BeforeEach(func() {
    16  		SkipIfRemote("podman pod clone is not supported in remote")
    17  	})
    18  
    19  	It("podman pod clone basic test", func() {
    20  		create := podmanTest.Podman([]string{"pod", "create", "--name", "1"})
    21  		create.WaitWithDefaultTimeout()
    22  		Expect(create).To(ExitCleanly())
    23  
    24  		run := podmanTest.Podman([]string{"run", "--pod", "1", "-dt", ALPINE})
    25  		run.WaitWithDefaultTimeout()
    26  		Expect(run).To(ExitCleanly())
    27  
    28  		clone := podmanTest.Podman([]string{"pod", "clone", create.OutputToString()})
    29  		clone.WaitWithDefaultTimeout()
    30  		Expect(clone).To(ExitCleanly())
    31  
    32  		podInspect := podmanTest.Podman([]string{"pod", "inspect", clone.OutputToString()})
    33  		podInspect.WaitWithDefaultTimeout()
    34  		Expect(podInspect).To(ExitCleanly())
    35  		data := podInspect.InspectPodToJSON()
    36  		Expect(data.Name).To(ContainSubstring("-clone"))
    37  
    38  		podStart := podmanTest.Podman([]string{"pod", "start", clone.OutputToString()})
    39  		podStart.WaitWithDefaultTimeout()
    40  		Expect(podStart).To(ExitCleanly())
    41  
    42  		podInspect = podmanTest.Podman([]string{"pod", "inspect", clone.OutputToString()})
    43  		podInspect.WaitWithDefaultTimeout()
    44  		Expect(podInspect).To(ExitCleanly())
    45  		data = podInspect.InspectPodToJSON()
    46  		Expect(data.Containers[1].State).To(ContainSubstring("running")) // make sure non infra ctr is running
    47  	})
    48  
    49  	It("podman pod clone renaming test", func() {
    50  		create := podmanTest.Podman([]string{"pod", "create", "--name", "1"})
    51  		create.WaitWithDefaultTimeout()
    52  		Expect(create).To(ExitCleanly())
    53  
    54  		clone := podmanTest.Podman([]string{"pod", "clone", "--name", "2", create.OutputToString()})
    55  		clone.WaitWithDefaultTimeout()
    56  		Expect(clone).To(ExitCleanly())
    57  
    58  		podInspect := podmanTest.Podman([]string{"pod", "inspect", clone.OutputToString()})
    59  		podInspect.WaitWithDefaultTimeout()
    60  		Expect(podInspect).To(ExitCleanly())
    61  		data := podInspect.InspectPodToJSON()
    62  		Expect(data.Name).To(ContainSubstring("2"))
    63  
    64  		podStart := podmanTest.Podman([]string{"pod", "start", clone.OutputToString()})
    65  		podStart.WaitWithDefaultTimeout()
    66  		Expect(podStart).To(ExitCleanly())
    67  	})
    68  
    69  	It("podman pod clone start test", func() {
    70  		create := podmanTest.Podman([]string{"pod", "create", "--name", "1"})
    71  		create.WaitWithDefaultTimeout()
    72  		Expect(create).To(ExitCleanly())
    73  
    74  		clone := podmanTest.Podman([]string{"pod", "clone", "--start", create.OutputToString()})
    75  		clone.WaitWithDefaultTimeout()
    76  		Expect(clone).To(ExitCleanly())
    77  
    78  		podInspect := podmanTest.Podman([]string{"pod", "inspect", clone.OutputToString()})
    79  		podInspect.WaitWithDefaultTimeout()
    80  		Expect(podInspect).To(ExitCleanly())
    81  		data := podInspect.InspectPodToJSON()
    82  		Expect(data.State).To(ContainSubstring("Running"))
    83  
    84  	})
    85  
    86  	It("podman pod clone destroy test", func() {
    87  		create := podmanTest.Podman([]string{"pod", "create", "--name", "1"})
    88  		create.WaitWithDefaultTimeout()
    89  		Expect(create).To(ExitCleanly())
    90  
    91  		clone := podmanTest.Podman([]string{"pod", "clone", "--destroy", create.OutputToString()})
    92  		clone.WaitWithDefaultTimeout()
    93  		Expect(clone).To(ExitCleanly())
    94  
    95  		podInspect := podmanTest.Podman([]string{"pod", "inspect", create.OutputToString()})
    96  		podInspect.WaitWithDefaultTimeout()
    97  		Expect(podInspect).ToNot(ExitCleanly())
    98  	})
    99  
   100  	It("podman pod clone infra option test", func() {
   101  		// proof of concept that all currently tested infra options work since
   102  
   103  		volName := "testVol"
   104  		volCreate := podmanTest.Podman([]string{"volume", "create", volName})
   105  		volCreate.WaitWithDefaultTimeout()
   106  		Expect(volCreate).Should(ExitCleanly())
   107  
   108  		podName := "testPod"
   109  		podCreate := podmanTest.Podman([]string{"pod", "create", "--name", podName})
   110  		podCreate.WaitWithDefaultTimeout()
   111  		Expect(podCreate).Should(ExitCleanly())
   112  
   113  		podClone := podmanTest.Podman([]string{"pod", "clone", "--volume", volName + ":/tmp1", podName})
   114  		podClone.WaitWithDefaultTimeout()
   115  		Expect(podClone).Should(ExitCleanly())
   116  
   117  		podInspect := podmanTest.Podman([]string{"pod", "inspect", "testPod-clone"})
   118  		podInspect.WaitWithDefaultTimeout()
   119  		Expect(podInspect).Should(ExitCleanly())
   120  		data := podInspect.InspectPodToJSON()
   121  		Expect(data.Mounts[0]).To(HaveField("Name", volName))
   122  	})
   123  
   124  	It("podman pod clone --shm-size", func() {
   125  		podCreate := podmanTest.Podman([]string{"pod", "create"})
   126  		podCreate.WaitWithDefaultTimeout()
   127  		Expect(podCreate).Should(ExitCleanly())
   128  
   129  		podClone := podmanTest.Podman([]string{"pod", "clone", "--shm-size", "10mb", podCreate.OutputToString()})
   130  		podClone.WaitWithDefaultTimeout()
   131  		Expect(podClone).Should(ExitCleanly())
   132  
   133  		run := podmanTest.Podman([]string{"run", "--pod", podClone.OutputToString(), ALPINE, "mount"})
   134  		run.WaitWithDefaultTimeout()
   135  		Expect(run).Should(ExitCleanly())
   136  		t, strings := run.GrepString("shm on /dev/shm type tmpfs")
   137  		Expect(t).To(BeTrue(), "found /dev/shm")
   138  		Expect(strings[0]).Should(ContainSubstring("size=10240k"))
   139  	})
   140  
   141  	It("podman pod clone --uts test", func() {
   142  		SkipIfRemote("hostname for the custom NS test is not as expected on the remote client")
   143  
   144  		session := podmanTest.Podman([]string{"pod", "create"})
   145  		session.WaitWithDefaultTimeout()
   146  		Expect(session).Should(ExitCleanly())
   147  
   148  		session = podmanTest.Podman([]string{"pod", "clone", "--uts", "host", session.OutputToString()})
   149  		session.WaitWithDefaultTimeout()
   150  		Expect(session).Should(ExitCleanly())
   151  
   152  		session = podmanTest.Podman([]string{"run", "--pod", session.OutputToString(), ALPINE, "printenv", "HOSTNAME"})
   153  		session.WaitWithDefaultTimeout()
   154  		Expect(session).Should(ExitCleanly())
   155  		Expect(session.OutputToString()).To(ContainSubstring(hostname))
   156  
   157  		podName := "utsPod"
   158  		ns := "ns:/proc/self/ns/"
   159  
   160  		session = podmanTest.Podman([]string{"pod", "create"})
   161  		session.WaitWithDefaultTimeout()
   162  		Expect(session).Should(ExitCleanly())
   163  
   164  		// just share uts with a custom path
   165  		podCreate := podmanTest.Podman([]string{"pod", "clone", "--uts", ns, "--name", podName, session.OutputToString()})
   166  		podCreate.WaitWithDefaultTimeout()
   167  		Expect(podCreate).Should(ExitCleanly())
   168  
   169  		podInspect := podmanTest.Podman([]string{"pod", "inspect", podName})
   170  		podInspect.WaitWithDefaultTimeout()
   171  		Expect(podInspect).Should(ExitCleanly())
   172  		podJSON := podInspect.InspectPodToJSON()
   173  		Expect(podJSON.InfraConfig).To(HaveField("UtsNS", ns))
   174  	})
   175  
   176  })