1 # In contrast to systemd-networkd-dhcpserver, this test configures
2 # the router with a static DHCP lease for the client's MAC address.
3 import ./make-test-python.nix ({ lib, ... }: {
4 name = "systemd-networkd-dhcpserver-static-leases";
5 meta = with lib.maintainers; {
6 maintainers = [ veehaitch ];
10 virtualisation.vlans = [ 1 ];
11 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
15 firewall.enable = false;
19 # systemd-networkd will load the first network unit file
20 # that matches, ordered lexiographically by filename.
21 # /etc/systemd/network/{40-eth1,99-main}.network already
22 # exists. This network unit must be loaded for the test,
23 # however, hence why this network is named such.
28 Address = "10.0.0.1/24";
30 dhcpServerStaticLeases = [{
31 MACAddress = "02:de:ad:be:ef:01";
32 Address = "10.0.0.10";
40 virtualisation.vlans = [ 1 ];
41 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
45 matchConfig.OriginalName = "eth1";
46 linkConfig.MACAddress = "02:de:ad:be:ef:01";
48 networks."40-eth1" = {
49 matchConfig.Name = "eth1";
54 # This setting is important to have the router assign the
55 # configured lease based on the client's MAC address. Also see:
56 # https://github.com/systemd/systemd/issues/21368#issuecomment-982193546
57 dhcpV4Config.ClientIdentifier = "mac";
58 linkConfig.RequiredForOnline = "routable";
63 firewall.enable = false;
64 interfaces.eth1 = lib.mkForce {};
71 with subtest("check router network configuration"):
72 router.wait_for_unit("systemd-networkd-wait-online.service")
73 eth1_status = router.succeed("networkctl status eth1")
74 assert "Network File: /etc/systemd/network/01-eth1.network" in eth1_status, \
75 "The router interface eth1 is not using the expected network file"
76 assert "10.0.0.1" in eth1_status, "Did not find expected router IPv4"
78 with subtest("check client network configuration"):
79 client.wait_for_unit("systemd-networkd-wait-online.service")
80 eth1_status = client.succeed("networkctl status eth1")
81 assert "Network File: /etc/systemd/network/40-eth1.network" in eth1_status, \
82 "The client interface eth1 is not using the expected network file"
83 assert "10.0.0.10" in eth1_status, "Did not find expected client IPv4"
85 with subtest("router and client can reach each other"):
86 client.wait_until_succeeds("ping -c 5 10.0.0.1")
87 router.wait_until_succeeds("ping -c 5 10.0.0.10")