From 671ed724d515aa6ea522f90d631fdd7680d5d46f Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Wed, 11 May 2016 10:45:59 +0100 Subject: [PATCH 1/2] Move wait_for_proxy to config.sh --- test/310_docker_restart_test.sh | 12 ------------ test/640_proxy_restart_reattaches_test.sh | 12 ------------ test/config.sh | 12 ++++++++++++ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/test/310_docker_restart_test.sh b/test/310_docker_restart_test.sh index 5abfd774..24730696 100755 --- a/test/310_docker_restart_test.sh +++ b/test/310_docker_restart_test.sh @@ -8,18 +8,6 @@ check_attached() { done } -wait_for_proxy() { - for i in $(seq 1 120); do - echo "Waiting for proxy to start" - if proxy docker_on $1 info > /dev/null 2>&1 ; then - return - fi - sleep 1 - done - echo "Timed out waiting for proxy to start" >&2 - exit 1 -} - start_suite "Containers get same IP address on restart" weave_on $HOST1 launch-router diff --git a/test/640_proxy_restart_reattaches_test.sh b/test/640_proxy_restart_reattaches_test.sh index 4ea8e04b..17dbbc86 100755 --- a/test/640_proxy_restart_reattaches_test.sh +++ b/test/640_proxy_restart_reattaches_test.sh @@ -9,18 +9,6 @@ check_attached() { assert_dns_record $HOST1 c1 $NAME $C2 } -wait_for_proxy() { - for i in $(seq 1 120); do - echo "Waiting for proxy to start" - if proxy docker_on $1 info > /dev/null 2>&1 ; then - return - fi - sleep 1 - done - echo "Timed out waiting for proxy to start" >&2 - exit 1 -} - N=50 # Create and remove a lot of containers in a small subnet; the failure # mode is that this takes a long time as it has to wait for the old diff --git a/test/config.sh b/test/config.sh index 02ba5630..599194bb 100644 --- a/test/config.sh +++ b/test/config.sh @@ -171,6 +171,18 @@ proxy_start_container_with_dns() { proxy docker_on $host run "$@" -dt $DNS_IMAGE /bin/sh } +wait_for_proxy() { + for i in $(seq 1 120); do + echo "Waiting for proxy to start" + if proxy docker_on $1 info > /dev/null 2>&1 ; then + return + fi + sleep 1 + done + echo "Timed out waiting for proxy to start" >&2 + exit 1 +} + rm_containers() { host=$1 shift From 02d9c090ed2dce41222a73b23a5dd32ea5653bb9 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Thu, 12 May 2016 10:54:46 +0100 Subject: [PATCH 2/2] Add wait_for_attached --- test/140_weave_local_test.sh | 4 ++-- test/310_docker_restart_test.sh | 11 ++-------- test/320_claim_3_test.sh | 16 +-------------- test/640_proxy_restart_reattaches_test.sh | 25 ++++++++++------------- test/config.sh | 14 +++++++++++++ 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/test/140_weave_local_test.sh b/test/140_weave_local_test.sh index ed403d9c..0874923f 100755 --- a/test/140_weave_local_test.sh +++ b/test/140_weave_local_test.sh @@ -16,10 +16,10 @@ weave_local_on $HOST1 launch --ipalloc-range 10.2.5.0/24 assert_raises "docker_on $HOST1 ps | grep weave" weave_local_on $HOST1 run 10.2.6.5/24 -ti --name=c1 $SMALL_IMAGE /bin/sh -assert_raises "exec_on $HOST1 c1 $CHECK_ETHWE_UP" +wait_for_attached $HOST1 c1 weave_local_on $HOST1 run -ti --name=c2 $SMALL_IMAGE /bin/sh -assert_raises "exec_on $HOST1 c2 $CHECK_ETHWE_UP" +wait_for_attached $HOST1 c2 assert "weave_local_on $HOST1 ps | wc -l" 3 diff --git a/test/310_docker_restart_test.sh b/test/310_docker_restart_test.sh index 24730696..d1bff78f 100755 --- a/test/310_docker_restart_test.sh +++ b/test/310_docker_restart_test.sh @@ -2,12 +2,6 @@ . ./config.sh -check_attached() { - for c in $@; do - assert_raises "exec_on $HOST1 $c $CHECK_ETHWE_UP" - done -} - start_suite "Containers get same IP address on restart" weave_on $HOST1 launch-router @@ -19,15 +13,14 @@ start_container $HOST1 --name=c1 proxy docker_on $HOST1 run -di --name=c2 --restart=always -dt --entrypoint="/home/weave/sigproxy" weaveworks/weaveexec sleep 600 C2=$(container_ip $HOST1 c2) assert_raises "[ -n $C2 ]" -check_attached c2 +wait_for_attached $HOST1 c2 docker_on $HOST1 rm -f c1 # Restart docker daemon, using different commands for systemd- and upstart-managed. run_on $HOST1 sh -c "command -v systemctl >/dev/null && sudo systemctl restart docker || sudo service docker restart" wait_for_proxy $HOST1 -sleep 3 # allow for re-tries of attach -check_attached c2 +wait_for_attached $HOST1 c2 # Check same IP address was retained assert "container_ip $HOST1 c2" "$C2" diff --git a/test/320_claim_3_test.sh b/test/320_claim_3_test.sh index 2584098e..6f9b8602 100755 --- a/test/320_claim_3_test.sh +++ b/test/320_claim_3_test.sh @@ -13,20 +13,6 @@ delete_persistence() { done } -wait_for_container_ip() { - host=$1 - container=$2 - for i in $(seq 1 120); do - echo "Waiting for $container ip at $host" - if container_ip $host $container > /dev/null 2>&1 ; then - return - fi - sleep 1 - done - echo "Timed out waiting for $container ip at $host" >&2 - exit 1 -} - start_suite "Claiming addresses" weave_on $HOST1 launch-router --ipalloc-range $UNIVERSE $HOST2 @@ -86,7 +72,7 @@ assert_raises "proxy_start_container $HOST1 -e WEAVE_CIDR=10.3.0.1/12" # Launch host2, so that host1 can establish the ring. weave_on $HOST2 launch --ipalloc-range $UNIVERSE $HOST1 -wait_for_container_ip $HOST1 c4 +wait_for_attached $HOST1 c4 assert_raises "[ $(container_ip $HOST1 c4) == $C4 ]" end_suite diff --git a/test/640_proxy_restart_reattaches_test.sh b/test/640_proxy_restart_reattaches_test.sh index 17dbbc86..0cb46eaa 100755 --- a/test/640_proxy_restart_reattaches_test.sh +++ b/test/640_proxy_restart_reattaches_test.sh @@ -4,11 +4,6 @@ NAME=seetwo.weave.local -check_attached() { - assert_raises "exec_on $HOST1 c2 $CHECK_ETHWE_UP" - assert_dns_record $HOST1 c1 $NAME $C2 -} - N=50 # Create and remove a lot of containers in a small subnet; the failure # mode is that this takes a long time as it has to wait for the old @@ -27,39 +22,41 @@ proxy_start_container_with_dns $HOST1 -di --name=c1 --restart=always C2=$(container_ip $HOST1 c2) proxy docker_on $HOST1 restart -t=1 c2 -check_attached +wait_for_attached $HOST1 c2 +assert_dns_record $HOST1 c1 $NAME $C2 # Restart weave router docker_on $HOST1 restart weave +wait_for_attached $HOST1 c2 sleep 1 -check_attached +assert_dns_record $HOST1 c1 $NAME $C2 # Kill outside of Docker so Docker will restart it run_on $HOST1 sudo kill -KILL $(docker_on $HOST1 inspect --format='{{.State.Pid}}' c2) +wait_for_attached $HOST1 c2 sleep 1 -check_attached +assert_dns_record $HOST1 c1 $NAME $C2 run_on $HOST1 "sudo service docker restart" wait_for_proxy $HOST1 -sleep 5 # allow for re-tries of attach +wait_for_attached $HOST1 c2 # Re-fetch the IP since it is not retained on docker restart C2=$(container_ip $HOST1 c2) || (echo "container c2 has no IP address" 2>&1; exit 1) -check_attached +assert_dns_record $HOST1 c1 $NAME $C2 assert_raises "timeout 90 cat <( run_many )" # Start a container that needs IPAM, then restart it when the router is stopped proxy_start_container $HOST1 -di --name=c3 --restart=always -assert_raises "exec_on $HOST1 c3 $CHECK_ETHWE_UP" +wait_for_attached $HOST1 c3 weave_on $HOST1 stop-router docker_on $HOST1 restart c3 weave_on $HOST1 launch-router -sleep 5 -assert_raises "exec_on $HOST1 c3 $CHECK_ETHWE_UP" +wait_for_attached $HOST1 c3 # Restarting proxy shouldn't kill unattachable containers weave_on $HOST1 stop weave_on $HOST1 launch-proxy -assert_raises "exec_on $HOST1 c3 $CHECK_ETHWE_UP" +wait_for_attached $HOST1 c3 end_suite diff --git a/test/config.sh b/test/config.sh index 599194bb..57ceca69 100644 --- a/test/config.sh +++ b/test/config.sh @@ -197,6 +197,20 @@ container_pid() { docker_on $1 inspect -f '{{.State.Pid}}' $2 } +wait_for_attached() { + host=$1 + container=$2 + for i in $(seq 1 10); do + echo "Waiting for $container on $host to be attached" + if exec_on $host $container $CHECK_ETHWE_UP > /dev/null 2>&1 ; then + return + fi + sleep 1 + done + echo "Timed out waiting for $container on $host to be attached" >&2 + exit 1 +} + # assert_dns_record [ ...] assert_dns_record() { local host=$1