mirror of
https://github.com/containers/podman.git
synced 2025-06-08 00:00:51 +08:00
Fix #2521
* Bad merge against podman stop, restored overwritten code Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/adapter/shortcuts"
|
"github.com/containers/libpod/pkg/adapter/shortcuts"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetLatestContainer gets the latest Container and wraps it in an adapter Container
|
// 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.
|
// 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
|
// 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) {
|
func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopValues) ([]string, map[string]error, error) {
|
||||||
timeout := uint(0)
|
var timeout *uint
|
||||||
if cli.Flags().Changed("timeout") {
|
if cli.Flags().Changed("timeout") || cli.Flags().Changed("time") {
|
||||||
timeout = uint(cli.Timeout)
|
t := uint(cli.Timeout)
|
||||||
|
timeout = &t
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -61,11 +63,18 @@ func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range ctrs {
|
for _, c := range ctrs {
|
||||||
err := c.StopWithTimeout(timeout)
|
if timeout == nil {
|
||||||
if err != nil && errors.Cause(err) != libpod.ErrCtrStopped {
|
t := c.StopTimeout()
|
||||||
failures[c.ID()] = err
|
timeout = &t
|
||||||
} else {
|
logrus.Debugf("Set timeout to container %s default (%d)", c.ID(), *timeout)
|
||||||
|
}
|
||||||
|
if err := c.StopWithTimeout(*timeout); err == nil {
|
||||||
ok = append(ok, c.ID())
|
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
|
return ok, failures, nil
|
||||||
|
@ -82,7 +82,7 @@ var _ = Describe("Podman stop", func() {
|
|||||||
Expect(session3.ExitCode()).To(Equal(0))
|
Expect(session3.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman stop all containers", func() {
|
It("podman stop all containers -t", func() {
|
||||||
session := podmanTest.RunTopContainer("test1")
|
session := podmanTest.RunTopContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -107,6 +107,32 @@ var _ = Describe("Podman stop", func() {
|
|||||||
Expect(output).To(ContainSubstring(cid3))
|
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() {
|
It("podman stop latest containers", func() {
|
||||||
session := podmanTest.RunTopContainer("test1")
|
session := podmanTest.RunTopContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user