From 81f84023bef5e94dfbcfbb44443bc03707b355c4 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Thu, 8 Jan 2015 14:51:47 -0800 Subject: [PATCH] `docker ps --filter exited=status` should not show running containers Docker-DCO-1.1-Signed-off-by: Jessica Frazelle (github: jfrazelle) --- daemon/list.go | 5 ++--- integration-cli/docker_cli_ps_test.go | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/daemon/list.go b/daemon/list.go index 937cdd2123..6c86b6f297 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -73,7 +73,6 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status { if !container.Running && !all && n <= 0 && since == "" && before == "" { return nil } - if !psFilters.Match("name", container.Name) { return nil } @@ -96,10 +95,10 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status { return errLast } } - if len(filt_exited) > 0 && !container.Running { + if len(filt_exited) > 0 { should_skip := true for _, code := range filt_exited { - if code == container.ExitCode { + if code == container.ExitCode && !container.Running { should_skip = false break } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 09207826bb..1318b9efd3 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -398,11 +398,15 @@ func TestPsListContainersFilterName(t *testing.T) { } func TestPsListContainersFilterExited(t *testing.T) { - deleteAllContainers() defer deleteAllContainers() - runCmd := exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true") - out, _, err := runCommandWithOutput(runCmd) - if err != nil { + + runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top") + if out, _, err := runCommandWithOutput(runCmd); err != nil { + t.Fatal(out, err) + } + + runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true") + if out, _, err := runCommandWithOutput(runCmd); err != nil { t.Fatal(out, err) } firstZero, err := getIDByName("zero1") @@ -411,8 +415,7 @@ func TestPsListContainersFilterExited(t *testing.T) { } runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true") - out, _, err = runCommandWithOutput(runCmd) - if err != nil { + if out, _, err := runCommandWithOutput(runCmd); err != nil { t.Fatal(out, err) } secondZero, err := getIDByName("zero2") @@ -421,8 +424,7 @@ func TestPsListContainersFilterExited(t *testing.T) { } runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false") - out, _, err = runCommandWithOutput(runCmd) - if err == nil { + if out, _, err := runCommandWithOutput(runCmd); err == nil { t.Fatal("Should fail.", out, err) } firstNonZero, err := getIDByName("nonzero1") @@ -431,8 +433,7 @@ func TestPsListContainersFilterExited(t *testing.T) { } runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false") - out, _, err = runCommandWithOutput(runCmd) - if err == nil { + if out, _, err := runCommandWithOutput(runCmd); err == nil { t.Fatal("Should fail.", out, err) } secondNonZero, err := getIDByName("nonzero2") @@ -442,7 +443,7 @@ func TestPsListContainersFilterExited(t *testing.T) { // filter containers by exited=0 runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") - out, _, err = runCommandWithOutput(runCmd) + out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatal(out, err) } @@ -472,5 +473,6 @@ func TestPsListContainersFilterExited(t *testing.T) { if ids[1] != firstNonZero { t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1]) } + logDone("ps - test ps filter exited") }