From 74c13b7659e6802aa05319a6e215f5ebf96fecee Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 26 Feb 2019 23:03:35 +0100 Subject: [PATCH 1/3] networkd-test: show service journal on startup failure This provides easier evaluation of failed tests. --- test/networkd-test.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/networkd-test.py b/test/networkd-test.py index 9487910b71..7c921c205b 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -335,13 +335,16 @@ class ClientTestBase(NetworkdTestingUtilities): raise NotImplementedError('must be implemented by a subclass') + def start_unit(self, unit): + try: + subprocess.check_call(['systemctl', 'start', unit]) + except subprocess.CalledProcessError: + self.show_journal(unit) + raise + def do_test(self, coldplug=True, ipv6=False, extra_opts='', online_timeout=10, dhcp_mode='yes'): - try: - subprocess.check_call(['systemctl', 'start', 'systemd-resolved']) - except subprocess.CalledProcessError: - self.show_journal('systemd-resolved.service') - raise + self.start_unit('systemd-resolved') self.write_network(self.config, '''\ [Match] Name={} @@ -352,14 +355,14 @@ DHCP={} if coldplug: # create interface first, then start networkd self.create_iface(ipv6=ipv6) - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') elif coldplug is not None: # start networkd first, then create interface - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') self.create_iface(ipv6=ipv6) else: # "None" means test sets up interface by itself - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') try: subprocess.check_call([NETWORKD_WAIT_ONLINE, '--interface', @@ -618,7 +621,7 @@ Address=10.241.3.2/24 DNS=10.241.3.1 Domains= ~company ~lab''') - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') subprocess.check_call([NETWORKD_WAIT_ONLINE, '--interface', self.iface, '--interface=testvpnclient', '--timeout=20']) @@ -888,7 +891,7 @@ Address=192.168.42.100 DNS=192.168.42.1 Domains= one two three four five six seven eight nine ten''') - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') for timeout in range(50): with open(RESOLV_CONF) as f: @@ -920,7 +923,7 @@ Address=192.168.42.100 DNS=192.168.42.1 Domains={p}0 {p}1 {p}2 {p}3 {p}4'''.format(p=name_prefix)) - subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + self.start_unit('systemd-networkd') for timeout in range(50): with open(RESOLV_CONF) as f: @@ -950,7 +953,8 @@ DNS=192.168.42.1''') [Network] DNS=127.0.0.1''') - subprocess.check_call(['systemctl', 'start', 'systemd-resolved', 'systemd-networkd']) + self.start_unit('systemd-resolved') + self.start_unit('systemd-networkd') for timeout in range(50): with open(RESOLV_CONF) as f: From 829c0672e0f43ef8f054534ed2847f41ecd796b0 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 26 Feb 2019 23:05:05 +0100 Subject: [PATCH 2/3] networkd-test: specify Address= with prefix length This avoids a warning: An address '192.168.42.100' is specified without prefix length. The behavior of parsing addresses without prefix length will be changed in the future release. Please specify prefix length explicitly. --- test/networkd-test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/networkd-test.py b/test/networkd-test.py index 7c921c205b..07b03b113d 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -475,7 +475,7 @@ MACAddress=12:34:56:78:9a:bc''') [Match] Name=dummy0 [Network] -Address=192.168.42.100 +Address=192.168.42.100/24 DNS=192.168.42.1 Domains= ~company''') @@ -499,7 +499,7 @@ MACAddress=12:34:56:78:9a:bc''') self.write_network('myvpn.network', '''[Match] Name=dummy0 [Network] -Address=192.168.42.100 +Address=192.168.42.100/24 DNS=192.168.42.1 Domains= ~company ~.''') @@ -887,7 +887,7 @@ MACAddress=12:34:56:78:9a:bc''') [Match] Name=dummy0 [Network] -Address=192.168.42.100 +Address=192.168.42.100/24 DNS=192.168.42.1 Domains= one two three four five six seven eight nine ten''') @@ -919,7 +919,7 @@ MACAddress=12:34:56:78:9a:bc''') [Match] Name=dummy0 [Network] -Address=192.168.42.100 +Address=192.168.42.100/24 DNS=192.168.42.1 Domains={p}0 {p}1 {p}2 {p}3 {p}4'''.format(p=name_prefix)) @@ -947,7 +947,7 @@ MACAddress=12:34:56:78:9a:bc''') [Match] Name=dummy0 [Network] -Address=192.168.42.100 +Address=192.168.42.100/24 DNS=192.168.42.1''') self.write_network_dropin('test.network', 'dns', '''\ [Network] From 09b8826ea371e027c76a573a226bfd8f8c5652a2 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 27 Feb 2019 23:15:31 +0100 Subject: [PATCH 3/3] networkd-test: ignore failures of test_route_only_dns* in containers This test exposes a race condition when running in LXC, see issue #11848 for details. Until that is understood and fixed, skip the test as it's not a recent regression. --- test/networkd-test.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/networkd-test.py b/test/networkd-test.py index 07b03b113d..9af141fa65 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -29,6 +29,7 @@ import time import unittest HAVE_DNSMASQ = shutil.which('dnsmasq') is not None +IS_CONTAINER = subprocess.call(['systemd-detect-virt', '--quiet', '--container']) == 0 NETWORK_UNITDIR = '/run/systemd/network' @@ -479,8 +480,15 @@ Address=192.168.42.100/24 DNS=192.168.42.1 Domains= ~company''') - self.do_test(coldplug=True, ipv6=False, - extra_opts='IPv6AcceptRouterAdvertisements=False') + try: + self.do_test(coldplug=True, ipv6=False, + extra_opts='IPv6AcceptRouterAdvertisements=False') + except subprocess.CalledProcessError as e: + # networkd often fails to start in LXC: https://github.com/systemd/systemd/issues/11848 + if IS_CONTAINER and e.cmd == ['systemctl', 'start', 'systemd-networkd']: + raise unittest.SkipTest('https://github.com/systemd/systemd/issues/11848') + else: + raise with open(RESOLV_CONF) as f: contents = f.read() @@ -503,8 +511,15 @@ Address=192.168.42.100/24 DNS=192.168.42.1 Domains= ~company ~.''') - self.do_test(coldplug=True, ipv6=False, - extra_opts='IPv6AcceptRouterAdvertisements=False') + try: + self.do_test(coldplug=True, ipv6=False, + extra_opts='IPv6AcceptRouterAdvertisements=False') + except subprocess.CalledProcessError as e: + # networkd often fails to start in LXC: https://github.com/systemd/systemd/issues/11848 + if IS_CONTAINER and e.cmd == ['systemctl', 'start', 'systemd-networkd']: + raise unittest.SkipTest('https://github.com/systemd/systemd/issues/11848') + else: + raise with open(RESOLV_CONF) as f: contents = f.read()