From 18c26e9fbbbed83cb097abf0315435d6634bc666 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 1 Feb 2016 12:04:15 +0000 Subject: [PATCH] don't set the interface 'up' before it is fully configured This was causing container entrypoints to execute too early, e.g. before the interface had been given an IP address. But only when running with --no-multicast-route, since otherwise weavewait is waiting for the multicast route to appear. Fixes #1942. --- test/610_proxy_wait_for_weave_test.sh | 15 +++++++++++++-- weave | 8 ++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/test/610_proxy_wait_for_weave_test.sh b/test/610_proxy_wait_for_weave_test.sh index 7525d4e028..a89edaf772 100755 --- a/test/610_proxy_wait_for_weave_test.sh +++ b/test/610_proxy_wait_for_weave_test.sh @@ -6,15 +6,26 @@ entrypoint() { docker_on $HOST1 inspect --format="{{.Config.Entrypoint}}" "$@" } +check_iface_ready() { + assert_raises "proxy docker_on $HOST1 run -e 'WEAVE_CIDR=$1' $BASE_IMAGE $CHECK_ETHWE_UP" + assert_raises "proxy docker_on $HOST1 run -e 'WEAVE_CIDR=$1' $BASE_IMAGE ip -4 -o addr show ethwe | grep -q '$1'" +} + start_suite "Proxy waits for weave to be ready before running container commands" -weave_on $HOST1 launch-proxy + BASE_IMAGE=busybox # Ensure the base image does not exist, so that it will be pulled ! docker_on $HOST1 inspect --format=" " $BASE_IMAGE >/dev/null 2>&1 || docker_on $HOST1 rmi $BASE_IMAGE -assert_raises "proxy docker_on $HOST1 run --name c1 -e 'WEAVE_CIDR=10.2.1.1/24' $BASE_IMAGE $CHECK_ETHWE_UP" +# check that interface is ready, with and without --no-multicast-route +weave_on $HOST1 launch-proxy --no-multicast-route +check_iface_ready 10.2.1.1/24 +weave_on $HOST1 stop-proxy +weave_on $HOST1 launch-proxy +check_iface_ready 10.2.1.1/24 # Check committed containers only have one weavewait prepended +proxy_start_container $HOST1 --name c1 -e 'WEAVE_CIDR=10.2.1.1/24' COMMITTED_IMAGE=$(proxy docker_on $HOST1 commit c1) assert_raises "proxy docker_on $HOST1 run --name c2 $COMMITTED_IMAGE" assert "entrypoint c2" "$(entrypoint $COMMITTED_IMAGE)" diff --git a/weave b/weave index 77d03f8ce8..f4dd5393f5 100755 --- a/weave +++ b/weave @@ -763,11 +763,11 @@ connect_container_to_bridge() { # veth pair in the 'up' or 'down' state. Furthermore, moving one # end into a netns normally sets them to 'down'. But, moving an # end into the default netns is a null operation, so they stay up, - # which leads to errors later on. So to get a consistent result, - # we have to be explicit in setting them 'up' or 'down' as - # necessary. + # which leads to errors in 'set name' since that requires the + # interface to be down. So to get a consistent result, we set the + # interface 'down' to begin with. if ! netnsenter ip link set $GUEST_IFNAME down || - ! netnsenter ip link set $GUEST_IFNAME name $1 up || + ! netnsenter ip link set $GUEST_IFNAME name $1 || ! ip link set $LOCAL_IFNAME up || ! add_iface_$BRIDGE_TYPE $LOCAL_IFNAME || ! configure_arp_cache $1 "netnsenter" ; then