diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-04 12:24:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 12:24:26 -0800 |
commit | 33be9e6845d74755a6626b9f142f6c264f6b670a (patch) | |
tree | f3d42325eadc8bc4a58fa3289815225763c1fd81 | |
parent | 34bf58c5dbb898ef9f813e79b13735eecc933369 (diff) | |
parent | ae47a7c47e103f22e557de394342054ca801168c (diff) | |
download | podman-33be9e6845d74755a6626b9f142f6c264f6b670a.tar.gz podman-33be9e6845d74755a6626b9f142f6c264f6b670a.tar.bz2 podman-33be9e6845d74755a6626b9f142f6c264f6b670a.zip |
Merge pull request #2523 from jwhonce/bug/2521
Fix #2521
-rw-r--r-- | pkg/adapter/containers.go | 23 | ||||
-rw-r--r-- | test/e2e/stop_test.go | 28 |
2 files changed, 43 insertions, 8 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index b0c75cf49..7514f30d2 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -9,6 +9,7 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/adapter/shortcuts" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // GetLatestContainer gets the latest Container and wraps it in an adapter Container @@ -45,9 +46,10 @@ func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) { // StopContainers stops container(s) based on CLI inputs. // Returns list of successful id(s), map of failed id(s) + error, or error not from container func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopValues) ([]string, map[string]error, error) { - timeout := uint(0) - if cli.Flags().Changed("timeout") { - timeout = uint(cli.Timeout) + var timeout *uint + if cli.Flags().Changed("timeout") || cli.Flags().Changed("time") { + t := uint(cli.Timeout) + timeout = &t } var ( @@ -61,11 +63,18 @@ func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopVa } for _, c := range ctrs { - err := c.StopWithTimeout(timeout) - if err != nil && errors.Cause(err) != libpod.ErrCtrStopped { - failures[c.ID()] = err - } else { + if timeout == nil { + t := c.StopTimeout() + timeout = &t + logrus.Debugf("Set timeout to container %s default (%d)", c.ID(), *timeout) + } + if err := c.StopWithTimeout(*timeout); err == nil { ok = append(ok, c.ID()) + } else if errors.Cause(err) == libpod.ErrCtrStopped { + ok = append(ok, c.ID()) + logrus.Debugf("Container %s is already stopped", c.ID()) + } else { + failures[c.ID()] = err } } return ok, failures, nil diff --git a/test/e2e/stop_test.go b/test/e2e/stop_test.go index eb680d2a1..cd0d804ee 100644 --- a/test/e2e/stop_test.go +++ b/test/e2e/stop_test.go @@ -82,7 +82,7 @@ var _ = Describe("Podman stop", func() { Expect(session3.ExitCode()).To(Equal(0)) }) - It("podman stop all containers", func() { + It("podman stop all containers -t", func() { session := podmanTest.RunTopContainer("test1") session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) @@ -107,6 +107,32 @@ var _ = Describe("Podman stop", func() { Expect(output).To(ContainSubstring(cid3)) }) + It("podman stop container --time", func() { + session := podmanTest.RunTopContainer("test4") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid1 := session.OutputToString() + + session = podmanTest.Podman([]string{"stop", "--time", "1", "test4"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + output := session.OutputToString() + Expect(output).To(ContainSubstring(cid1)) + }) + + It("podman stop container --timeout", func() { + session := podmanTest.RunTopContainer("test5") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid1 := session.OutputToString() + + session = podmanTest.Podman([]string{"stop", "--timeout", "1", "test5"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + output := session.OutputToString() + Expect(output).To(ContainSubstring(cid1)) + }) + It("podman stop latest containers", func() { session := podmanTest.RunTopContainer("test1") session.WaitWithDefaultTimeout() |