From aa028f4d092e589f446e1e5b02bc9d00cda94c3e Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 28 Jan 2016 11:28:19 -0800 Subject: [PATCH 1/2] Host Down containers in ps requires -a Signed-off-by: Victor Vieux --- api/handlers.go | 4 ++-- test/integration/api/ps.bats | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index eef7dd9457..d75c6d3e6b 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -327,8 +327,8 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { // Filtering: select the containers we want to return. candidates := []*cluster.Container{} for _, container := range c.cluster.Containers() { - // Skip stopped containers unless -a was specified. - if !container.Info.State.Running && !all && before == nil && limit <= 0 { + // Skip stopped containers unless -a was specified + if (!container.Info.State.Running || !container.Engine.IsHealthy()) && !all && before == nil && limit <= 0 { continue } diff --git a/test/integration/api/ps.bats b/test/integration/api/ps.bats index 374771eb70..c2ce5816cb 100644 --- a/test/integration/api/ps.bats +++ b/test/integration/api/ps.bats @@ -7,6 +7,30 @@ function teardown() { stop_docker } +@test "docker ps - host down" { + start_docker_with_busybox 2 + swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]} + + docker_swarm run -d -e constraint:node==node-0 busybox sleep 42 + docker_swarm run -d -e constraint:node==node-1 busybox sleep 42 + + run docker_swarm ps + [ "${#lines[@]}" -eq 3 ] + + # Stop node-0 + docker_host stop ${DOCKER_CONTAINERS[0]} + + # Wait for Swarm to detect the node failure. + retry 5 1 eval "docker_swarm info | grep -q 'Unhealthy'" + + run docker_swarm ps + # container with host down shouldn't be displyed since they are not `running` + [ "${#lines[@]}" -eq 2 ] + + run docker_swarm ps -a + [ "${#lines[@]}" -eq 3 ] +} + @test "docker ps -n" { start_docker_with_busybox 2 swarm_manage From 2cc980e4abc2752a2a763380821fb0817772544f Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 28 Jan 2016 11:46:31 -0800 Subject: [PATCH 2/2] check the container started successfully after reschedule Signed-off-by: Victor Vieux --- test/integration/rescheduling.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/rescheduling.bats b/test/integration/rescheduling.bats index f96e70dac2..ab8bc8245a 100644 --- a/test/integration/rescheduling.bats +++ b/test/integration/rescheduling.bats @@ -67,6 +67,9 @@ function teardown() { run docker_swarm inspect c3 [ "$status" -eq 0 ] [[ "${output}" == *'"Name": "node-1"'* ]] + + run docker_swarm ps -q + [ "${#lines[@]}" -eq 2 ] } @test "rescheduling with constraints" {