[autotest-client-tests] ubuntu_fan_smoke_test: Add DNS hinting for docker test

Message ID 1510926807-12463-1-git-send-email-stefan.bader@canonical.com
State New
Headers show
Series
  • [autotest-client-tests] ubuntu_fan_smoke_test: Add DNS hinting for docker test
Related show

Commit Message

Stefan Bader Nov. 17, 2017, 1:53 p.m.
When running in an environment which only has systemd-resolvd as
DNS resolver, it is possible that docker cannot figure out the
IP address of the real DNS server to use. Adding --dns in that
case to avoid issues.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 ubuntu_fan_smoke_test/smoke_test_old.sh | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Po-Hsu Lin Nov. 21, 2017, 6:12 a.m. | #1
Patch works as expected.
Acked-by: Po-Hsu Lin <po-hsu.lin@canonical.com>

Patch

diff --git a/ubuntu_fan_smoke_test/smoke_test_old.sh b/ubuntu_fan_smoke_test/smoke_test_old.sh
index 9622575..eb0d2dc 100755
--- a/ubuntu_fan_smoke_test/smoke_test_old.sh
+++ b/ubuntu_fan_smoke_test/smoke_test_old.sh
@@ -128,7 +128,7 @@  fanatic_enable_docker_test()
 
 fanatic_docker_test()
 {
-	echo -n "fanatic docker test: "
+	echo -n "fanatic docker test"
 	enable_fan
 
 	info=$(ip address | ./extract-fan-info)
@@ -136,7 +136,22 @@  fanatic_docker_test()
 	fan_addr=$(echo $info | cut -d: -f2)
 	enable_docker
 	service docker restart
-	docker run $image sh -c "apt-get update && apt-get install iputils-ping -y && ping -c 10 $fan_addr" > $TMP
+
+	# Docker needs DNS hinting if systemd-resolvd is in charge
+	dns_opt=""
+	dns1=$(awk '$1=="nameserver"{print $2; exit}' /etc/resolv.conf)
+	if [ "$dns1" = "127.0.0.53" ]; then
+		dns_opt="--dns=$(systemd-resolve --status |
+			awk '/DNS Servers:/{
+				sub(/.*DNS Servers: */, "")
+				sub(/,.*/, "")
+				print
+				exit}')"
+		echo -n "($dns_opt): "
+	else
+		echo -n ": "
+	fi
+	docker run $dns_opt $image sh -c "apt-get update && apt-get install iputils-ping -y && ping -c 10 $fan_addr" > $TMP
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "FAILED: (docker run returned $ret)"