summaryrefslogtreecommitdiffstats
path: root/test/networkd-test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/networkd-test.py')
-rwxr-xr-xtest/networkd-test.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/test/networkd-test.py b/test/networkd-test.py
index 512137c..47a3ad7 100755
--- a/test/networkd-test.py
+++ b/test/networkd-test.py
@@ -888,8 +888,10 @@ class NetworkdClientTest(ClientTestBase, unittest.TestCase):
set -eu
mkdir -p /run/systemd/network
mkdir -p /run/systemd/netif
+mkdir -p /var/lib/systemd/network
mount -t tmpfs none /run/systemd/network
mount -t tmpfs none /run/systemd/netif
+mount -t tmpfs none /var/lib/systemd/network
[ ! -e /run/dbus ] || mount -t tmpfs none /run/dbus
# create router/client veth pair
cat <<EOF >/run/systemd/network/50-test.netdev
@@ -917,6 +919,10 @@ DNS=192.168.5.1
{dhopts}
EOF
+# For the networkd instance invoked below cannot support varlink connection.
+# Hence, 'networkctl persistent-storage yes' cannot be used.
+export SYSTEMD_NETWORK_PERSISTENT_STORAGE_READY=1
+
# run networkd as in systemd-networkd.service
exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ {{ s/^.*=//; s/^[@+-]//; s/^!*//; p}}')
'''.format(ifr=self.if_router,
@@ -930,6 +936,7 @@ exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ {{ s/^.*=/
'-p', 'InaccessibleDirectories=-/etc/systemd/network',
'-p', 'InaccessibleDirectories=-/run/systemd/network',
'-p', 'InaccessibleDirectories=-/run/systemd/netif',
+ '-p', 'InaccessibleDirectories=-/var/lib/systemd/network',
'--service-type=notify', script])
# wait until devices got created
@@ -1017,17 +1024,19 @@ DNS=127.0.0.1
self.start_unit('systemd-resolved')
self.start_unit('systemd-networkd')
- for timeout in range(50):
+ subprocess.check_call([NETWORKD_WAIT_ONLINE, '--interface', 'dummy0', '--timeout=10'])
+
+ out = subprocess.check_output(['networkctl', 'status', 'dummy0'])
+ self.assertIn(b'50-test.network.d/dns.conf', out)
+
+ for _ in range(50):
with open(RESOLV_CONF) as f:
contents = f.read()
- if ' 127.0.0.1' in contents and '192.168.42.1' in contents:
+ if 'nameserver 127.0.0.1\n' in contents and 'nameserver 192.168.42.1\n' in contents:
break
time.sleep(0.1)
- self.assertIn('nameserver 192.168.42.1\n', contents)
- self.assertIn('nameserver 127.0.0.1\n', contents)
-
- out = subprocess.check_output(['networkctl', 'status', 'dummy0'])
- self.assertIn(b'50-test.network.d/dns.conf', out)
+ else:
+ self.fail(f'Expected DNS servers not found in resolv.conf: {contents}')
def test_dhcp_timezone(self):
'''networkd sets time zone from DHCP'''
@@ -1046,13 +1055,16 @@ DNS=127.0.0.1
self.create_iface(dhcpserver_opts='EmitTimezone=yes\nTimezone=Pacific/Honolulu')
self.do_test(coldplug=None, extra_opts='IPv6AcceptRA=false\n[DHCP]\nUseTimezone=true', dhcp_mode='ipv4')
- # should have applied the received timezone
- try:
- self.assertEqual(get_tz(), 'Pacific/Honolulu')
- except AssertionError:
+ # Should have applied the received timezone. This is asynchronous, so we need to wait for a while:
+ for _ in range(20):
+ tz = get_tz()
+ if tz == 'Pacific/Honolulu':
+ break
+ time.sleep(0.5)
+ else:
self.show_journal('systemd-networkd.service')
- self.show_journal('systemd-hostnamed.service')
- raise
+ self.show_journal('systemd-timedated.service')
+ self.fail(f'Timezone: {tz}, expected: Pacific/Honolulu')
class MatchClientTest(unittest.TestCase, NetworkdTestingUtilities):