summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2016-06-30 15:44:22 +0200
committerEvgeny Vereshchagin <evvers@ya.ru>2016-06-30 16:44:22 +0300
commit30b42a9a36727ac6a5201d51b6d9cd9c788a559a (patch)
tree45b7ec9a1d77c5417a35a3aa42b59c2cdd704412 /test
parent2e0d8df13b1c1deda7b5769accae9e6cd5bf5966 (diff)
test: check resolved generated resolv.conf in networkd-test (#3628)
* test: check resolved generated resolv.conf in networkd-test Directly verify the contents of /run/systemd/resolve/resolv.conf instead of /etc/resolv.conf. The latter might be a plain file or a symlink to something else (like Debian's resolvconf output), and in these cases we cannot make strong assumptions about the contents. Drop the "/etc/resolv.conf is a symlink" conditions and the "resolv.conf can have at most three nameservers" alternatives, as we know that resolved always adds all nameservers. Explicitly start resolved at the start of a test to ensure that it is running. * test: get along with existing system search domains in resolv.conf The previous change has uncovered a bug in the tests: Existing search domains can exist in resolv.conf which test_search_domains{,_too_long} didn't take into account. As existing domains take some of the "max 6 domains" and "max 255 chars" limit, don't expect that the last items from our test data actually appears in the output, just the first few.
Diffstat (limited to 'test')
-rwxr-xr-xtest/networkd-test.py75
1 files changed, 32 insertions, 43 deletions
diff --git a/test/networkd-test.py b/test/networkd-test.py
index 8f5d43bc88..bfa1bf3580 100755
--- a/test/networkd-test.py
+++ b/test/networkd-test.py
@@ -42,6 +42,8 @@ networkd_active = subprocess.call(['systemctl', 'is-active', '--quiet',
'systemd-networkd']) == 0
have_dnsmasq = shutil.which('dnsmasq')
+RESOLV_CONF = '/run/systemd/resolve/resolv.conf'
+
@unittest.skipIf(networkd_active,
'networkd is already active')
@@ -104,6 +106,7 @@ class ClientTestBase:
def do_test(self, coldplug=True, ipv6=False, extra_opts='',
online_timeout=10, dhcp_mode='yes'):
+ subprocess.check_call(['systemctl', 'start', 'systemd-resolved'])
with open(self.config, 'w') as f:
f.write('''[Match]
Name=%s
@@ -179,20 +182,14 @@ DHCP=%s
self.print_server_log()
raise
- # verify resolv.conf if it gets dynamically managed
- if os.path.islink('/etc/resolv.conf'):
- for timeout in range(50):
- with open('/etc/resolv.conf') as f:
- contents = f.read()
- if 'nameserver 192.168.5.1\n' in contents:
- break
- # resolv.conf can have at most three nameservers; if we already
- # have three different ones, that's also okay
- if contents.count('nameserver ') >= 3:
- break
- time.sleep(0.1)
- else:
- self.fail('nameserver 192.168.5.1 not found in /etc/resolv.conf')
+ for timeout in range(50):
+ with open(RESOLV_CONF) as f:
+ contents = f.read()
+ if 'nameserver 192.168.5.1\n' in contents:
+ break
+ time.sleep(0.1)
+ else:
+ self.fail('nameserver 192.168.5.1 not found in ' + RESOLV_CONF)
if not coldplug:
# check post-down.d hook
@@ -246,17 +243,12 @@ Domains= ~company''')
self.do_test(coldplug=True, ipv6=False,
extra_opts='IPv6AcceptRouterAdvertisements=False')
- if os.path.islink('/etc/resolv.conf'):
- with open('/etc/resolv.conf') as f:
- contents = f.read()
-
+ with open(RESOLV_CONF) as f:
+ contents = f.read()
# ~company is not a search domain, only a routing domain
self.assertNotRegex(contents, 'search.*company')
-
- # our global server should appear, unless we already have three
- # (different) servers
- if contents.count('nameserver ') < 3:
- self.assertIn('nameserver 192.168.5.1\n', contents)
+ # our global server should appear
+ self.assertIn('nameserver 192.168.5.1\n', contents)
@unittest.skipUnless(have_dnsmasq, 'dnsmasq not installed')
@@ -423,16 +415,15 @@ Domains= one two three four five six seven eight nine ten''')
subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
- if os.path.islink('/etc/resolv.conf'):
- for timeout in range(50):
- with open('/etc/resolv.conf') as f:
- contents = f.read()
- if 'search one\n' in contents:
- break
- time.sleep(0.1)
- self.assertIn('search one two three four five six\n'
- '# Too many search domains configured, remaining ones ignored.\n',
- contents)
+ for timeout in range(50):
+ with open(RESOLV_CONF) as f:
+ contents = f.read()
+ if ' one' in contents:
+ break
+ time.sleep(0.1)
+ self.assertRegex(contents, 'search .*one two three four')
+ self.assertNotIn('seven\n', contents)
+ self.assertIn('# Too many search domains configured, remaining ones ignored.\n', contents)
def test_search_domains_too_long(self):
@@ -461,16 +452,14 @@ Domains=''')
subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
- if os.path.islink('/etc/resolv.conf'):
- for timeout in range(50):
- with open('/etc/resolv.conf') as f:
- contents = f.read()
- if 'search one\n' in contents:
- break
- time.sleep(0.1)
- self.assertIn('search %(p)s0 %(p)s1 %(p)s2 %(p)s3\n'
- '# Total length of all search domains is too long, remaining ones ignored.' % {'p': name_prefix},
- contents)
+ for timeout in range(50):
+ with open(RESOLV_CONF) as f:
+ contents = f.read()
+ if ' one' in contents:
+ break
+ time.sleep(0.1)
+ self.assertRegex(contents, 'search .*%(p)s0 %(p)s1 %(p)s2' % {'p': name_prefix})
+ self.assertIn('# Total length of all search domains is too long, remaining ones ignored.', contents)
if __name__ == '__main__':