From 4eec75bec35a126a4b5479fda93cb51752ee434c Mon Sep 17 00:00:00 2001 From: Deborah Brouwer Date: Thu, 7 Mar 2024 13:11:03 -0800 Subject: [PATCH] =?UTF-8?q?Get=20dns=20server=20address=20if=20host=20isn?= =?UTF-8?q?=E2=80=99t=20using=20systemd-resolved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The worker containers aren’t using systemd-resolved so get_host_dns() can’t find the dns server causing tests that need it to fail. Add an alternative place to look for the dns server address that doesn’t rely on systemd-resolved. Signed-off-by: Deborah Brouwer --- lib/tapnet.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/tapnet.pm b/lib/tapnet.pm index 28864f46..0dfdd225 100644 --- a/lib/tapnet.pm +++ b/lib/tapnet.pm @@ -62,6 +62,17 @@ sub get_host_dns { # FIXME this is gonna break when we have IPv6 DNS servers on the # worker hosts my @forwards = split(' ', $result); + + # Alternatively, for hosts that aren't running systemd, read /etc/resolv.conf + if (!@forwards && open(my $fh, '<', "/etc/resolv.conf")) { + while (<$fh>) { + next if /:/; # ignore ipv6 addresses + if ($_ =~ m/^nameserver +(.+)/) { + push @forwards, $1; + } + } + close($fh); + } return @forwards; }