Merge pull request #542 from weaveworks/testing

Add tests for short-lived connection between hosts and containers.
This commit is contained in:
Tom Wilkie
2015-10-12 12:51:35 +01:00
9 changed files with 122 additions and 22 deletions

View File

@@ -7,10 +7,10 @@ start_suite "Launch scope and check it boots"
weave_on $HOST1 launch
scope_on $HOST1 launch
sleep 5 # give the probe a few seconds to build a report and send it to the app
wait_for_containers $HOST1 60 weave weaveproxy weavescope
has_container $HOST1 weave 1
has_container $HOST1 weaveproxy 1
has_container $HOST1 weavescope 1
has_container $HOST1 weave
has_container $HOST1 weaveproxy
has_container $HOST1 weavescope
scope_end_suite

View File

@@ -6,10 +6,10 @@ start_suite "Launch scope (without weave installed) and check it boots"
scope_on $HOST1 launch
sleep 5 # give the probe a few seconds to build a report and send it to the app
wait_for_containers $HOST1 60 weavescope
has_container $HOST1 weave 0
has_container $HOST1 weaveproxy 0
has_container $HOST1 weavescope 1
has_container $HOST1 weavescope
scope_end_suite

View File

@@ -19,8 +19,8 @@ check() {
has_container $1 weave 2
has_container $1 weaveproxy 2
has_container $1 weavescope 2
has_container $1 db1 1
has_container $1 db2 1
has_container $1 db1
has_container $1 db2
}
check $HOST1

View File

@@ -16,8 +16,8 @@ check() {
has_container $1 weave 0
has_container $1 weaveproxy 0
has_container $1 weavescope 2
has_container $1 db1 1
has_container $1 db2 1
has_container $1 db1
has_container $1 db2
}
check $HOST1

View File

@@ -4,21 +4,28 @@
start_suite "Test short lived connections from the Internet"
if ! echo "$HOST1" | grep "us-central1-a"; then
echo "Skipping; test needs to be run against VMs on GCE."
scope_end_suite
exit
fi
weave_on $HOST1 launch
scope_on $HOST1 launch
docker_on $HOST1 run -d -p 80:80 --name nginx nginx
do_connections() {
while true; do
curl -s http://$HOST1:80/ >/dev/null
curl -s http://$HOST1:80/ >/dev/null || true
sleep 1
done
}
do_connections&
sleep 5 # give the probe a few seconds to build a report and send it to the app
wait_for_containers $HOST1 60 nginx "The Internet"
has_container $HOST1 nginx 1
has_container $HOST1 nginx
has_container $HOST1 "The Internet"
has_connection $HOST1 "The Internet" nginx
kill %do_connections

View File

@@ -0,0 +1,21 @@
#! /bin/bash
. ./config.sh
start_suite "Test short lived connections between containers"
weave_on $HOST1 launch
scope_on $HOST1 launch
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST1 run -d --name client alpine /bin/sh -c "while true; do \
wget http://nginx.weave.local:80/ >/dev/null || true; \
sleep 1; \
done"
wait_for_containers $HOST1 60 nginx client
has_container $HOST1 nginx
has_container $HOST1 client
has_connection $HOST1 client nginx
scope_end_suite

View File

@@ -0,0 +1,30 @@
#! /bin/bash
. ./config.sh
start_suite "Test short lived connections between containers on different hosts"
weave_on $HOST1 launch $HOST1 $HOST2
weave_on $HOST2 launch $HOST1 $HOST2
scope_on $HOST1 launch
scope_on $HOST2 launch
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST2 run -d --name client alpine /bin/sh -c "while true; do \
wget http://nginx.weave.local:80/ >/dev/null || true; \
sleep 1; \
done"
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container $1 nginx
has_container $1 client
has_connection $1 client nginx
}
check $HOST1
check $HOST2
scope_end_suite

View File

@@ -35,7 +35,7 @@ weave_on() {
has_container() {
local host=$1
local name=$2
local count=$3
local count=${3:-1}
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '[.nodes[] | select(.label_major == \"$name\")] | length'" $count
}
@@ -57,7 +57,47 @@ has_connection() {
local host="$1"
local from="$2"
local to="$3"
local timeout="${4:-60}"
local from_id=$(container_id "$host" "$from")
local to_id=$(container_id "$host" "$to")
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
for i in $(seq $timeout); do
local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)"
local edge=$(echo "$containers" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
if [ "$edge" = "true" ]; then
echo "Found edge $from -> $to after $i secs"
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
return
fi
sleep 1
done
echo "Failed to find edge $from -> $to after $timeout secs"
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
}
wait_for_containers() {
local host="$1"
local timeout="$2"
shift 2
for i in $(seq $timeout); do
local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)"
local found=0
for name in "$@"; do
local count=$(echo "$containers" | jq -r "[.nodes[] | select(.label_major == \"$name\")] | length")
if [ -n "$count" ] && [ "$count" -ge 1 ]; then
found=$(( found + 1 ))
fi
done
if [ "$found" -eq $# ]; then
echo "Found $found containers after $i secs"
return
fi
sleep 1
done
echo "Failed to find containers $@ after $i secs"
}

View File

@@ -6,21 +6,23 @@ set -e
echo Copying scope images and scripts to hosts
for HOST in $HOSTS; do
docker_on $HOST load -i ../scope.tar
upload_executable $HOST ../scope
upload_executable $HOST ../scope /usr/local/scope/bin/scope
docker_on $HOST load -i ../scope.tar
upload_executable $HOST ../scope
upload_executable $HOST ../scope /usr/local/scope/bin/scope
done
echo Installing weave
for HOST in $HOSTS; do
run_on $HOST "sudo curl -sL git.io/weave -o /usr/local/bin/weave"
run_on $HOST "sudo chmod a+x /usr/local/bin/weave"
run_on $HOST "sudo curl -sL git.io/weave -o /usr/local/bin/weave"
run_on $HOST "sudo chmod a+x /usr/local/bin/weave"
done
echo Prefetching Images
for HOST in $HOSTS; do
weave_on $HOST setup
docker_on $HOST pull peterbourgon/tns-db
weave_on $HOST setup
docker_on $HOST pull peterbourgon/tns-db
docker_on $HOST pull alpine
docker_on $HOST pull nginx
done
curl -sL git.io/weave -o ./weave