Skip to content

Commit

Permalink
Give summary when failed to pause containers
Browse files Browse the repository at this point in the history
When we failed to pause one or more containers, besides the error
message for each container, we should give a more useful summary
information e.g. "failed to pause containers: ctrA,ctrB", instead of
"one or more of the container deletions failed", the old summary info is
totally useless.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
  • Loading branch information
WeiZhang555 committed Oct 28, 2016
1 parent fcdc1a4 commit 71a48ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions pause.go
Expand Up @@ -5,6 +5,7 @@ package main
import (
"fmt"
"os"
"strings"

"github.com/urfave/cli"
)
Expand All @@ -20,7 +21,7 @@ paused. `,
Use runc list to identiy instances of containers and their current status.`,
Action: func(context *cli.Context) error {
hasError := false
var failedOnes []string
if !context.Args().Present() {
return fmt.Errorf("runc: \"pause\" requires a minimum of 1 argument")
}
Expand All @@ -34,17 +35,17 @@ Use runc list to identiy instances of containers and their current status.`,
container, err := factory.Load(id)
if err != nil {
fmt.Fprintf(os.Stderr, "container %s does not exist\n", id)
hasError = true
failedOnes = append(failedOnes, id)
continue
}
if err := container.Pause(); err != nil {
fmt.Fprintf(os.Stderr, "pause container %s : %s\n", id, err)
hasError = true
failedOnes = append(failedOnes, id)
}
}

if hasError {
return fmt.Errorf("one or more of container pause failed")
if len(failedOnes) > 0 {
return fmt.Errorf("failed to pause containers: %s", strings.Join(failedOnes, ","))
}
return nil
},
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/pause.bats
Expand Up @@ -85,9 +85,10 @@ function teardown() {

wait_for_container 15 1 test_busybox2

# pause test_busybox1, test_busybox2 and nonexistant container
runc pause test_busybox1 test_busybox2 nonexistant
# pause test_busybox1, test_busybox2 and nonexistent container
runc pause test_busybox1 test_busybox2 nonexistent
[ "$status" -ne 0 ]
[[ ${lines[-1]} =~ "failed to pause containers: nonexistent ]]
# test state of test_busybox1 and test_busybox2 is paused
testcontainer test_busybox1 paused
Expand Down

0 comments on commit 71a48ae

Please sign in to comment.