Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make stop stopped container return no error #1209

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,9 @@ func (mgr *ContainerManager) Stop(ctx context.Context, name string, timeout int6
c.Lock()
defer c.Unlock()

if !c.IsRunning() {
return fmt.Errorf("container's status is not running: %s", c.meta.State.Status)
if c.IsStopped() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a new container, it's status is "created", actually, the container is stopped, but IsStopped() will return false

// stopping a stopped container is valid.
return nil
}

if timeout == 0 {
Expand All @@ -720,7 +721,7 @@ func (mgr *ContainerManager) Stop(ctx context.Context, name string, timeout int6
func (mgr *ContainerManager) stop(ctx context.Context, c *Container, timeout int64) error {
msg, err := mgr.Client.DestroyContainer(ctx, c.ID(), timeout)
if err != nil {
return errors.Wrapf(err, "failed to destroy container: %s", c.ID())
return errors.Wrapf(err, "failed to destroy container %s", c.ID())
}

return mgr.markStoppedAndRelease(c, msg)
Expand Down
3 changes: 3 additions & 0 deletions test/cli_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (suite *PouchStopSuite) TestStopWorks(c *check.C) {

command.PouchRun("start", name).Assert(c, icmd.Success)

// test stop a running container
command.PouchRun("stop", name).Assert(c, icmd.Success)
// test stop a stopped container
command.PouchRun("stop", name).Assert(c, icmd.Success)

res := command.PouchRun("ps", "-a")
Expand Down