[proxy] Fix bug in weave env/config when passing multiple -H flags

The echo in proxy_addr was not preserving newlines, so the multiple
addrs were all getting returned
This commit is contained in:
Paul Bellamy committed 2015-10-14 11:58:10 +01:00
1 parent d5e63b875b
commit fd07f59d16
2 files changed
+26 -11

No files matched your search

+13 -4
View File
@@ -2,6 +2,13 @@
. ./config.sh . ./config.sh
CMD="run -e WEAVE_CIDR=10.2.1.4/24 $SMALL_IMAGE $CHECK_ETHWE_UP"
check() {
assert_raises "eval '$(weave_on $HOST1 env)' ; docker $CMD"
assert_raises "docker $(weave_on $HOST1 config) $CMD"
}
start_suite "Configure the docker daemon for the proxy" start_suite "Configure the docker daemon for the proxy"
# No output when nothing running # No output when nothing running
@@ -9,14 +16,16 @@ assert "weave_on $HOST1 env" ""
assert "weave_on $HOST1 config" "" assert "weave_on $HOST1 config" ""
weave_on $HOST1 launch-proxy weave_on $HOST1 launch-proxy
check
CMD="run -e WEAVE_CIDR=10.2.1.4/24 $SMALL_IMAGE $CHECK_ETHWE_UP"
assert_raises "eval '$(weave_on $HOST1 env)' ; docker $CMD"
assert_raises "docker $(weave_on $HOST1 config) $CMD"
# Check we can use the weave script through the proxy # Check we can use the weave script through the proxy
assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE version" assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE version"
assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE ps" assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE ps"
assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE launch-router" assert_raises "eval '$(weave_on $HOST1 env)' ; $WEAVE launch-router"
# Check we can use weave env/config with multiple -Hs specified
weave_on $HOST1 stop
weave_on $HOST1 launch-proxy -H tcp://0.0.0.0:12375 -H unix:///var/run/weave/weave.sock
check
end_suite end_suite
+13 -7
View File
@@ -1072,15 +1072,21 @@ proxy_args() {
fi fi
} }
proxy_addr() { proxy_addrs() {
if addr=$(http_call_unix $PROXY_CONTAINER_NAME status.sock GET /status 2>&1) ; then if addr="$(http_call_unix $PROXY_CONTAINER_NAME status.sock GET /status 2>&1)" ; then
echo "$addr" | head -n1 | sed "s/0.0.0.0/$PROXY_HOST/g" echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g"
else else
echo "$PROXY_CONTAINER_NAME container is not present. Have you launched it?" >&2 echo "$PROXY_CONTAINER_NAME container is not present. Have you launched it?" >&2
return 1 return 1
fi fi
} }
proxy_addr() {
addr=$(proxy_addrs) || return 1
echo "$addr" | cut -d ' ' -f1
}
warn_if_stopping_proxy_in_env() { warn_if_stopping_proxy_in_env() {
if PROXY_ADDR=$(proxy_addr 2>/dev/null) ; then if PROXY_ADDR=$(proxy_addr 2>/dev/null) ; then
[ "$PROXY_ADDR" != "$DOCKER_CLIENT_HOST" ] || echo "WARNING: It appears that your environment is configured to use the Weave Docker API proxy. Stopping it will break this and subsequent docker invocations. To restore your environment, run 'eval \$(weave env --restore)'." [ "$PROXY_ADDR" != "$DOCKER_CLIENT_HOST" ] || echo "WARNING: It appears that your environment is configured to use the Weave Docker API proxy. Stopping it will break this and subsequent docker invocations. To restore your environment, run 'eval \$(weave env --restore)'."
@@ -1377,8 +1383,8 @@ case "$COMMAND" in
;; ;;
config|proxy-config) config|proxy-config)
[ "$COMMAND" = "config" ] || deprecation_warning "$COMMAND" "'weave config'" [ "$COMMAND" = "config" ] || deprecation_warning "$COMMAND" "'weave config'"
if PROXY_addr=$(proxy_addr) ; then if PROXY_ADDR=$(proxy_addr) ; then
echo "-H=$PROXY_addr" echo "-H=$PROXY_ADDR"
fi fi
;; ;;
connect) connect)
@@ -1419,10 +1425,10 @@ case "$COMMAND" in
else else
res=1 res=1
fi fi
if [ -z "$SUB_STATUS" ] && check_running $PROXY_CONTAINER_NAME 2>/dev/null && PROXY_ADDR=$(proxy_addr) ; then if [ -z "$SUB_STATUS" ] && check_running $PROXY_CONTAINER_NAME 2>/dev/null && PROXY_ADDRS=$(proxy_addrs) ; then
echo echo
echo " Service: proxy" echo " Service: proxy"
echo " Address: $PROXY_ADDR" echo " Address: $PROXY_ADDRS"
fi fi
[ -n "$SUB_STATUS" ] || echo [ -n "$SUB_STATUS" ] || echo
[ $res -eq 0 ] [ $res -eq 0 ]