mirror of
https://github.com/containers/podman.git
synced 2025-12-16 12:29:28 +08:00
The remote API will wait 300s by default before conmon will call the cleanup. In the meantime when you inspect an exec session started with ExecStart() (so not attached) and it did exit we do not know that. If a caller inspects it they think it is still running. To prevent this we should sync the session based on the exec pid and update the state accordingly. For a reproducer see the test in this commit or the issue. Fixes #18424 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
86 lines
2.5 KiB
Go
86 lines
2.5 KiB
Go
package bindings_test
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/containers/podman/v4/pkg/api/handlers"
|
|
"github.com/containers/podman/v4/pkg/bindings/containers"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("Podman containers exec", func() {
|
|
var (
|
|
bt *bindingTest
|
|
s *gexec.Session
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
bt = newBindingTest()
|
|
bt.RestoreImagesFromCache()
|
|
s = bt.startAPIService()
|
|
time.Sleep(1 * time.Second)
|
|
err := bt.NewConnection()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
s.Kill()
|
|
bt.cleanup()
|
|
})
|
|
|
|
It("Podman exec create+start makes an exec session", func() {
|
|
name := "testCtr"
|
|
cid, err := bt.RunTopContainer(&name, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
execConfig := new(handlers.ExecCreateConfig)
|
|
execConfig.Cmd = []string{"echo", "hello world"}
|
|
|
|
sessionID, err := containers.ExecCreate(bt.conn, name, execConfig)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(sessionID).To(Not(Equal("")))
|
|
|
|
inspectOut, err := containers.ExecInspect(bt.conn, sessionID, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(inspectOut.ContainerID).To(Equal(cid))
|
|
Expect(inspectOut.ProcessConfig.Entrypoint).To(Equal("echo"))
|
|
Expect(inspectOut.ProcessConfig.Arguments).To(HaveLen(1))
|
|
Expect(inspectOut.ProcessConfig.Arguments[0]).To(Equal("hello world"))
|
|
|
|
err = containers.ExecStart(bt.conn, sessionID, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
inspectOut, err = containers.ExecInspect(bt.conn, sessionID, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(inspectOut.ContainerID).To(Equal(cid))
|
|
Expect(inspectOut.Running).To(BeFalse(), "session should not be running")
|
|
Expect(inspectOut.ExitCode).To(Equal(0), "exit code from echo")
|
|
})
|
|
|
|
It("Podman exec create with bad command fails", func() {
|
|
name := "testCtr"
|
|
_, err := bt.RunTopContainer(&name, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
execConfig := new(handlers.ExecCreateConfig)
|
|
|
|
_, err = containers.ExecCreate(bt.conn, name, execConfig)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("Podman exec create with invalid container fails", func() {
|
|
execConfig := new(handlers.ExecCreateConfig)
|
|
execConfig.Cmd = []string{"echo", "hello world"}
|
|
|
|
_, err := containers.ExecCreate(bt.conn, "doesnotexist", execConfig)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("Podman exec inspect on invalid session fails", func() {
|
|
_, err := containers.ExecInspect(bt.conn, "0000000000000000000000000000000000000000000000000000000000000000", nil)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|