Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Fix docker api proxy smoke-tests after docker-py change (on 1.0 branch) #1367

Merged
merged 5 commits into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions proxy/create_container_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions proxy/create_exec_interceptor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proxy

import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
Expand All @@ -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 {
Expand All @@ -29,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...)
return nil
}

if err := marshalRequestBody(r, options); err != nil {
return err
}
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 nil
return marshalRequestBody(r, options)
}

func (i *createExecInterceptor) InterceptResponse(r *http.Response) error {
Expand Down
4 changes: 3 additions & 1 deletion test/600_proxy_docker_py_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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

This comment was marked as abuse.


weave_on $HOST1 launch-proxy --no-default-ipam

Expand All @@ -13,7 +15,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"
Expand Down