diff options
author | Vincent Haupert <mail@vincent-haupert.de> | 2021-11-30 09:57:15 +0100 |
---|---|---|
committer | Vincent Haupert <mail@vincent-haupert.de> | 2021-11-30 09:58:33 +0100 |
commit | ce81231420ec3499ac4e8f31076cc9425dbf90f3 (patch) | |
tree | d3e149edd849dac4d2c164af3c3bce6f1ddd10d5 /nixos/tests/systemd-networkd-dhcpserver-static-leases.nix | |
parent | 73bd63bf75def965284d5f2c58fbf4c0494ae324 (diff) | |
download | nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar.gz nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar.bz2 nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar.lz nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar.xz nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.tar.zst nixpkgs-ce81231420ec3499ac4e8f31076cc9425dbf90f3.zip |
nixos/networkd: add `dhcpServerStaticLeaseConfig` option
Add `systemd.network.networks.*.dhcpServerStaticLeaseConfig` to allow for configuring static DHCP leases through the `[DHCPServerStaticLease]` section. See systemd.network(5) of systemd 249 for details. Also adds the NixOS test `systemd-networkd-dhcpserver-static-lease` to test the assignment of static leases.
Diffstat (limited to 'nixos/tests/systemd-networkd-dhcpserver-static-leases.nix')
-rw-r--r-- | nixos/tests/systemd-networkd-dhcpserver-static-leases.nix | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/nixos/tests/systemd-networkd-dhcpserver-static-leases.nix b/nixos/tests/systemd-networkd-dhcpserver-static-leases.nix new file mode 100644 index 00000000000..a8254a15801 --- /dev/null +++ b/nixos/tests/systemd-networkd-dhcpserver-static-leases.nix @@ -0,0 +1,81 @@ +# In contrast to systemd-networkd-dhcpserver, this test configures +# the router with a static DHCP lease for the client's MAC address. +import ./make-test-python.nix ({ lib, ... }: { + name = "systemd-networkd-dhcpserver-static-leases"; + meta = with lib.maintainers; { + maintainers = [ veehaitch tomfitzhenry ]; + }; + nodes = { + router = { + virtualisation.vlans = [ 1 ]; + systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug"; + networking = { + useNetworkd = true; + useDHCP = false; + firewall.enable = false; + }; + systemd.network = { + networks = { + # systemd-networkd will load the first network unit file + # that matches, ordered lexiographically by filename. + # /etc/systemd/network/{40-eth1,99-main}.network already + # exists. This network unit must be loaded for the test, + # however, hence why this network is named such. + "01-eth1" = { + name = "eth1"; + networkConfig = { + DHCPServer = true; + Address = "10.0.0.1/24"; + }; + dhcpServerStaticLeases = [{ + dhcpServerStaticLeaseConfig = { + MACAddress = "02:de:ad:be:ef:01"; + Address = "10.0.0.10"; + }; + }]; + }; + }; + }; + }; + + client = { + virtualisation.vlans = [ 1 ]; + systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug"; + networking = { + useNetworkd = true; + useDHCP = false; + firewall.enable = false; + interfaces.eth1 = { + useDHCP = true; + macAddress = "02:de:ad:be:ef:01"; + }; + }; + + # This setting is important to have the router assign the + # configured lease based on the client's MAC address. Also see: + # https://github.com/systemd/systemd/issues/21368#issuecomment-982193546 + systemd.network.networks."40-eth1".dhcpV4Config.ClientIdentifier = "mac"; + }; + }; + testScript = '' + start_all() + + with subtest("check router network configuration"): + router.wait_for_unit("systemd-networkd-wait-online.service") + eth1_status = router.succeed("networkctl status eth1") + assert "Network File: /etc/systemd/network/01-eth1.network" in eth1_status, \ + "The router interface eth1 is not using the expected network file" + assert "10.0.0.1" in eth1_status, "Did not find expected router IPv4" + + with subtest("check client network configuration"): + client.wait_for_unit("systemd-networkd-wait-online.service") + eth1_status = client.succeed("networkctl status eth1") + assert "Network File: /etc/systemd/network/40-eth1.network" in eth1_status, \ + "The client interface eth1 is not using the expected network file" + assert "10.0.0.10" in eth1_status, "Did not find expected client IPv4" + + with subtest("router and client can reach each other"): + client.wait_until_succeeds("ping -c 5 10.0.0.1") + router.wait_until_succeeds("ping -c 5 10.0.0.10") + ''; +}) |