mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Merge pull request #542 from weaveworks/testing
Add tests for short-lived connection between hosts and containers.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
21
integration/310_container_to_container_edge_test.sh
Executable file
21
integration/310_container_to_container_edge_test.sh
Executable 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
|
||||
30
integration/320_container_edge_cross_host_2_test.sh
Executable file
30
integration/320_container_edge_cross_host_2_test.sh
Executable 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
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user