Skip to content

Commit

Permalink
Merge pull request #7717 from rhatdan/attach
Browse files Browse the repository at this point in the history
Fix up attach tests for podman remote
  • Loading branch information
openshift-merge-robot authored Sep 22, 2020
2 parents 141688c + f949cfd commit 6900b5a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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)
}

Expand Down
10 changes: 6 additions & 4 deletions test/e2e/attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var _ = Describe("Podman attach", func() {
})

It("podman attach to non-running container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"create", "--name", "test1", "-d", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expand All @@ -51,8 +50,8 @@ var _ = Describe("Podman attach", func() {
})

It("podman container attach to non-running container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-d", "-i", ALPINE, "ls"})

session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand Down Expand Up @@ -87,7 +86,6 @@ var _ = Describe("Podman attach", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})
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.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expand All @@ -96,7 +94,11 @@ var _ = Describe("Podman attach", func() {
session.WaitWithDefaultTimeout()
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)
results.Signal(syscall.SIGTSTP)
Expect(results.OutputToString()).To(ContainSubstring("test2"))
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/libpod_suite_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/onsi/ginkgo"
)

func IsRemote() bool {
return true
}

func SkipIfRemote() {
ginkgo.Skip("This function is not enabled for remote podman")
}
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/libpod_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
. "github.com/onsi/ginkgo"
)

func IsRemote() bool {
return false
}

func SkipIfRemote() {
}

Expand Down
4 changes: 4 additions & 0 deletions test/e2e/libpod_suite_varlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/onsi/ginkgo"
)

func IsRemote() bool {
return true
}

func SkipIfRemote() {
ginkgo.Skip("This function is not enabled for remote podman")
}
Expand Down

0 comments on commit 6900b5a

Please sign in to comment.