1{ system ? builtins.currentSystem,
2 config ? {},
3 pkgs ? import ../.. { inherit system config; }
4}:
5
6with import ../lib/testing-python.nix { inherit system pkgs; };
7with pkgs.lib;
8
9let
10 # Hostname can also be set through "hostname" in user-data.
11 # This is how proxmox configures hostname through cloud-init.
12 metadataDrive = pkgs.stdenv.mkDerivation {
13 name = "metadata";
14 buildCommand = ''
15 mkdir -p $out/iso
16
17 cat << EOF > $out/iso/user-data
18 #cloud-config
19 hostname: testhostname
20 EOF
21
22 cat << EOF > $out/iso/meta-data
23 instance-id: iid-local02
24 EOF
25
26 ${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso
27 '';
28 };
29
30in makeTest {
31 name = "cloud-init-hostname";
32 meta = with pkgs.lib.maintainers; {
33 maintainers = [ lewo illustris ];
34 };
35
36 nodes.machine2 = { ... }: {
37 virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
38 services.cloud-init.enable = true;
39 networking.hostName = "";
40 };
41
42 testScript = ''
43 unnamed.wait_for_unit("cloud-final.service")
44 assert "testhostname" in unnamed.succeed("hostname")
45 '';
46}