about summary refs log tree commit diff
path: root/nixos/tests/cloud-init-hostname.nix
blob: 7c657cc9f6f98ca87373b89642d13f1e54be2ce3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ system ? builtins.currentSystem,
  config ? {},
  pkgs ? import ../.. { inherit system config; }
}:

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

let
  # Hostname can also be set through "hostname" in user-data.
  # This is how proxmox configures hostname through cloud-init.
  metadataDrive = pkgs.stdenv.mkDerivation {
    name = "metadata";
    buildCommand = ''
      mkdir -p $out/iso

      cat << EOF > $out/iso/user-data
      #cloud-config
      hostname: testhostname
      EOF

      cat << EOF > $out/iso/meta-data
      instance-id: iid-local02
      EOF

      ${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso
    '';
  };

in makeTest {
  name = "cloud-init-hostname";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ lewo illustris ];
  };

  nodes.machine2 = { ... }: {
    virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
    services.cloud-init.enable = true;
    networking.hostName = "";
  };

  testScript = ''
    unnamed.wait_for_unit("cloud-final.service")
    assert "testhostname" in unnamed.succeed("hostname")
  '';
}