diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-18 16:17:01 +0100 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-20 12:19:21 +0100 |
commit | e8c0de91271331ddbae872de63d0a267d4f71e12 (patch) | |
tree | 766e05a6536acd6c0cb3dc82a18fbbd261680d3d /test/networkd-test.py | |
parent | test: clean up "dummy0" interface after each test case in networkd-test.py (diff) | |
download | systemd-e8c0de91271331ddbae872de63d0a267d4f71e12.tar.xz systemd-e8c0de91271331ddbae872de63d0a267d4f71e12.zip |
hostnamed: allow networkd to set the transient hostname
systemd-networkd runs as user "systemd-network" and thus is not privileged to
set the transient hostname:
systemd-networkd[516]: ens3: Could not set hostname: Interactive authentication required.
Standard polkit *.policy files do not have a syntax for granting privileges to
a user, so ship a pklocalauthority (for polkit < 106) and a JavaScript rules
file (for polkit >= 106) that grants the "systemd-network" system user that
privilege.
Add DnsmasqClientTest.test_transient_hostname() test to networkd-test.py to
cover this. Make do_test() a bit more flexible by interpreting "coldplug==None"
as "test sets up the interface by itself". Change DnsmasqClientTest to set up
test_eth42 with a fixed MAC address so that we can configure dnsmasq to send a
special host name for that.
Fixes #4646
Diffstat (limited to 'test/networkd-test.py')
-rwxr-xr-x | test/networkd-test.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/test/networkd-test.py b/test/networkd-test.py index 9767bd72f2..e3007325fa 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -123,10 +123,13 @@ DHCP=%s # create interface first, then start networkd self.create_iface(ipv6=ipv6) subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) - else: + elif coldplug is not None: # start networkd first, then create interface subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) self.create_iface(ipv6=ipv6) + else: + # "None" means test sets up interface by itself + subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) try: subprocess.check_call([self.networkd_wait_online, '--interface', @@ -196,7 +199,7 @@ DHCP=%s else: self.fail('nameserver 192.168.5.1 not found in ' + RESOLV_CONF) - if not coldplug: + if coldplug is False: # check post-down.d hook self.shutdown_iface() @@ -293,13 +296,15 @@ class DnsmasqClientTest(ClientTestBase, unittest.TestCase): def setUp(self): super().setUp() self.dnsmasq = None + self.iface_mac = 'de:ad:be:ef:47:11' def create_iface(self, ipv6=False, dnsmasq_opts=None): '''Create test interface with DHCP server behind it''' # add veth pair - subprocess.check_call(['ip', 'link', 'add', 'name', self.iface, 'type', - 'veth', 'peer', 'name', self.if_router]) + subprocess.check_call(['ip', 'link', 'add', 'name', self.iface, + 'address', self.iface_mac, + 'type', 'veth', 'peer', 'name', self.if_router]) # give our router an IP subprocess.check_call(['ip', 'a', 'flush', 'dev', self.if_router]) @@ -415,6 +420,19 @@ Domains= ~company ~lab''') self.assertRegex(general_log, 'query.*megasearch.net') self.assertNotIn('megasearch.net', vpn_log) + def test_transient_hostname(self): + '''networkd sets transient hostname from DHCP''' + + self.create_iface(dnsmasq_opts=['--dhcp-host=%s,192.168.5.210,testgreen' % self.iface_mac]) + self.do_test(coldplug=None, extra_opts='IPv6AcceptRA=False', dhcp_mode='ipv4') + + # should have received the fixed IP above + out = subprocess.check_output(['ip', '-4', 'a', 'show', 'dev', self.iface]) + self.assertRegex(out, b'inet 192.168.5.210/24 .* scope global dynamic') + + # should have set transient hostname + self.assertIn(b'testgreen', subprocess.check_output(['hostnamectl'])) + class NetworkdClientTest(ClientTestBase, unittest.TestCase): '''Test networkd client against networkd server''' |