From b56ff7678cefdefe750a1b598f7454e16c98bf77 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Tue, 15 Sep 2015 17:06:51 +0100 Subject: [PATCH] Make code coverage work through the proxy Previously, the proxy would run the weave script in ways that did not run the weaver executable. Now they can. This is a problem because of the contortions involved in using golang's code coverage support in the integration tests, which require the weaver command line args to be slightly mangled. --- proxy/common.go | 19 ++++++++++++++++--- proxy/proxy.go | 12 +++++++----- weave | 2 ++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/proxy/common.go b/proxy/common.go index 068e1712..02de6009 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -24,15 +24,28 @@ var ( func callWeave(args ...string) ([]byte, []byte, error) { args = append([]string{"--local"}, args...) - Log.Debug("Calling weave", args) cmd := exec.Command("./weave", args...) cmd.Env = []string{ "PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PROCFS=/hostproc", } - if bridge := os.Getenv("DOCKER_BRIDGE"); bridge != "" { - cmd.Env = append(cmd.Env, fmt.Sprintf("DOCKER_BRIDGE=%s", bridge)) + + propagateEnv := func(key string) { + if val := os.Getenv(key); val != "" { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, val)) + } } + + propagateEnv("DOCKER_BRIDGE") + + // Propogage WEAVE_DEBUG, to make debugging easier. + propagateEnv("WEAVE_DEBUG") + + // This prevents the code coverage contortions in our + // integration test suite breaking things. + propagateEnv("COVERAGE") + + Log.Debug("Calling weave args: ", args, "env: ", cmd.Env) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr diff --git a/proxy/proxy.go b/proxy/proxy.go index 8d09292e..f24b3227 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -436,13 +436,15 @@ func (proxy *Proxy) getDNSDomain() (domain string) { } weaveContainer, err := proxy.client.InspectContainer("weave") - if err != nil || - weaveContainer.NetworkSettings == nil || - weaveContainer.NetworkSettings.IPAddress == "" { - return + var weaveIP string + if err == nil && weaveContainer.NetworkSettings != nil { + weaveIP = weaveContainer.NetworkSettings.IPAddress + } + if weaveIP == "" { + weaveIP = "127.0.0.1" } - url := fmt.Sprintf("http://%s:%d/domain", weaveContainer.NetworkSettings.IPAddress, router.HTTPPort) + url := fmt.Sprintf("http://%s:%d/domain", weaveIP, router.HTTPPort) resp, err := http.Get(url) if err != nil || resp.StatusCode != http.StatusOK { return diff --git a/weave b/weave index 554185b4..29c10d22 100755 --- a/weave +++ b/weave @@ -1381,6 +1381,8 @@ launch_proxy() { -e PROCFS=/hostproc \ -e WEAVE_CIDR=none \ -e DOCKER_BRIDGE \ + -e WEAVE_DEBUG \ + -e COVERAGE \ --entrypoint=/home/weave/weaveproxy \ $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS) wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock