Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
making test helpers more robust so scope can use them
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Jun 29, 2015
1 parent 1ef3bd3 commit 26cb65c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
8 changes: 4 additions & 4 deletions test/140_weave_local_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

start_suite "Run weave with --local"

run_on $HOST1 sudo ./weave --local reset
run_on $HOST1 sudo weave --local reset

run_on $HOST1 sudo ./weave --local launch -iprange 10.2.5.0/24
run_on $HOST1 sudo weave --local launch -iprange 10.2.5.0/24
assert_raises "docker_on $HOST1 ps | grep weave"

run_on $HOST1 sudo ./weave --local run 10.2.6.5/24 -ti --name=c1 $SMALL_IMAGE /bin/sh
run_on $HOST1 sudo weave --local run 10.2.6.5/24 -ti --name=c1 $SMALL_IMAGE /bin/sh
assert_raises "exec_on $HOST1 c1 $CHECK_ETHWE_UP"

run_on $HOST1 sudo ./weave --local run -ti --name=c2 $SMALL_IMAGE /bin/sh
run_on $HOST1 sudo weave --local run -ti --name=c2 $SMALL_IMAGE /bin/sh
assert_raises "exec_on $HOST1 c2 $CHECK_ETHWE_UP"

end_suite
24 changes: 20 additions & 4 deletions test/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Protect against being sourced multiple times to prevent
# overwriting assert.sh global state
if ! [ -z "$SOURCED_CONFIG_SH" ]; then
Expand All @@ -25,9 +27,11 @@ fi
HOST1=$(echo $HOSTS | cut -f 1 -d ' ')
HOST2=$(echo $HOSTS | cut -f 2 -d ' ')

. ./assert.sh
. "$DIR/assert.sh"


SSH=${SSH:-ssh -l vagrant -i ./insecure_private_key -o UserKnownHostsFile=./.ssh_known_hosts -o CheckHostIP=no -o StrictHostKeyChecking=no}
SSH_DIR=${SSH_DIR:-$DIR}
SSH=${SSH:-ssh -l vagrant -i "$SSH_DIR/insecure_private_key" -o "UserKnownHostsFile=$SSH_DIR/.ssh_known_hosts" -o CheckHostIP=no -o StrictHostKeyChecking=no}

SMALL_IMAGE="gliderlabs/alpine"
DNS_IMAGE="aanand/docker-dnsutils"
Expand All @@ -41,6 +45,18 @@ DOCKER_PORT=2375
WEAVEDNS_ARGS="--no-cache"
[ -n "$DEBUG" ] && WEAVEDNS_ARGS="$WEAVEDNS_ARGS --debug"


upload_executable() {
host=$1
file=$2
prefix=${3:-/usr/local/bin/}
suffix=$(basename "$file")
target="$prefix$suffix"
[ -z "$DEBUG" ] || greyly echo "Uploading to $host: $file -> $target" >&2
<"$file" remote $host $SSH $host sh -c "cat | sudo tee $target >/dev/null"
run_on $host "sudo chmod a+x $target"
}

remote() {
rem=$1
shift 1
Expand Down Expand Up @@ -182,5 +198,5 @@ end_suite() {
whitely assert_end
}

WEAVE=../weave
DOCKER_NS=./bin/docker-ns
WEAVE=$DIR/../weave
DOCKER_NS=$DIR/../bin/docker-ns
2 changes: 1 addition & 1 deletion test/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -ex

KEY_FILE=/tmp/gce_private_key.json
SSH_KEY_FILE=$HOME/.ssh/gce_ssh_key
PROJECT=positive-cocoa-90213
PROJECT=${PROJECT:-positive-cocoa-90213}
IMAGE=ubuntu-14-04
TEMPLATE_NAME="test-template-2"
ZONE=us-central1-a
Expand Down
13 changes: 7 additions & 6 deletions test/run_all.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

. ./config.sh
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$DIR/config.sh"

whitely echo Sanity checks
if ! bash ./sanity_check.sh; then
if ! bash "$DIR/sanity_check.sh"; then
whitely echo ...failed
exit 1
fi
Expand All @@ -27,8 +28,8 @@ trap check_test_status EXIT
TESTS="${@:-*_test.sh}"

# If running on circle, use the scheduler to work out what tests to run
if [ -n "$CIRCLECI" ]; then
TESTS=$(echo $TESTS | ./sched sched $CIRCLE_BUILD_NUM $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
TESTS=$(echo $TESTS | "$DIR/sched" sched $CIRCLE_BUILD_NUM $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
fi

echo Running $TESTS
Expand All @@ -39,7 +40,7 @@ for t in $TESTS; do
. $t

# Report test runtime when running on circle, to help scheduler
if [ -n "$CIRCLECI" ]; then
./sched time $t $(bc -l <<< "$tests_time/1000000000")
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
"$DIR/sched" time $t $(bc -l <<< "$tests_time/1000000000")
fi
done
7 changes: 4 additions & 3 deletions test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

. ./config.sh

(cd ./tls && go get ./... && go run generate_certs.go $HOSTS)
Expand All @@ -11,9 +13,8 @@ echo " prefetch test images"
for HOST in $HOSTS; do
docker_on $HOST load -i ../weave.tar
run_on $HOST mkdir -p bin
cat ../bin/docker-ns | run_on $HOST sh -c "cat > $DOCKER_NS"
cat ../weave | run_on $HOST sh -c "cat > ./weave"
run_on $HOST chmod a+x $DOCKER_NS ./weave
upload_executable $HOST ../bin/docker-ns
upload_executable $HOST ../weave
rsync -az -e "$SSH" ./tls/ $HOST:~/tls
for IMG in $TEST_IMAGES ; do
docker_on $HOST inspect --format=" " $IMG >/dev/null 2>&1 || docker_on $HOST pull $IMG
Expand Down

0 comments on commit 26cb65c

Please sign in to comment.