From 28043dfd7d1147347d999e5b051811919f51e93b Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Mon, 4 May 2015 04:43:05 -0400 Subject: [PATCH 1/2] check status code in exec Signed-off-by: Xian Chaobo --- api/handlers.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/handlers.go b/api/handlers.go index b2c552b8d5..3560339ff5 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -325,6 +325,17 @@ func postContainersExec(c *context, w http.ResponseWriter, r *http.Request) { defer resp.Body.Close() defer closeIdleConnections(client) + // check status code + if resp.StatusCode < 200 || resp.StatusCode >= 400 { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + return + } + httpError(w, string(body), http.StatusInternalServerError) + return + } + data, err := ioutil.ReadAll(resp.Body) if err != nil { httpError(w, err.Error(), http.StatusInternalServerError) From a313f46bb879771faf216c60579584167f4b8ba9 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Tue, 5 May 2015 04:55:17 -0400 Subject: [PATCH 2/2] add test when container is not running Signed-off-by: Xian Chaobo --- test/integration/api.bats | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 8d16247f8f..1fe7d6fa92 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -190,7 +190,15 @@ function teardown() { @test "docker exec" { start_docker 3 swarm_manage - run docker_swarm run -d --name test_container busybox sleep 100 + run docker_swarm create --name test_container busybox sleep 100 + [ "$status" -eq 0 ] + + # if container is not runing, exec will failed + run docker_swarm exec test_container ls + [ "$status" -ne 0 ] + [[ "$output" == *"is not running"* ]] + + run docker_swarm start test_container [ "$status" -eq 0 ] # make sure container is up and not paused