Merge pull request #683 from rade/refactor_smoke_tests

Refactor smoke tests
This commit is contained in:
Adam Harrison committed 2015-05-18 11:37:40 +01:00
commit eecb540141
15 files changed
+77 -97

No files matched your search

+3 -3
View File
@@ -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
+3 -3
View File
@@ -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
+4 -5
View File
@@ -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
+4 -10
View File
@@ -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"
+5 -9
View File
@@ -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"
+3 -4
View File
@@ -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
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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
+3 -3
View File
@@ -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"
+2 -2
View File
@@ -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
+5 -7
View File
@@ -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
+2 -2
View File
@@ -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"
+17 -29
View File
@@ -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 <host>
weave_status_on() {
HOST=$1; shift
DOCKER_HOST=tcp://$HOST:2375 $WEAVE status
}
# weave_ps_on <host>
weave_ps_on() {
HOST=$1; shift
DOCKER_HOST=tcp://$HOST:2375 $WEAVE ps
}
NAME=multicidr.weave.local
# assert_container_cidrs <host> <cid> <cidr> [<cidr> ...]
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 <host> <cid> <fqdn> <ip> [<ip> ...]
@@ -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
+18 -12
View File
@@ -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 <host> <container> <name> <query> <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 <host> <container> <name> <ip>
@@ -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() {
+2 -2
View File
@@ -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