git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/networking.nix: test the services.dhcpd4.machines option

This modifies the `router` to not give out a range of IP addresses but only give out a fixed address based on the MAC address using the `services.dhcpd4.machines` option. To get access to the MAC address the `qemuNicMac` function is defined and exported from `qemu-flags.nix`.

commite15815e885db42e642ed67527df76bbcc35f3e91 authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 20 Apr 2020, 22:06 (7 years ago) parent0410f5d
2 files changed+15−9
nixos/lib/qemu-flags.nix+3−2 nixos/tests/networking.nix+12−7
nixos/lib/qemu-flags.nix+3−2
@@ -9,10 +9,11 @@ let
99 else pkgs.lib.toHex n);
1010in
1111
12−{
12+rec {
13+ qemuNicMac = net: machine: "52:54:00:12:${zeroPad net}:${zeroPad machine}";
1314
1415 qemuNICFlags = nic: net: machine:
15− [ "-device virtio-net-pci,netdev=vlan${toString nic},mac=52:54:00:12:${zeroPad net}:${zeroPad machine}"
16+ [ "-device virtio-net-pci,netdev=vlan${toString nic},mac=${qemuNicMac net machine}"
1617 "-netdev vde,id=vlan${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
1718 ];
1819
nixos/tests/networking.nix+12−7
@@ -8,7 +8,9 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
88with pkgs.lib;
99
1010let
11− router = { config, pkgs, ... }:
11+ qemu-flags = import ../lib/qemu-flags.nix { inherit pkgs; };
12+
13+ router = { config, pkgs, lib, ... }:
1214 with pkgs.lib;
1315 let
1416 vlanIfs = range 1 (length config.virtualisation.vlans);
@@ -31,16 +33,19 @@ let
3133 enable = true;
3234 interfaces = map (n: "eth${toString n}") vlanIfs;
3335 extraConfig = ''
34− authoritative;
3536 '' + flip concatMapStrings vlanIfs (n: ''
3637 subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
3738 option routers 192.168.${toString n}.1;
38− # XXX: technically it's _not guaranteed_ that IP addresses will be
39− # issued from the first item in range onwards! We assume that in
40− # our tests however.
41− range 192.168.${toString n}.2 192.168.${toString n}.254;
4239 }
43− '');
40+ '')
41+ ;
42+ machines = lib.flip map vlanIfs (vlan:
43+ {
44+ hostName = "client${toString vlan}";
45+ ethernetAddress = qemu-flags.qemuNicMac vlan 1;
46+ ipAddress = "192.168.${toString vlan}.2";
47+ }
48+ );
4449 };
4550 services.radvd = {
4651 enable = true;