Skip to content

Commit

Permalink
Make integration test check API responses contain expected containers.
Browse files Browse the repository at this point in the history
Also
- Add test for clustering without weave.
- Update test template for docker 1.8
- Prefetch images
- Stop all containers when test finishes.
- Add small sleep after weave launch, and supply all the hosts to ensure IPAM works correctly.
  • Loading branch information
Tom Wilkie committed Sep 30, 2015
1 parent b78be6a commit 8a8520f
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 35 deletions.
1 change: 1 addition & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
insecure_private_key
.vagrant
.ssh_known_hosts
weave
10 changes: 8 additions & 2 deletions integration/100_launch_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

start_suite "Launch scope and check it boots"

weave_on $HOST1 launch
scope_on $HOST1 launch
assert_raises "curl $HOST1:4040"

end_suite
sleep 5

has_container $HOST1 weave 1
has_container $HOST1 weaveproxy 1
has_container $HOST1 weavescope 1

scope_end_suite
13 changes: 7 additions & 6 deletions integration/105_launch_sans_weave_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

start_suite "Launch scope (without weave installed) and check it boots"

assert_raises "run_on $HOST1 \
PATH=/usr/local/scope/bin:/usr/sbin:/usr/bin:/sbin:/bin \
DOCKER_HOST=tcp://$HOST1:$DOCKER_PORT \
scope launch"
scope_on $HOST1 launch

assert_raises "curl $HOST1:4040"
sleep 5

end_suite
has_container $HOST1 weave 0
has_container $HOST1 weaveproxy 0
has_container $HOST1 weavescope 1

scope_end_suite
2 changes: 1 addition & 1 deletion integration/110_shutdown_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'app exiting'"
assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'probe exiting'"
assert_raises "docker_on $HOST1 inspect --format='{{.State.Running}}' weavescope" "false"

end_suite
scope_end_suite
48 changes: 27 additions & 21 deletions integration/200_clustering_2_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@

. ./config.sh

start_suite "Launch 2 scopes and check they cluster"

weave_on $HOST2 launch
weave_on $HOST2 launch-dns
docker_on $HOST2 run -dit --name db1 peterbourgon/tns-db
container_id=$(docker_on $HOST2 run -dit --name app1 --link db1:db1 peterbourgon/tns-app)

scope_on $HOST1 launch $HOST2
scope_on $HOST2 launch $HOST1

SUCCESS=
for i in {1..10}; do
if (curl -s $HOST1:4040/api/topology/containers | grep "$container_id" >/dev/null); then
SUCCESS=1
break
fi
sleep 1
done
assert "echo $SUCCESS" "1"

end_suite
start_suite "Launch 2 scopes and check they cluster automatically"

weave_on $HOST1 launch $HOST1 $HOST2
weave_on $HOST2 launch $HOST1 $HOST2

sleep 10 # let weave settle

scope_on $HOST1 launch
scope_on $HOST2 launch

docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on $HOST2 run -dit --name db2 peterbourgon/tns-db

sleep 30

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
}

check $HOST1
check $HOST2

scope_end_suite
26 changes: 26 additions & 0 deletions integration/205_clustering_sans_weave_2_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/bash

. ./config.sh

start_suite "Launch 2 scopes and check they cluster (without weave)"

scope_on $HOST1 launch $HOST1 $HOST2
scope_on $HOST2 launch $HOST1 $HOST2

docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on $HOST2 run -dit --name db2 peterbourgon/tns-db

sleep 30

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
}

check $HOST1
check $HOST2

scope_end_suite
25 changes: 21 additions & 4 deletions integration/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,38 @@ export HOSTS
: ${WEAVE_REPO:=github.com/weaveworks/weave}
: ${WEAVE_ROOT:="$(go list -e -f {{.Dir}} $WEAVE_REPO)"}

WEAVE="./weave"
SCOPE="../scope"
RUNNER="$WEAVE_ROOT/testing/runner/runner"
[ -x "$RUNNER" ] || (echo "Could not find weave test runner at $RUNNER." >&2 ; exit 1)

. "$WEAVE_ROOT/test/config.sh"

scope_on() {
host=$1
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Scope on $host: $@" >&2
run_on $host DOCKER_HOST=tcp://$host:$DOCKER_PORT scope "$@"
DOCKER_HOST=tcp://$host:$DOCKER_PORT $SCOPE "$@"
}

weave_on() {
host=$1
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Weave on $host: $@" >&2
run_on $host DOCKER_HOST=tcp://$host:$DOCKER_PORT weave "$@"
DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@"
}

# this checks we have a weavescope container
has_container() {
local host=$1
local name=$2
local count=$3
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '[.nodes | .[] | select(.label_major == \"$name\")] | length'" $count
}

scope_end_suite() {
end_suite
for host in $HOSTS; do
docker_on $host rm -f $(docker_on $host ps -a -q) 2>/dev/null 1>&2 || true
done
}
2 changes: 1 addition & 1 deletion integration/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -e
. ./config.sh

export PROJECT=scope-integration-tests
export TEMPLATE_NAME="test-template-2"
export TEMPLATE_NAME="test-template-3"
export NUM_HOSTS=2
. "$WEAVE_ROOT/test/gce.sh" "$@"
8 changes: 8 additions & 0 deletions integration/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ 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"
done

echo Prefetching Images
for HOST in $HOSTS; do
weave_on $HOST setup
docker_on $HOST pull peterbourgon/tns-db
done

curl -sL git.io/weave -o ./weave

0 comments on commit 8a8520f

Please sign in to comment.