diff --git a/test/100_cross_hosts_test.sh b/test/100_cross_hosts_test.sh index 6d9a0e30..678b3f0e 100755 --- a/test/100_cross_hosts_test.sh +++ b/test/100_cross_hosts_test.sh @@ -10,8 +10,8 @@ start_suite "Ping over cross-host weave network" weave_on $HOST1 launch weave_on $HOST2 launch $HOST1 -weave_on $HOST2 run $C2/24 -t --name=c2 gliderlabs/alpine /bin/sh -weave_on $HOST1 run $C1/24 -t --name=c1 gliderlabs/alpine /bin/sh -assert_raises "exec_on $HOST1 c1 ping -q -c 4 $C2" +start_container $HOST1 $C1/24 --name=c1 +start_container $HOST2 $C2/24 --name=c2 +assert_raises "exec_on $HOST1 c1 $PING $C2" end_suite diff --git a/test/110_encryption_test.sh b/test/110_encryption_test.sh index e5099b68..967e0003 100755 --- a/test/110_encryption_test.sh +++ b/test/110_encryption_test.sh @@ -10,8 +10,8 @@ start_suite "Ping over encrypted cross-host weave network" weave_on $HOST1 launch -password notverysecure weave_on $HOST2 launch -password notverysecure $HOST1 -weave_on $HOST2 run $C2/24 -t --name=c2 gliderlabs/alpine /bin/sh -weave_on $HOST1 run $C1/24 -t --name=c1 gliderlabs/alpine /bin/sh -assert_raises "exec_on $HOST1 c1 ping -q -c 4 $C2" +start_container $HOST1 $C1/24 --name=c1 +start_container $HOST2 $C2/24 --name=c2 +assert_raises "exec_on $HOST1 c1 $PING $C2" end_suite diff --git a/test/120_ipam_test.sh b/test/120_ipam_test.sh index f7cb15d1..efd7c804 100755 --- a/test/120_ipam_test.sh +++ b/test/120_ipam_test.sh @@ -9,10 +9,9 @@ start_suite "Ping over cross-host weave network with IPAM" weave_on $HOST1 launch -iprange $UNIVERSE weave_on $HOST2 launch -iprange $UNIVERSE $HOST1 -weave_on $HOST1 run -t --name=c1 gliderlabs/alpine /bin/sh -weave_on $HOST2 run -t --name=c2 gliderlabs/alpine /bin/sh -# Note can't use weave_on here because it echoes the command -C2IP=$(DOCKER_HOST=tcp://$HOST2:2375 $WEAVE ps | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') -assert_raises "exec_on $HOST1 c1 ping -q -c 4 $C2IP" +start_container $HOST1 --name=c1 +start_container $HOST2 --name=c2 +C2=$(container_ip $HOST2 c2) +assert_raises "exec_on $HOST1 c1 $PING $C2" end_suite diff --git a/test/130_expose_test.sh b/test/130_expose_test.sh index 353fa408..cacc3dfd 100755 --- a/test/130_expose_test.sh +++ b/test/130_expose_test.sh @@ -8,8 +8,6 @@ C3=10.2.2.34 C4=10.2.2.37 EXP=10.2.1.101 -PING="ping -nq -W 1 -c 1" - weave_on1() { assert_raises "weave_on $HOST1 $@" } @@ -29,18 +27,14 @@ check_container_connectivity() { # exec_on1 "c3 ! $PING $C1" } -start_container() { - weave_on $HOST1 run $2/24 --name=$1 -t gliderlabs/alpine /bin/sh -} - start_suite "exposing weave network to host" weave_on $HOST1 launch -start_container c1 $C1 -start_container c2 $C2 -start_container c3 $C3 -start_container c4 $C4 +start_container $HOST1 $C1/24 --name=c1 +start_container $HOST1 $C2/24 --name=c2 +start_container $HOST1 $C3/24 --name=c3 +start_container $HOST1 $C4/24 --name=c4 # absence of host connectivity by default run_on1 "! $PING $C1" diff --git a/test/140_ipam_expose_test.sh b/test/140_ipam_expose_test.sh index b0ed95c1..11b40994 100755 --- a/test/140_ipam_expose_test.sh +++ b/test/140_ipam_expose_test.sh @@ -6,8 +6,6 @@ R1=10.2.1.0/24 C3=10.2.2.34 C4=10.2.2.37 -PING="ping -nq -W 1 -c 1" - weave_on1() { assert_raises "weave_on $HOST1 $@" } @@ -31,13 +29,11 @@ start_suite "exposing weave network to host with IPAM" weave_on $HOST1 launch -iprange $R1 -weave_on $HOST1 run -t --name=c1 gliderlabs/alpine /bin/sh -weave_on $HOST1 run -t --name=c2 gliderlabs/alpine /bin/sh -weave_on $HOST1 run $C3/24 -t --name=c3 gliderlabs/alpine /bin/sh -weave_on $HOST1 run $C4/24 -t --name=c4 gliderlabs/alpine /bin/sh - -# Note can't use weave_on here because it echoes the command -C1=$(DOCKER_HOST=tcp://$HOST1:2375 $WEAVE ps c1 | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') +start_container $HOST1 --name=c1 +start_container $HOST1 --name=c2 +start_container $HOST1 $C3/24 --name=c3 +start_container $HOST1 $C4/24 --name=c4 +C1=$(container_ip $HOST1 c1) # absence of host connectivity by default run_on1 "! $PING $C1" diff --git a/test/200_dns_test.sh b/test/200_dns_test.sh index b0717349..c39305ee 100755 --- a/test/200_dns_test.sh +++ b/test/200_dns_test.sh @@ -10,12 +10,11 @@ start_suite "Resolve names on a single host" weave_on $HOST1 launch-dns 10.2.254.1/24 -weave_on $HOST1 run $C2/24 -t --name=c2 -h $NAME gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns $C1/24 -t --name=c1 aanand/docker-dnsutils /bin/sh +start_container $HOST1 $C2/24 --name=c2 -h $NAME +start_container_with_dns $HOST1 $C1/24 --name=c1 assert_dns_record $HOST1 c1 $NAME $C2 -assert_dns_status $HOST1 c1 "MX seetwo.weave.local" NXDOMAIN -assert_dns_status $HOST1 c1 "AAAA seetwo.weave.local" NXDOMAIN +assert_raises "exec_on $HOST1 c1 dig MX $NAME | grep -q \"status: NXDOMAIN\"" end_suite diff --git a/test/210_dns_multicast_test.sh b/test/210_dns_multicast_test.sh index a315028e..ead67e95 100755 --- a/test/210_dns_multicast_test.sh +++ b/test/210_dns_multicast_test.sh @@ -11,11 +11,11 @@ start_suite "Resolve names across hosts" weave_on $HOST1 launch weave_on $HOST2 launch $HOST1 -weave_on $HOST1 launch-dns 10.2.254.1/24 -debug -weave_on $HOST2 launch-dns 10.2.254.2/24 -debug +weave_on $HOST1 launch-dns 10.2.254.1/24 +weave_on $HOST2 launch-dns 10.2.254.2/24 -weave_on $HOST2 run $C2/24 -t --name=c2 -h $NAME gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns $C1/24 --name=c1 -t aanand/docker-dnsutils /bin/sh +start_container $HOST2 $C2/24 --name=c2 -h $NAME +start_container_with_dns $HOST1 $C1/24 --name=c1 assert_dns_record $HOST1 c1 $NAME $C2 diff --git a/test/220_dns_custom_test.sh b/test/220_dns_custom_test.sh index 35d14d91..44f40231 100755 --- a/test/220_dns_custom_test.sh +++ b/test/220_dns_custom_test.sh @@ -11,8 +11,8 @@ start_suite "Resolve names in custom domain" weave_on $HOST1 launch-dns 10.2.254.1/24 --domain $DOMAIN. -weave_on $HOST1 run $C2/24 -t --name=c2 -h $NAME gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns $C1/24 -t --name=c1 aanand/docker-dnsutils /bin/sh +start_container $HOST1 $C2/24 --name=c2 -h $NAME +start_container_with_dns $HOST1 $C1/24 --name=c1 assert_dns_record $HOST1 c1 $NAME $C2 diff --git a/test/230_dns_unqualified_test.sh b/test/230_dns_unqualified_test.sh index 3ceab5fc..574fef06 100755 --- a/test/230_dns_unqualified_test.sh +++ b/test/230_dns_unqualified_test.sh @@ -12,9 +12,9 @@ start_suite "Resolve unqualified names" weave_on $HOST1 launch-dns 10.2.254.1/24 -weave_on $HOST1 run $C1/24 -t --name=c1 -h $NAME gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns $C2/24 -t --name=c2 -h seetwo.$DOMAIN aanand/docker-dnsutils /bin/sh -weave_on $HOST1 run --with-dns $C3/24 -t --name=c3 --dns-search=weave.local aanand/docker-dnsutils /bin/sh +start_container $HOST1 $C1/24 --name=c1 -h $NAME +start_container_with_dns $HOST1 $C2/24 --name=c2 -h seetwo.$DOMAIN +start_container_with_dns $HOST1 $C3/24 --name=c3 --dns-search=$DOMAIN assert "exec_on $HOST1 c2 getent hosts seeone | tr -s ' '" "$C1 $NAME" assert "exec_on $HOST1 c3 getent hosts seeone | tr -s ' '" "$C1 $NAME" diff --git a/test/240_dns_add_name_test.sh b/test/240_dns_add_name_test.sh index 45697ec6..0377cb11 100755 --- a/test/240_dns_add_name_test.sh +++ b/test/240_dns_add_name_test.sh @@ -11,8 +11,8 @@ start_suite "Add and remove names on a single host" weave_on $HOST1 launch-dns 10.2.254.1/24 -weave_on $HOST1 run $C2/24 -t --name=c2 gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns $C1/24 -t --name=c1 aanand/docker-dnsutils /bin/sh +start_container $HOST1 $C2/24 --name=c2 +start_container_with_dns $HOST1 $C1/24 --name=c1 weave_on $HOST1 dns-add $C2 c2 -h $NAME2 diff --git a/test/250_dns_ipam_test.sh b/test/250_dns_ipam_test.sh index 57298a51..b8988a54 100755 --- a/test/250_dns_ipam_test.sh +++ b/test/250_dns_ipam_test.sh @@ -3,6 +3,7 @@ . ./config.sh UNIVERSE=10.2.3.0/24 +NAME=seetwo.weave.local start_suite "Resolve names over cross-host weave network with IPAM" @@ -12,13 +13,10 @@ weave_on $HOST2 launch -iprange $UNIVERSE $HOST1 weave_on $HOST1 launch-dns 10.2.254.1/24 weave_on $HOST2 launch-dns 10.2.254.2/24 -weave_on $HOST2 run -t --name=c2 -h seetwo.weave.local gliderlabs/alpine /bin/sh -weave_on $HOST1 run --with-dns --name=c1 -t aanand/docker-dnsutils /bin/sh +start_container $HOST2 --name=c2 -h $NAME +start_container_with_dns $HOST1 --name=c1 +C2=$(container_ip $HOST2 c2) -# Note can't use weave_on here because it echoes the command -C2IP=$(DOCKER_HOST=tcp://$HOST2:2375 $WEAVE ps c2 | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') - -assert "exec_on $HOST1 c1 dig +short seetwo.weave.local" "$C2IP" -assert "exec_on $HOST1 c1 dig +short -x $C2IP" "seetwo.weave.local." +assert_dns_record $HOST1 c1 $NAME $C2 end_suite diff --git a/test/300_fallback_dns_test.sh b/test/300_fallback_dns_test.sh index c9f94b94..4f57f811 100755 --- a/test/300_fallback_dns_test.sh +++ b/test/300_fallback_dns_test.sh @@ -4,9 +4,9 @@ start_suite "Resolve a non-weave address" -weave_on $HOST1 launch-dns 10.2.254.1/24 -debug +weave_on $HOST1 launch-dns 10.2.254.1/24 -weave_on $HOST1 run --with-dns 10.2.1.5/24 --name=c1 -t aanand/docker-dnsutils /bin/sh +start_container_with_dns $HOST1 10.2.1.5/24 --name=c1 assert_raises "exec_on $HOST1 c1 host -t mx weave.works | grep google" assert_raises "exec_on $HOST1 c1 getent hosts 8.8.8.8 | grep google" diff --git a/test/500_weave_multi_cidr_test.sh b/test/500_weave_multi_cidr_test.sh index f9cdf3d8..4e3edf32 100755 --- a/test/500_weave_multi_cidr_test.sh +++ b/test/500_weave_multi_cidr_test.sh @@ -2,33 +2,16 @@ . ./config.sh -start_suite "Weave run/start/attach/detach with multiple cidr arguments" - -weave_on $HOST1 launch -weave_on $HOST1 launch-dns 10.254.254.254/24 - -# weave_status_on -weave_status_on() { - HOST=$1; shift - - DOCKER_HOST=tcp://$HOST:2375 $WEAVE status -} - -# weave_ps_on -weave_ps_on() { - HOST=$1; shift - - DOCKER_HOST=tcp://$HOST:2375 $WEAVE ps -} +NAME=multicidr.weave.local # assert_container_cidrs [ ...] assert_container_cidrs() { HOST=$1; shift CID=$1; shift - CIDRS=$@ + CIDRS="$@" # Assert container has attached CIDRs - assert_raises "weave_ps_on $HOST | grep \"^$CID [^ ]* $CIDRS$\"" + assert_raises "weave_on $HOST ps | grep \"^$CID [^ ]* $CIDRS$\"" } # assert_zone_records [ ...] @@ -38,11 +21,11 @@ assert_zone_records() { FQDN=$1; shift # Assert correct number of records exist - assert "weave_status_on $HOST | grep \"^$CID\" | wc -l" $# + assert "weave_on $HOST status | grep \"^$CID\" | wc -l" $# # Assert correct records exist - for IP in $@; do - assert_raises "weave_status_on $HOST | grep \"^$CID $IP $FQDN$\"" + for IP; do + assert_raises "weave_on $HOST status | grep \"^$CID $IP $FQDN$\"" done } @@ -50,33 +33,38 @@ assert_zone_records() { assert_bridge_cidrs() { HOST=$1; shift DEV=$1; shift - CIDRS=$@ + CIDRS="$@" BRIDGE_CIDRS=$($SSH $HOST ip addr show dev $DEV | grep -o 'inet .*' | cut -d ' ' -f 2) assert "echo $BRIDGE_CIDRS" "$CIDRS" } +start_suite "Weave run/start/attach/detach with multiple cidr arguments" + +weave_on $HOST1 launch +weave_on $HOST1 launch-dns 10.254.254.254/24 + # Run container with three cidrs -CID=$(DOCKER_HOST=tcp://$HOST1:2375 $WEAVE run 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 -t --name multicidr -h multicidr.weave.local gliderlabs/alpine /bin/sh | cut -b 1-12) +CID=$(start_container $HOST1 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 --name=multicidr -h $NAME | cut -b 1-12) assert_container_cidrs $HOST1 $CID 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 -assert_zone_records $HOST1 $CID multicidr.weave.local. 10.2.1.1 10.2.2.1 10.2.3.1 +assert_zone_records $HOST1 $CID $NAME. 10.2.1.1 10.2.2.1 10.2.3.1 # Remove two of them weave_on $HOST1 detach 10.2.1.1/24 10.2.3.1/24 $CID assert_container_cidrs $HOST1 $CID 10.2.2.1/24 -assert_zone_records $HOST1 $CID multicidr.weave.local. 10.2.2.1 +assert_zone_records $HOST1 $CID $NAME. 10.2.2.1 # Put them both back weave_on $HOST1 attach 10.2.1.1/24 10.2.3.1/24 $CID assert_container_cidrs $HOST1 $CID 10.2.2.1/24 10.2.1.1/24 10.2.3.1/24 -assert_zone_records $HOST1 $CID multicidr.weave.local. 10.2.2.1 10.2.1.1 10.2.3.1 +assert_zone_records $HOST1 $CID $NAME. 10.2.2.1 10.2.1.1 10.2.3.1 # Stop the container, restart with three IPs docker_on $HOST1 stop $CID weave_on $HOST1 start 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 $CID assert_container_cidrs $HOST1 $CID 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 -assert_zone_records $HOST1 $CID multicidr.weave.local. 10.2.1.1 10.2.2.1 10.2.3.1 +assert_zone_records $HOST1 $CID $NAME. 10.2.1.1 10.2.2.1 10.2.3.1 # Expose some cidrs weave_on $HOST1 expose 10.2.1.2/24 10.2.2.2/24 10.2.3.2/24 diff --git a/test/config.sh b/test/config.sh index 72fd59d1..3983c826 100644 --- a/test/config.sh +++ b/test/config.sh @@ -29,10 +29,12 @@ HOST2=$(echo $HOSTS | cut -f 2 -d ' ') SSH=${SSH:-ssh -l vagrant -i ./insecure_private_key -o UserKnownHostsFile=./.ssh_known_hosts -o CheckHostIP=no -o StrictHostKeyChecking=no} +PING="ping -nq -W 1 -c 1" + remote() { rem=$1 shift 1 - $@ > >(while read line; do echo -e "\e[0;34m$rem>\e[0m $line"; done) + "$@" > >(while read line; do echo -e "\e[0;34m$rem>\e[0m $line"; done) } colourise() { @@ -64,21 +66,21 @@ run_on() { host=$1 shift 1 greyly echo "Running on $host: $@" >&2 - remote $host $SSH $host $@ + remote $host $SSH $host "$@" } docker_on() { host=$1 shift 1 greyly echo "Docker on $host: $@" >&2 - docker -H tcp://$host:2375 $@ + docker -H tcp://$host:2375 "$@" } weave_on() { host=$1 shift 1 greyly echo "Weave on $host: $@" >&2 - DOCKER_HOST=tcp://$host:2375 $WEAVE $@ + DOCKER_HOST=tcp://$host:2375 $WEAVE "$@" } exec_on() { @@ -88,16 +90,20 @@ exec_on() { docker -H tcp://$host:2375 exec $container "$@" } -dig_on() { +start_container() { host=$1 - cont=$2 - query=$3 - docker -H tcp://$host:2375 exec $cont sh -c "dig $query" + shift 1 + weave_on $host run "$@" -t gliderlabs/alpine /bin/sh } -# assert_dns_status -assert_dns_status() { - assert_raises "dig_on \"$1\" \"$2\" \"$3\" | grep -q \"status: $4\"" +start_container_with_dns() { + host=$1 + shift 1 + weave_on $host run --with-dns "$@" -t aanand/docker-dnsutils /bin/sh +} + +container_ip() { + weave_on $1 ps $2 | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' } # assert_dns_record @@ -113,7 +119,7 @@ start_suite() { [ -n "$containers" ] && docker_on $host rm -f $containers >/dev/null 2>&1 weave_on $host reset 2>/dev/null done - whitely echo $@ + whitely echo "$@" } end_suite() { diff --git a/test/sanity_check.sh b/test/sanity_check.sh index ed633070..a003f570 100755 --- a/test/sanity_check.sh +++ b/test/sanity_check.sh @@ -5,8 +5,8 @@ set -e whitely echo Ping each host from the other -run_on $HOST2 ping -q -c 4 $HOST1 -run_on $HOST1 ping -q -c 4 $HOST2 +run_on $HOST2 $PING $HOST1 +run_on $HOST1 $PING $HOST2 whitely echo Check we can reach docker docker_on $HOST1 info