Fixes #8909
Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
| ... | ... |
@@ -99,7 +99,7 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
|
| 99 | 99 |
if len(filt_exited) > 0 && !container.Running {
|
| 100 | 100 |
should_skip := true |
| 101 | 101 |
for _, code := range filt_exited {
|
| 102 |
- if code == container.GetExitCode() {
|
|
| 102 |
+ if code == container.ExitCode {
|
|
| 103 | 103 |
should_skip = false |
| 104 | 104 |
break |
| 105 | 105 |
} |
| ... | ... |
@@ -396,3 +396,81 @@ func TestPsListContainersFilterName(t *testing.T) {
|
| 396 | 396 |
|
| 397 | 397 |
logDone("ps - test ps filter name")
|
| 398 | 398 |
} |
| 399 |
+ |
|
| 400 |
+func TestPsListContainersFilterExited(t *testing.T) {
|
|
| 401 |
+ deleteAllContainers() |
|
| 402 |
+ defer deleteAllContainers() |
|
| 403 |
+ runCmd := exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true") |
|
| 404 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 405 |
+ if err != nil {
|
|
| 406 |
+ t.Fatal(out, err) |
|
| 407 |
+ } |
|
| 408 |
+ firstZero, err := getIDByName("zero1")
|
|
| 409 |
+ if err != nil {
|
|
| 410 |
+ t.Fatal(err) |
|
| 411 |
+ } |
|
| 412 |
+ |
|
| 413 |
+ runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true") |
|
| 414 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 415 |
+ if err != nil {
|
|
| 416 |
+ t.Fatal(out, err) |
|
| 417 |
+ } |
|
| 418 |
+ secondZero, err := getIDByName("zero2")
|
|
| 419 |
+ if err != nil {
|
|
| 420 |
+ t.Fatal(err) |
|
| 421 |
+ } |
|
| 422 |
+ |
|
| 423 |
+ runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false") |
|
| 424 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 425 |
+ if err == nil {
|
|
| 426 |
+ t.Fatal("Should fail.", out, err)
|
|
| 427 |
+ } |
|
| 428 |
+ firstNonZero, err := getIDByName("nonzero1")
|
|
| 429 |
+ if err != nil {
|
|
| 430 |
+ t.Fatal(err) |
|
| 431 |
+ } |
|
| 432 |
+ |
|
| 433 |
+ runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false") |
|
| 434 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 435 |
+ if err == nil {
|
|
| 436 |
+ t.Fatal("Should fail.", out, err)
|
|
| 437 |
+ } |
|
| 438 |
+ secondNonZero, err := getIDByName("nonzero2")
|
|
| 439 |
+ if err != nil {
|
|
| 440 |
+ t.Fatal(err) |
|
| 441 |
+ } |
|
| 442 |
+ |
|
| 443 |
+ // filter containers by exited=0 |
|
| 444 |
+ runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") |
|
| 445 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 446 |
+ if err != nil {
|
|
| 447 |
+ t.Fatal(out, err) |
|
| 448 |
+ } |
|
| 449 |
+ ids := strings.Split(strings.TrimSpace(out), "\n") |
|
| 450 |
+ if len(ids) != 2 {
|
|
| 451 |
+ t.Fatalf("Should be 2 zero exited containerst got %d", len(ids))
|
|
| 452 |
+ } |
|
| 453 |
+ if ids[0] != secondZero {
|
|
| 454 |
+ t.Fatalf("First in list should be %q, got %q", secondZero, ids[0])
|
|
| 455 |
+ } |
|
| 456 |
+ if ids[1] != firstZero {
|
|
| 457 |
+ t.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
|
|
| 458 |
+ } |
|
| 459 |
+ |
|
| 460 |
+ runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1") |
|
| 461 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 462 |
+ if err != nil {
|
|
| 463 |
+ t.Fatal(out, err) |
|
| 464 |
+ } |
|
| 465 |
+ ids = strings.Split(strings.TrimSpace(out), "\n") |
|
| 466 |
+ if len(ids) != 2 {
|
|
| 467 |
+ t.Fatalf("Should be 2 zero exited containerst got %d", len(ids))
|
|
| 468 |
+ } |
|
| 469 |
+ if ids[0] != secondNonZero {
|
|
| 470 |
+ t.Fatalf("First in list should be %q, got %q", secondNonZero, ids[0])
|
|
| 471 |
+ } |
|
| 472 |
+ if ids[1] != firstNonZero {
|
|
| 473 |
+ t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
|
|
| 474 |
+ } |
|
| 475 |
+ logDone("ps - test ps filter exited")
|
|
| 476 |
+} |