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