From a181ff3f792d4d79cc5c1daea76b4bab5bebc7d0 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 30 Sep 2020 13:25:01 -0400 Subject: [PATCH] Compare to the correct host network setting In systemd-resolved hosts with no DNS customizations, the docker driver DNS setting should be compared to /run/systemd/resolve/resolv.conf while exec/java drivers should be compared to /etc/resolv.conf. When system-resolved is enabled, /etc/resolv.conf is a stub that points to 127.0.0.53. Docker avoids this stub because this address isn't accessible from the container. The exec/java drivers that don't create network isolations use the stub though in the default configuration. --- plugins/drivers/testutils/dns_testing.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/drivers/testutils/dns_testing.go b/plugins/drivers/testutils/dns_testing.go index f27a8fead..ccd0f0e29 100644 --- a/plugins/drivers/testutils/dns_testing.go +++ b/plugins/drivers/testutils/dns_testing.go @@ -16,7 +16,11 @@ func TestTaskDNSConfig(t *testing.T, driver *DriverHarness, taskID string, dns * caps, err := driver.Capabilities() require.NoError(t, err) - isolated := (caps.FSIsolation != drivers.FSIsolationNone) + // FS isolation is used here as a proxy for network isolation. + // This is true for the current built-in drivers but it is not necessarily so. + isolated := caps.FSIsolation != drivers.FSIsolationNone + usesHostNetwork := caps.FSIsolation != drivers.FSIsolationImage + if !isolated { t.Skip("dns config not supported on non isolated drivers") } @@ -39,7 +43,12 @@ func TestTaskDNSConfig(t *testing.T, driver *DriverHarness, taskID string, dns * require.ElementsMatch(t, dns.Options, dresolvconf.GetOptions(resolvConf)) } } else { - system, err := dresolvconf.Get() + systemPath := "/etc/resolv.conf" + if !usesHostNetwork { + systemPath = dresolvconf.Path() + } + + system, err := dresolvconf.GetSpecific(systemPath) require.NoError(t, err) require.ElementsMatch(t, dresolvconf.GetNameservers(system.Content, dtypes.IP), dresolvconf.GetNameservers(resolvConf, dtypes.IP)) require.ElementsMatch(t, dresolvconf.GetSearchDomains(system.Content), dresolvconf.GetSearchDomains(resolvConf))