From 4fb5fee4120165d43ee6b98f7258cda741d41d45 Mon Sep 17 00:00:00 2001 From: chenkang Date: Fri, 16 Apr 2021 15:12:57 +0800 Subject: add ut Signed-off-by: chenkang --- test/e2e/run_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index cefe00655..ac459f6ab 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1613,4 +1613,12 @@ WORKDIR /madethis`, BB) Expect(running.ExitCode()).To(Equal(0)) Expect(len(running.OutputToStringArray())).To(Equal(2)) }) + + It("podman run with pidfile", func() { + session := podmanTest.Podman([]string{"run", "--pidfile", tempdir + "pidfile", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + err := os.Remove(tempdir + "pidfile") + Expect(err).To(BeNil()) + }) }) -- cgit v1.2.3-54-g00ecf From c9f347e9a8c013348d236bc205b3eca13d3f29ef Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 20:32:19 +0800 Subject: skip pidfile it on remote Signed-off-by: chenkang --- test/e2e/run_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index ac459f6ab..93505d742 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1615,10 +1615,18 @@ WORKDIR /madethis`, BB) }) It("podman run with pidfile", func() { - session := podmanTest.Podman([]string{"run", "--pidfile", tempdir + "pidfile", ALPINE, "ls"}) + SkipIfRemote("pidfile not handled by remote") + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"run", "--pidfile", pidfile, ALPINE, "ls"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - err := os.Remove(tempdir + "pidfile") + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer Expect(err).To(BeNil()) }) }) -- cgit v1.2.3-54-g00ecf From f3f7ae5cddada6a1faa4bef21c586efb83c70c19 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 20:42:21 +0800 Subject: add pidfile it for container start Signed-off-by: chenkang --- test/e2e/start_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index f527b67f6..be724ab35 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -1,7 +1,10 @@ package integration import ( + "io/ioutil" "os" + "strconv" + "strings" . "github.com/containers/podman/v3/test/utils" . "github.com/onsi/ginkgo" @@ -206,4 +209,23 @@ var _ = Describe("Podman start", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) }) + + It("podman start container with special pidfile", func() { + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"create", "--pidfile", pidfile, ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + session = podmanTest.Podman([]string{"start", cid}) + Expect(session.ExitCode()).To(Equal(0)) + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer + Expect(err).To(BeNil()) + }) }) -- cgit v1.2.3-54-g00ecf From 4ce7aa6ee8aac132c4447d8a1be0fbce31d53bdc Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 22:30:43 +0800 Subject: skip pidfile test on remote Signed-off-by: chenkang --- test/e2e/start_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index be724ab35..d5d12fc71 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -211,6 +211,7 @@ var _ = Describe("Podman start", func() { }) It("podman start container with special pidfile", func() { + SkipIfRemote("pidfile not handled by remote") pidfile := tempdir + "pidfile" session := podmanTest.Podman([]string{"create", "--pidfile", pidfile, ALPINE, "ls"}) session.WaitWithDefaultTimeout() -- cgit v1.2.3-54-g00ecf From a1002beb78e3a63c0704f5cd8f6ff6556e60bb2f Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 23:35:27 +0800 Subject: fix start it Signed-off-by: chenkang --- libpod/container_inspect.go | 2 +- libpod/define/container_inspect.go | 2 +- test/e2e/start_test.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 57968039f..61cc43314 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -128,6 +128,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver StaticDir: config.StaticDir, OCIRuntime: config.OCIRuntime, ConmonPidFile: config.ConmonPidFile, + PidFile: config.PidFile, Name: config.Name, RestartCount: int32(runtimeInfo.RestartCount), Driver: driverData.Name, @@ -141,7 +142,6 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver Mounts: inspectMounts, Dependencies: c.Dependencies(), IsInfra: c.IsInfra(), - PidFile: config.PidFile, } if c.state.ConfigPath != "" { diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 126ce85a6..1a38f5b0a 100644 --- a/libpod/define/container_inspect.go +++ b/libpod/define/container_inspect.go @@ -627,6 +627,7 @@ type InspectContainerData struct { OCIConfigPath string `json:"OCIConfigPath,omitempty"` OCIRuntime string `json:"OCIRuntime,omitempty"` ConmonPidFile string `json:"ConmonPidFile"` + PidFile string `json:"PidFile"` Name string `json:"Name"` RestartCount int32 `json:"RestartCount"` Driver string `json:"Driver"` @@ -647,7 +648,6 @@ type InspectContainerData struct { IsInfra bool `json:"IsInfra"` Config *InspectContainerConfig `json:"Config"` HostConfig *InspectContainerHostConfig `json:"HostConfig"` - PidFile string `json:"PidFile"` } // InspectExecSession contains information about a given exec session. diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index d5d12fc71..cb2db0810 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -219,6 +219,7 @@ var _ = Describe("Podman start", func() { cid := session.OutputToString() session = podmanTest.Podman([]string{"start", cid}) + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) readFirstLine := func(path string) string { content, err := ioutil.ReadFile(path) -- cgit v1.2.3-54-g00ecf From 4ffaa50d05bcb08d7db242232a128bb3493fcf25 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sun, 18 Apr 2021 21:29:12 +0800 Subject: add it for inspect pidfile Signed-off-by: chenkang --- test/e2e/inspect_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 772ebed05..ba018b5ad 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -508,4 +508,14 @@ var _ = Describe("Podman inspect", func() { Expect(data[0].HostConfig.CapDrop[1]).To(Equal("CAP_MKNOD")) Expect(data[0].HostConfig.CapDrop[2]).To(Equal("CAP_NET_RAW")) }) + + It("podman inspect container with GO format for PidFile", func() { + SkipIfRemote("pidfile not handled by remote") + session, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + + session = podmanTest.Podman([]string{"inspect", "--format", "{{.PidFile}}", "test1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) -- cgit v1.2.3-54-g00ecf