nixos/tests/networking: test hostname via DHCP

This commit is contained in:
rnhmjoj 2025-02-26 16:02:20 +01:00
parent bf1cf6bffc
commit 54a6949722
No known key found for this signature in database
GPG Key ID: BFBAF4C975F76450
3 changed files with 31 additions and 2 deletions

View File

@ -284,7 +284,8 @@ in
[
dhcpcd
config.networking.resolvconf.package
] ++ lib.optional cfg.setHostname (
]
++ lib.optional cfg.setHostname (
pkgs.writeShellScriptBin "hostname" ''
${lib.getExe' pkgs.systemd "hostnamectl"} set-hostname --transient $1
''

View File

@ -178,6 +178,29 @@ let
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:2::2")
'';
};
dhcpHostname = {
name = "hostnameDHCP";
nodes.router = router;
nodes.client = clientConfig {
# use the name given by the DHCP server
system.name = "client";
networking.hostName = lib.mkForce "";
security.polkit.enable = true;
virtualisation.interfaces.enp1s0.vlan = 1;
networking.interfaces.enp1s0.useDHCP = true;
};
testScript = ''
router.start()
router.systemctl("start network-online.target")
router.wait_for_unit("network-online.target")
client.start()
client.wait_for_unit("network.target")
with subtest("Wait until we have received the hostname"):
client.wait_until_succeeds("hostname | grep -q 'client1'")
'';
};
dhcpOneIf = {
name = "OneInterfaceDHCP";
nodes.router = router;

View File

@ -63,7 +63,12 @@ stdenv.mkDerivation rec {
) "[ -e ${placeholder "out"}/lib/dhcpcd/dev/udev.so ]";
passthru.tests = {
inherit (nixosTests.networking.scripted) macvlan dhcpSimple dhcpOneIf;
inherit (nixosTests.networking.scripted)
macvlan
dhcpSimple
dhcpHostname
dhcpOneIf
;
};
meta = with lib; {