test: fix networkd-test.py rate limiting and dynamic user

- Reset systemd-networkd.service before each test run, to avoid running
   into restart limits.
 - Our networkd-test-router.service unit needs to run as root and thus
   can't use `User=`; but networkd still insists on the
   `systemd-network` system user to exist, so create it.
This commit is contained in:
Martin Pitt
2018-07-03 14:49:50 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent a9518dc369
commit c44c1b8ab5
+8
View File
@@ -54,6 +54,11 @@ def setUpModule():
# Ensure the unit directory exists so tests can dump files into it.
os.makedirs(NETWORK_UNITDIR, exist_ok=True)
# create static systemd-network user for networkd-test-router.service (it
# needs to do some stuff as root and can't start as user; but networkd
# still insists on the user)
subprocess.check_call(['adduser', '--system', '--no-create-home', 'systemd-network'])
class NetworkdTestingUtilities:
"""Provide a set of utility functions to facilitate networkd tests.
@@ -172,6 +177,7 @@ Name=mybridge
DNS=192.168.250.1
Address=192.168.250.33/24
Gateway=192.168.250.1''')
subprocess.check_call(['systemctl', 'reset-failed', 'systemd-networkd'])
subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
def tearDown(self):
@@ -257,6 +263,8 @@ class ClientTestBase(NetworkdTestingUtilities):
self.assertTrue(out.startswith('-- cursor:'))
self.journal_cursor = out.split()[-1]
subprocess.check_call(['systemctl', 'reset-failed', 'systemd-networkd'])
def tearDown(self):
self.shutdown_iface()
subprocess.call(['systemctl', 'stop', 'systemd-networkd'])