test: fix exec preserve-fds test

it specifies a fd is passed down but we are not really doing it, and
it triggers the wrong fd to be closed by Podman after the OCI runtime
invocation.

Closes: https://github.com/containers/libpod/issues/5769

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-04-09 09:56:26 +02:00
parent 291ad7fbd9
commit d3cfa7a23c
5 changed files with 25 additions and 5 deletions

View File

@ -252,7 +252,13 @@ var _ = Describe("Podman exec", func() {
setup.WaitWithDefaultTimeout() setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0)) Expect(setup.ExitCode()).To(Equal(0))
session := podmanTest.Podman([]string{"exec", "--preserve-fds", "1", "test1", "ls"}) devNull, err := os.Open("/dev/null")
Expect(err).To(BeNil())
defer devNull.Close()
files := []*os.File{
devNull,
}
session := podmanTest.PodmanExtraFiles([]string{"exec", "--preserve-fds", "1", "test1", "ls"}, files)
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
}) })

View File

@ -34,6 +34,12 @@ func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration
return &PodmanSessionIntegration{podmanSession} return &PodmanSessionIntegration{podmanSession}
} }
// PodmanExtraFiles is the exec call to podman on the filesystem and passes down extra files
func (p *PodmanTestIntegration) PodmanExtraFiles(args []string, extraFiles []*os.File) *PodmanSessionIntegration {
podmanSession := p.PodmanAsUserBase(args, 0, 0, "", nil, false, false, nil, extraFiles)
return &PodmanSessionIntegration{podmanSession}
}
// PodmanNoCache calls podman with out adding the imagecache // PodmanNoCache calls podman with out adding the imagecache
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration { func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
podmanSession := p.PodmanBase(args, false, true) podmanSession := p.PodmanBase(args, false, true)

View File

@ -27,6 +27,12 @@ func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration
return &PodmanSessionIntegration{podmanSession} return &PodmanSessionIntegration{podmanSession}
} }
// PodmanExtraFiles is the exec call to podman on the filesystem and passes down extra files
func (p *PodmanTestIntegration) PodmanExtraFiles(args []string, extraFiles []*os.File) *PodmanSessionIntegration {
podmanSession := p.PodmanAsUserBase(args, 0, 0, "", nil, false, false, extraFiles)
return &PodmanSessionIntegration{podmanSession}
}
// PodmanNoCache calls the podman command with no configured imagecache // PodmanNoCache calls the podman command with no configured imagecache
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration { func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
podmanSession := p.PodmanBase(args, false, true) podmanSession := p.PodmanBase(args, false, true)
@ -42,7 +48,7 @@ func (p *PodmanTestIntegration) PodmanNoEvents(args []string) *PodmanSessionInte
// PodmanAsUser is the exec call to podman on the filesystem with the specified uid/gid and environment // PodmanAsUser is the exec call to podman on the filesystem with the specified uid/gid and environment
func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd string, env []string) *PodmanSessionIntegration { func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd string, env []string) *PodmanSessionIntegration {
podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false, false) podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false, false, nil)
return &PodmanSessionIntegration{podmanSession} return &PodmanSessionIntegration{podmanSession}
} }

View File

@ -23,7 +23,7 @@ var _ = Describe("PodmanTest test", func() {
FakeOutputs["check"] = []string{"check"} FakeOutputs["check"] = []string{"check"}
os.Setenv("HOOK_OPTION", "hook_option") os.Setenv("HOOK_OPTION", "hook_option")
env := os.Environ() env := os.Environ()
session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true, false) session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true, false, nil)
os.Unsetenv("HOOK_OPTION") os.Unsetenv("HOOK_OPTION")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.Command.Process).ShouldNot(BeNil()) Expect(session.Command.Process).ShouldNot(BeNil())

View File

@ -65,7 +65,7 @@ func (p *PodmanTest) MakeOptions(args []string, noEvents, noCache bool) []string
// PodmanAsUserBase exec podman as user. uid and gid is set for credentials usage. env is used // PodmanAsUserBase exec podman as user. uid and gid is set for credentials usage. env is used
// to record the env for debugging // to record the env for debugging
func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, noEvents, noCache bool) *PodmanSession { func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, noEvents, noCache bool, extraFiles []*os.File) *PodmanSession {
var command *exec.Cmd var command *exec.Cmd
podmanOptions := p.MakeOptions(args, noEvents, noCache) podmanOptions := p.MakeOptions(args, noEvents, noCache)
podmanBinary := p.PodmanBinary podmanBinary := p.PodmanBinary
@ -93,6 +93,8 @@ func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string
command.Dir = cwd command.Dir = cwd
} }
command.ExtraFiles = extraFiles
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
if err != nil { if err != nil {
Fail(fmt.Sprintf("unable to run podman command: %s\n%v", strings.Join(podmanOptions, " "), err)) Fail(fmt.Sprintf("unable to run podman command: %s\n%v", strings.Join(podmanOptions, " "), err))
@ -102,7 +104,7 @@ func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string
// PodmanBase exec podman with default env. // PodmanBase exec podman with default env.
func (p *PodmanTest) PodmanBase(args []string, noEvents, noCache bool) *PodmanSession { func (p *PodmanTest) PodmanBase(args []string, noEvents, noCache bool) *PodmanSession {
return p.PodmanAsUserBase(args, 0, 0, "", nil, noEvents, noCache) return p.PodmanAsUserBase(args, 0, 0, "", nil, noEvents, noCache, nil)
} }
// WaitForContainer waits on a started container // WaitForContainer waits on a started container