Fix up attach tests for podman remote

When we execute podman-remote attach, we were not checking if the
container was in the correct state, this is leading to timeouts and
we had turned off remote testing.

Also added an IfRemote() function so we can turn on more tests when
using the "-l" flag for local, but use container name for remote.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2020-09-21 17:42:22 -04:00
parent fffcc25d8d
commit f949cfddaa
5 changed files with 27 additions and 4 deletions

@ -389,6 +389,15 @@ func (ic *ContainerEngine) ContainerLogs(_ context.Context, nameOrIDs []string,
} }
func (ic *ContainerEngine) ContainerAttach(ctx context.Context, nameOrID string, options entities.AttachOptions) error { func (ic *ContainerEngine) ContainerAttach(ctx context.Context, nameOrID string, options entities.AttachOptions) error {
ctrs, err := getContainersByContext(ic.ClientCxt, false, false, []string{nameOrID})
if err != nil {
return err
}
ctr := ctrs[0]
if ctr.State != define.ContainerStateRunning.String() {
return errors.Errorf("you can only attach to running containers")
}
return containers.Attach(ic.ClientCxt, nameOrID, &options.DetachKeys, nil, bindings.PTrue, options.Stdin, options.Stdout, options.Stderr, nil) return containers.Attach(ic.ClientCxt, nameOrID, &options.DetachKeys, nil, bindings.PTrue, options.Stdin, options.Stdout, options.Stderr, nil)
} }

@ -40,7 +40,6 @@ var _ = Describe("Podman attach", func() {
}) })
It("podman attach to non-running container", func() { It("podman attach to non-running container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"create", "--name", "test1", "-d", "-i", ALPINE, "ls"}) session := podmanTest.Podman([]string{"create", "--name", "test1", "-d", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -51,8 +50,8 @@ var _ = Describe("Podman attach", func() {
}) })
It("podman container attach to non-running container", func() { It("podman container attach to non-running container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-d", "-i", ALPINE, "ls"}) session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-d", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -87,7 +86,6 @@ var _ = Describe("Podman attach", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
}) })
It("podman attach to the latest container", func() { It("podman attach to the latest container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"}) session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -96,7 +94,11 @@ var _ = Describe("Podman attach", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"attach", "-l"}) cid := "-l"
if IsRemote() {
cid = "test2"
}
results := podmanTest.Podman([]string{"attach", cid})
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
results.Signal(syscall.SIGTSTP) results.Signal(syscall.SIGTSTP)
Expect(results.OutputToString()).To(ContainSubstring("test2")) Expect(results.OutputToString()).To(ContainSubstring("test2"))

@ -19,6 +19,10 @@ import (
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
) )
func IsRemote() bool {
return true
}
func SkipIfRemote() { func SkipIfRemote() {
ginkgo.Skip("This function is not enabled for remote podman") ginkgo.Skip("This function is not enabled for remote podman")
} }

@ -12,6 +12,10 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
) )
func IsRemote() bool {
return false
}
func SkipIfRemote() { func SkipIfRemote() {
} }

@ -19,6 +19,10 @@ import (
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
) )
func IsRemote() bool {
return true
}
func SkipIfRemote() { func SkipIfRemote() {
ginkgo.Skip("This function is not enabled for remote podman") ginkgo.Skip("This function is not enabled for remote podman")
} }