summaryrefslogtreecommitdiff
path: root/test/networkd-test.py
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-12-05 22:00:42 +0100
committerLennart Poettering <lennart@poettering.net>2018-12-07 12:25:24 +0100
commit0373fc5b6f8478aa5d07458a7c2267a5b26daa1d (patch)
treea5a5b777790ff925f8c77769faadbcd1eb8e528b /test/networkd-test.py
parent8e0ba0c984bc39e76d993c64bf6efd427268613d (diff)
downloadsystemd-0373fc5b6f8478aa5d07458a7c2267a5b26daa1d.tar.gz
networkd-test: change test_transient_hostname_with_static to use an explicit static hostname
Previously, the test would use the existing static hostname. However, this woud not work as expected in the static hostname was "localhost" because the transient hostname will override the static one in that case anyway, as the assumption hostnamed makes is that "localhost" is a non-initialized hostname. Hence when testing this, let's first set the static hostname to something specific first (that is not "localhost").
Diffstat (limited to 'test/networkd-test.py')
-rwxr-xr-xtest/networkd-test.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/networkd-test.py b/test/networkd-test.py
index 0dc19a616e..176d52a028 100755
--- a/test/networkd-test.py
+++ b/test/networkd-test.py
@@ -742,8 +742,16 @@ Domains= ~company ~lab''')
orig_hostname = socket.gethostname()
self.addCleanup(socket.sethostname, orig_hostname)
+
if not os.path.exists('/etc/hostname'):
- self.write_config('/etc/hostname', orig_hostname)
+ self.write_config('/etc/hostname', "foobarqux")
+ else:
+ self.write_config('/run/hostname.tmp', "foobarqux")
+ subprocess.check_call(['mount', '--bind', '/run/hostname.tmp', '/etc/hostname'])
+ self.addCleanup(subprocess.call, ['umount', '/etc/hostname'])
+
+ socket.sethostname("foobarqux");
+
subprocess.check_call(['systemctl', 'stop', 'systemd-hostnamed.service'])
self.addCleanup(subprocess.call, ['systemctl', 'stop', 'systemd-hostnamed.service'])
@@ -755,7 +763,7 @@ Domains= ~company ~lab''')
out = subprocess.check_output(['ip', '-4', 'a', 'show', 'dev', self.iface])
self.assertRegex(out, b'inet 192.168.5.210/24 .* scope global dynamic')
# static hostname wins over transient one, thus *not* applied
- self.assertEqual(socket.gethostname(), orig_hostname)
+ self.assertEqual(socket.gethostname(), "foobarqux")
except AssertionError:
self.show_journal('systemd-networkd.service')
self.show_journal('systemd-hostnamed.service')