Add wait_for_attached

This commit is contained in:
Martynas Pumputis committed 2016-05-12 12:25:59 +01:00
1 parent 671ed724d5
commit 02d9c090ed
5 files changed
+30 -40

No files matched your search

+2 -2
View File
@@ -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
+2 -9
View File
@@ -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"
+1 -15
View File
@@ -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
+11 -14
View File
@@ -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
+14
View File
@@ -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 <host> <container> <name> [<ip> ...]
assert_dns_record() {
local host=$1