From 548b4aea40985dfab20256e56516820e0ee4a80d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 27 Aug 2015 14:54:20 +0100 Subject: [PATCH 1/5] Call to docker-py changed upstream --- test/600_proxy_docker_py_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/600_proxy_docker_py_test.sh b/test/600_proxy_docker_py_test.sh index 84d27608a5..cae5f228e2 100755 --- a/test/600_proxy_docker_py_test.sh +++ b/test/600_proxy_docker_py_test.sh @@ -13,7 +13,7 @@ if docker_on $HOST1 run \ -e DOCKER_HOST=tcp://172.17.42.1:12375 \ -v /tmp:/tmp \ -v /var/run/docker.sock:/var/run/docker.sock \ - joffrey/docker-py python tests/integration_test.py ; then + joffrey/docker-py py.test tests/integration_test.py ; then assert_raises "true" else assert_raises "false" From 7652b44c21fd0f0311e49a128e22fe731b9f3190 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 27 Aug 2015 15:14:06 +0100 Subject: [PATCH 2/5] Ensure we have the busybox image --- test/600_proxy_docker_py_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/600_proxy_docker_py_test.sh b/test/600_proxy_docker_py_test.sh index cae5f228e2..c7c8a1b6ea 100755 --- a/test/600_proxy_docker_py_test.sh +++ b/test/600_proxy_docker_py_test.sh @@ -5,6 +5,7 @@ start_suite "Run docker-py test suite against the proxy" docker_on $HOST1 pull joffrey/docker-py >/dev/null +docker_on $HOST1 pull busybox >/dev/null weave_on $HOST1 launch-proxy --no-default-ipam From 6b5f35e5744201af9545ec66f2b38eb912e37850 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 28 Aug 2015 15:09:33 +0100 Subject: [PATCH 3/5] [proxy] Only replace the request body if we've modified it. This is a temporary fix for a failure in docker-py tests: "test_valid_no_config_specified". --- proxy/create_container_interceptor.go | 13 +++++++------ proxy/create_exec_interceptor.go | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 42b60ed1e1..2983c6e0fc 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -45,6 +45,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { return err } r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(body)) container := createContainerRequestBody{} if err := json.Unmarshal(body, &container); err != nil { @@ -68,14 +69,14 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if err := i.setWeaveDNS(&container, r); err != nil { return err } - } - newBody, err := json.Marshal(container) - if err != nil { - return err + newBody, err := json.Marshal(container) + if err != nil { + return err + } + r.Body = ioutil.NopCloser(bytes.NewReader(newBody)) + r.ContentLength = int64(len(newBody)) } - r.Body = ioutil.NopCloser(bytes.NewReader(newBody)) - r.ContentLength = int64(len(newBody)) return nil } diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index f15ed56f25..841ff1459f 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -1,6 +1,7 @@ package proxy import ( + "bytes" "encoding/json" "io/ioutil" "net/http" @@ -18,6 +19,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { return err } r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(body)) options := docker.CreateExecOptions{} if err := json.Unmarshal(body, &options); err != nil { @@ -37,10 +39,10 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) cmd := append(weaveWaitEntrypoint, "-s") options.Cmd = append(cmd, options.Cmd...) - } - if err := marshalRequestBody(r, options); err != nil { - return err + if err := marshalRequestBody(r, options); err != nil { + return err + } } return nil From 24de98e188fc428397eae4452583d46112633a58 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 28 Aug 2015 18:08:24 +0100 Subject: [PATCH 4/5] refactor --- proxy/create_exec_interceptor.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index 841ff1459f..2ba19a6116 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -31,21 +31,21 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { return err } - _, hasWeaveWait := container.Volumes["/w"] + if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait { + return nil + } + cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig) if err != nil { Info.Printf("Ignoring container %s due to %s", container.ID, err) - } else if hasWeaveWait { - Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) - cmd := append(weaveWaitEntrypoint, "-s") - options.Cmd = append(cmd, options.Cmd...) - - if err := marshalRequestBody(r, options); err != nil { - return err - } + return nil } - return nil + Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) + cmd := append(weaveWaitEntrypoint, "-s") + options.Cmd = append(cmd, options.Cmd...) + + return marshalRequestBody(r, options) } func (i *createExecInterceptor) InterceptResponse(r *http.Response) error { From fef91b5339b59d3a772e8c6e66965c7fd4022418 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 28 Aug 2015 18:09:23 +0100 Subject: [PATCH 5/5] comment --- test/600_proxy_docker_py_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/600_proxy_docker_py_test.sh b/test/600_proxy_docker_py_test.sh index c7c8a1b6ea..57cc9b7c1c 100755 --- a/test/600_proxy_docker_py_test.sh +++ b/test/600_proxy_docker_py_test.sh @@ -5,6 +5,7 @@ start_suite "Run docker-py test suite against the proxy" docker_on $HOST1 pull joffrey/docker-py >/dev/null +# workaround for https://github.com/docker/docker-py/issues/745 docker_on $HOST1 pull busybox >/dev/null weave_on $HOST1 launch-proxy --no-default-ipam