diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-12-11 11:37:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 11:37:05 +0100 |
commit | 3bf72311c8a1b92b032285b0f7dff3f49d97ddc6 (patch) | |
tree | 0e4228fa30b9d28e23bc811178bc4671cab449c3 /test | |
parent | Logitech MX Master 2S: Unifying Receiver and Bluetooth Connectivity (#11078) (diff) | |
parent | networkd-test: add mkosi snippet for building and running networkd-tets.py in... (diff) | |
download | systemd-3bf72311c8a1b92b032285b0f7dff3f49d97ddc6.tar.gz systemd-3bf72311c8a1b92b032285b0f7dff3f49d97ddc6.tar.bz2 systemd-3bf72311c8a1b92b032285b0f7dff3f49d97ddc6.zip |
Merge pull request #11084 from poettering/networkd-test-fix
unbreak networkd-test.py
Diffstat (limited to 'test')
-rwxr-xr-x | test/mkosi.build.networkd-test | 24 | ||||
-rw-r--r-- | test/mkosi.default.networkd-test | 80 | ||||
-rw-r--r-- | test/mkosi.nspawn.networkd-test | 2 | ||||
-rwxr-xr-x | test/networkd-test.py | 43 |
4 files changed, 137 insertions, 12 deletions
diff --git a/test/mkosi.build.networkd-test b/test/mkosi.build.networkd-test new file mode 100755 index 000000000..cdaa4302f --- /dev/null +++ b/test/mkosi.build.networkd-test @@ -0,0 +1,24 @@ +#!/bin/sh +set -ex + +# First, source in the main build script +. "$SRCDIR"/mkosi.build + +mkdir -p "$DESTDIR"/usr/local/bin +cp "$SRCDIR"/test/networkd-test.py "$DESTDIR"/usr/local/bin/networkd-test.py + +mkdir -p "$DESTDIR"/etc/systemd/system +cat > "$DESTDIR"/etc/systemd/system/networkd-test.service <<EOF +[Unit] +Description=networkd test service +SuccessAction=exit +FailureAction=exit + +[Service] +ExecStart=/usr/local/bin/networkd-test.py +EOF + +mkdir -p "$DESTDIR"/etc/systemd/system/multi-user.target.wants/ +ln -s ../networkd-test.service "$DESTDIR"/etc/systemd/system/multi-user.target.wants/ + +systemctl --root="$DESTDIR" disable systemd-networkd.service diff --git a/test/mkosi.default.networkd-test b/test/mkosi.default.networkd-test new file mode 100644 index 000000000..9630d3ec4 --- /dev/null +++ b/test/mkosi.default.networkd-test @@ -0,0 +1,80 @@ +# Puts together an nspawn container and runs networkd-test.py in it, inside a +# network namespace and everything. Run this with "mkosi +# --default=mkosi.default.networkd-test boot". This will start the test and +# eventually exit with sucess in case the test succeeded. + +[Distribution] +Distribution=fedora +Release=29 + +[Output] +Format=raw_btrfs +Bootable=yes +KernelCommandLine=printk.devkmsg=on +OutputDirectory=../mkosi.output +Output=networkd-test.raw + +[Partitions] +RootSize=3G + +[Packages] +BuildPackages= + audit-libs-devel + bzip2-devel + cryptsetup-devel + dbus-devel + diffutils + docbook-style-xsl + elfutils-devel + gcc + gettext + git + gnu-efi + gnu-efi-devel + gnutls-devel + gperf + hostname + iptables-devel + kmod-devel + libacl-devel + libblkid-devel + libcap-devel + libcurl-devel + libgcrypt-devel + libidn2-devel + libmicrohttpd-devel + libmount-devel + libseccomp-devel + libselinux-devel + libtool + libxkbcommon-devel + libxslt + lz4 + lz4-devel + m4 + meson + pam-devel + pcre2-devel + pkgconfig + python3-devel + python3-lxml + qrencode-devel + tree + xz-devel + +Packages= + dnsmasq + iproute + libidn2 + polkit + python3 + +# Share caches with the top-level mkosi +BuildDirectory=../mkosi.builddir +Cache=../mkosi.cache + +# Run our own script +BuildScript=mkosi.build.networkd-test + +BuildSources=.. +NSpawnSettings=mkosi.nspawn.networkd-test diff --git a/test/mkosi.nspawn.networkd-test b/test/mkosi.nspawn.networkd-test new file mode 100644 index 000000000..a23aed6ed --- /dev/null +++ b/test/mkosi.nspawn.networkd-test @@ -0,0 +1,2 @@ +[Network] +Private=yes diff --git a/test/networkd-test.py b/test/networkd-test.py index d876f3a9e..176d52a02 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -53,6 +53,7 @@ def setUpModule(): if (subprocess.call(['systemctl', 'is-active', '--quiet', 'systemd-networkd.service']) == 0 and subprocess.call(['systemd-detect-virt', '--quiet']) != 0): raise unittest.SkipTest('not virtualized and networkd is already active') + # Ensure we don't mess with an existing networkd config for u in ['systemd-networkd.socket', 'systemd-networkd', 'systemd-resolved']: if subprocess.call(['systemctl', 'is-active', '--quiet', u]) == 0: @@ -60,6 +61,12 @@ def setUpModule(): running_units.append(u) else: stopped_units.append(u) + + # 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.call(['adduser', '--system', '--no-create-home', 'systemd-network']) + for d in ['/etc/systemd/network', '/run/systemd/network', '/run/systemd/netif', '/run/systemd/resolve']: if os.path.isdir(d): @@ -68,6 +75,9 @@ def setUpModule(): if os.path.isdir('/run/systemd/resolve'): os.chmod('/run/systemd/resolve', 0o755) shutil.chown('/run/systemd/resolve', 'systemd-resolve', 'systemd-resolve') + if os.path.isdir('/run/systemd/netif'): + os.chmod('/run/systemd/netif', 0o755) + shutil.chown('/run/systemd/netif', 'systemd-network', 'systemd-network') # Avoid "Failed to open /dev/tty" errors in containers. os.environ['SYSTEMD_LOG_TARGET'] = 'journal' @@ -75,11 +85,6 @@ 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']) - def tearDownModule(): global tmpmounts @@ -106,13 +111,17 @@ class NetworkdTestingUtilities: list(peer_options)) self.addCleanup(subprocess.call, ['ip', 'link', 'del', 'dev', peer]) + def write_config(self, path, contents): + """"Write a configuration file, and queue it to be removed.""" + + with open(path, 'w') as f: + f.write(contents) + + self.addCleanup(os.remove, path) + def write_network(self, unit_name, contents): """Write a network unit file, and queue it to be removed.""" - unit_path = os.path.join(NETWORK_UNITDIR, unit_name) - - with open(unit_path, 'w') as unit: - unit.write(contents) - self.addCleanup(os.remove, unit_path) + self.write_config(os.path.join(NETWORK_UNITDIR, unit_name), contents) def write_network_dropin(self, unit_name, dropin_name, contents): """Write a network unit drop-in, and queue it to be removed.""" @@ -700,6 +709,7 @@ Domains= ~company ~lab''') subprocess.check_call(['mount', '--bind', '/dev/null', '/etc/hostname']) self.addCleanup(subprocess.call, ['umount', '/etc/hostname']) subprocess.check_call(['systemctl', 'stop', 'systemd-hostnamed.service']) + self.addCleanup(subprocess.call, ['systemctl', 'stop', 'systemd-hostnamed.service']) self.create_iface(dnsmasq_opts=['--dhcp-host={},192.168.5.210,testgreen'.format(self.iface_mac)]) self.do_test(coldplug=None, extra_opts='IPv6AcceptRA=False', dhcp_mode='ipv4') @@ -732,9 +742,18 @@ Domains= ~company ~lab''') orig_hostname = socket.gethostname() self.addCleanup(socket.sethostname, orig_hostname) + if not os.path.exists('/etc/hostname'): - self.writeConfig('/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']) self.create_iface(dnsmasq_opts=['--dhcp-host={},192.168.5.210,testgreen'.format(self.iface_mac)]) self.do_test(coldplug=None, extra_opts='IPv6AcceptRA=False', dhcp_mode='ipv4') @@ -744,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') |