From eebb6742326a2775707b1e1e869ab01f6573137a Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 22 Apr 2015 19:38:04 +0100 Subject: [PATCH 1/2] simplify dns tests - use 'host' to lookup MX record. It's shorter - use getent everywhere else for dns lookups, instead of dig; this tests more of the o/s name resolution machinery and is generally shorter. - introduce assert_dns_record helper that performs forward and reverse - lookup introduce some vars for holding constants, so we don't have to repeat them --- test/200_dns_test.sh | 9 +++------ test/210_dns_multicast_test.sh | 13 +++++-------- test/220_dns_custom_test.sh | 12 +++++------- test/300_fallback_dns_test.sh | 8 ++++---- test/config.sh | 8 ++++++++ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/200_dns_test.sh b/test/200_dns_test.sh index 045cdacc..3a04ef45 100755 --- a/test/200_dns_test.sh +++ b/test/200_dns_test.sh @@ -4,6 +4,7 @@ C1=10.2.0.78 C2=10.2.0.34 +NAME=seetwo.weave.local start_suite "Resolve names on a single host" @@ -13,13 +14,9 @@ weave_on $HOST1 launch-dns 10.2.254.1/24 docker_on $HOST1 rm -f c1 c2 || true -weave_on $HOST1 run $C2/24 -t --name=c2 -h seetwo.weave.local ubuntu +weave_on $HOST1 run $C2/24 -t --name=c2 -h $NAME ubuntu weave_on $HOST1 run --with-dns $C1/24 -t --name=c1 aanand/docker-dnsutils /bin/sh -ok=$(exec_on $HOST1 c1 dig +short seetwo.weave.local) -assert "echo $ok" "$C2" - -ok=$(exec_on $HOST1 c1 dig +short -x $C2) -assert "echo $ok" "seetwo.weave.local." +assert_dns_record $HOST1 c1 $NAME $C2 end_suite diff --git a/test/210_dns_multicast_test.sh b/test/210_dns_multicast_test.sh index 2e72e262..bb83cec7 100755 --- a/test/210_dns_multicast_test.sh +++ b/test/210_dns_multicast_test.sh @@ -4,6 +4,7 @@ C1=10.2.3.78 C2=10.2.3.34 +NAME=seetwo.weave.local start_suite "Resolve names across hosts" @@ -19,16 +20,12 @@ 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 $HOST2 run $C2/24 -t --name=c2 -h seetwo.weave.local ubuntu +weave_on $HOST2 run $C2/24 -t --name=c2 -h $NAME ubuntu weave_on $HOST1 run --with-dns $C1/24 --name=c1 -t aanand/docker-dnsutils /bin/sh -ok=$(exec_on $HOST1 c1 dig +short seetwo.weave.local) -assert "echo $ok" "$C2" +assert_dns_record $HOST1 c1 $NAME $C2 -ok=$(exec_on $HOST1 c1 dig +short -x $C2) -assert "echo $ok" "seetwo.weave.local." - -ok=$(exec_on $HOST1 c1 dig +short -x 8.8.8.8) -assert "test -n \"$ok\" && echo pass" "pass" +ok=$(exec_on $HOST1 c1 getent hosts 8.8.8.8) +assert_raises "echo $ok | grep google" end_suite diff --git a/test/220_dns_custom_test.sh b/test/220_dns_custom_test.sh index 6ed56f04..94388f12 100755 --- a/test/220_dns_custom_test.sh +++ b/test/220_dns_custom_test.sh @@ -4,22 +4,20 @@ C1=10.2.56.34 C2=10.2.54.91 +DOMAIN=foo.bar +NAME=seetwo.$DOMAIN start_suite "Resolve names in custom domain" weave_on $HOST1 stop || true weave_on $HOST1 stop-dns || true -weave_on $HOST1 launch-dns 10.2.254.1/24 --domain foo.bar. +weave_on $HOST1 launch-dns 10.2.254.1/24 --domain $DOMAIN. docker_on $HOST1 rm -f c1 c2 || true -weave_on $HOST1 run $C2/24 -t --name=c2 -h seetwo.foo.bar ubuntu +weave_on $HOST1 run $C2/24 -t --name=c2 -h $NAME ubuntu weave_on $HOST1 run --with-dns $C1/24 -t --name=c1 aanand/docker-dnsutils /bin/sh -ok=$(exec_on $HOST1 c1 dig +short seetwo.foo.bar.) -assert "echo $ok" "$C2" - -ok=$(exec_on $HOST1 c1 dig +short -x $C2) -assert "echo $ok" "seetwo.foo.bar." +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 19e8cabd..bcaf5f9a 100755 --- a/test/300_fallback_dns_test.sh +++ b/test/300_fallback_dns_test.sh @@ -10,10 +10,10 @@ docker_on $HOST1 rm -f c1 || true weave_on $HOST1 run --with-dns 10.2.1.5/24 --name=c1 -t aanand/docker-dnsutils /bin/sh -ok=$(exec_on $HOST1 c1 dig +short -t MX weave.works) -assert "test -n \"$ok\" && echo pass" "pass" +ok=$(exec_on $HOST1 c1 host -t mx weave.works) +assert_raises "echo $ok | grep google" -ok=$(exec_on $HOST1 c1 dig +short -x 8.8.8.8) -assert "test -n \"$ok\" && echo pass" "pass" +ok=$(exec_on $HOST1 c1 getent hosts 8.8.8.8) +assert_raises "echo $ok | grep google" end_suite diff --git a/test/config.sh b/test/config.sh index c67896ba..e4950b1e 100644 --- a/test/config.sh +++ b/test/config.sh @@ -88,6 +88,14 @@ exec_on() { docker -H tcp://$host:2375 exec $container "$@" } +# assert_dns_record +assert_dns_record() { + ok=$(exec_on $1 $2 getent hosts $3) + assert "echo $ok" "$4 $3" + ok=$(exec_on $1 $2 getent hosts $4) + assert "echo $ok" "$4 $3" +} + start_suite() { whitely echo $@ } From 22c04bfc2451f57b70281da55b89d36614844734 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 22 Apr 2015 20:09:34 +0100 Subject: [PATCH 2/2] don't use $(exec_on ...) since that will cause the test to exit on failure --- test/210_dns_multicast_test.sh | 3 +-- test/300_fallback_dns_test.sh | 7 ++----- test/400_weave_local_test.sh | 4 ++-- test/config.sh | 6 ++---- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/test/210_dns_multicast_test.sh b/test/210_dns_multicast_test.sh index bb83cec7..9629c12f 100755 --- a/test/210_dns_multicast_test.sh +++ b/test/210_dns_multicast_test.sh @@ -25,7 +25,6 @@ weave_on $HOST1 run --with-dns $C1/24 --name=c1 -t aanand/docker-dnsutils /bin/s assert_dns_record $HOST1 c1 $NAME $C2 -ok=$(exec_on $HOST1 c1 getent hosts 8.8.8.8) -assert_raises "echo $ok | grep google" +assert_raises "exec_on $HOST1 c1 getent hosts 8.8.8.8 | grep google" end_suite diff --git a/test/300_fallback_dns_test.sh b/test/300_fallback_dns_test.sh index bcaf5f9a..8e665efb 100755 --- a/test/300_fallback_dns_test.sh +++ b/test/300_fallback_dns_test.sh @@ -10,10 +10,7 @@ docker_on $HOST1 rm -f c1 || true weave_on $HOST1 run --with-dns 10.2.1.5/24 --name=c1 -t aanand/docker-dnsutils /bin/sh -ok=$(exec_on $HOST1 c1 host -t mx weave.works) -assert_raises "echo $ok | grep google" - -ok=$(exec_on $HOST1 c1 getent hosts 8.8.8.8) -assert_raises "echo $ok | grep google" +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" end_suite diff --git a/test/400_weave_local_test.sh b/test/400_weave_local_test.sh index 2658a160..0b198951 100755 --- a/test/400_weave_local_test.sh +++ b/test/400_weave_local_test.sh @@ -11,8 +11,8 @@ assert_raises "docker_on $HOST1 ps | grep weave" 0 docker_on $HOST1 rm -f c1 || true run_on $HOST1 sudo ./weave --local run 10.2.6.5/24 -ti --name=c1 ubuntu -ok=$(exec_on $HOST1 c1 ifconfig | grep ethwe) -assert "test -n \"$ok\" && echo pass" "pass" + +assert_raises "exec_on $HOST1 c1 ifconfig | grep ethwe" docker_on $HOST1 rm -f c1 || true diff --git a/test/config.sh b/test/config.sh index e4950b1e..02656018 100644 --- a/test/config.sh +++ b/test/config.sh @@ -90,10 +90,8 @@ exec_on() { # assert_dns_record assert_dns_record() { - ok=$(exec_on $1 $2 getent hosts $3) - assert "echo $ok" "$4 $3" - ok=$(exec_on $1 $2 getent hosts $4) - assert "echo $ok" "$4 $3" + assert "exec_on $1 $2 getent hosts $3 | tr -s ' '" "$4 $3" + assert "exec_on $1 $2 getent hosts $4 | tr -s ' '" "$4 $3" } start_suite() {