Skip to content

Commit

Permalink
nixos/tests/hostname: check system's host name
Browse files Browse the repository at this point in the history
NixOS currently has issues with setting the FQDN of a system in a way
where standard tools work. In order to help with experimentation and
avoid regressions, add a test that checks that the hostname is
reported as the user wanted it to be.
  • Loading branch information
blitz committed May 12, 2020
1 parent e12b962 commit efd537c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Expand Up @@ -131,6 +131,7 @@ in
hitch = handleTest ./hitch {};
hocker-fetchdocker = handleTest ./hocker-fetchdocker {};
home-assistant = handleTest ./home-assistant.nix {};
hostname = handleTest ./hostname.nix {};
hound = handleTest ./hound.nix {};
hydra = handleTest ./hydra {};
hydra-db-migration = handleTest ./hydra/db-migration.nix {};
Expand Down
50 changes: 50 additions & 0 deletions nixos/tests/hostname.nix
@@ -0,0 +1,50 @@
{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; }
}:

with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let
makeHostNameTest = hostName: domain:
let
fqdn = hostName + (optionalString (domain != null) ".${domain}");
in
makeTest {
name = "hostname-${fqdn}";

machine = { lib, ... }: {
networking.hostName = hostName;
networking.domain = domain;

environment.systemPackages = with pkgs; [
inetutils
];
};

testScript = ''
start_all()
machine = ${hostName}
machine.wait_for_unit("network.target")
assert "${fqdn}" == machine.succeed("hostname --fqdn").strip()
assert "${optionalString (domain != null) domain}" == machine.succeed("dnsdomainname").strip()
assert (
"${fqdn}"
== machine.succeed(
'hostnamectl status | grep "Static hostname" | cut -d: -f2'
).strip()
)
'';
};

in
{
noExplicitDomain = makeHostNameTest "ahost" null;

# Fails due to #10183
# explicitDomain = makeHostNameTest "ahost" "adomain";
}

0 comments on commit efd537c

Please sign in to comment.