diff options
author | Antoine Eiche <lewo@abesis.fr> | 2017-02-25 15:32:06 +0100 |
---|---|---|
committer | Antoine Eiche <lewo@abesis.fr> | 2017-05-23 20:51:05 +0200 |
commit | 7b80f4c3442fbb0520c8596bd06f911bdfe09465 (patch) | |
tree | 14b08317c3dff33a0d750e574de1ded3e310579b /nixos/tests/cloud-init.nix | |
parent | 3497ba5c3a994379cca9bf44ba832cc66576fb58 (diff) | |
download | nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar.gz nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar.bz2 nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar.lz nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar.xz nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.tar.zst nixpkgs-7b80f4c3442fbb0520c8596bd06f911bdfe09465.zip |
nixos/cloudinit: add cloudinit test
An iso containing metadatas is created and attached as a cdrom to the qemu VM used for this test. The cloudinit service is enabled. The test case ensures the root authorized_keys file is populated and the cloudinit write_file module is working well.
Diffstat (limited to 'nixos/tests/cloud-init.nix')
-rw-r--r-- | nixos/tests/cloud-init.nix | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/nixos/tests/cloud-init.nix b/nixos/tests/cloud-init.nix new file mode 100644 index 00000000000..c0add7eff36 --- /dev/null +++ b/nixos/tests/cloud-init.nix @@ -0,0 +1,47 @@ +{ system ? builtins.currentSystem }: + +with import ../lib/testing.nix { inherit system; }; +with import ../lib/qemu-flags.nix; +with pkgs.lib; + +let + metadataDrive = pkgs.stdenv.mkDerivation { + name = "metadata"; + buildCommand = '' + mkdir -p $out/iso + + cat << EOF > $out/iso/user-data + #cloud-config + write_files: + - content: | + cloudinit + path: /tmp/cloudinit-write-file + EOF + + cat << EOF > $out/iso/meta-data + instance-id: iid-local01 + local-hostname: "test" + public-keys: + - "should be a key!" + EOF + ${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso + ''; + }; +in makeTest { + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ lewo ]; + }; + machine = + { config, pkgs, ... }: + { + virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ]; + services.cloud-init.enable = true; + }; + testScript = '' + $machine->start; + $machine->waitForUnit("cloud-init.service"); + $machine->succeed("cat /tmp/cloudinit-write-file | grep -q 'cloudinit'"); + + $machine->waitUntilSucceeds("cat /root/.ssh/authorized_keys | grep -q 'should be a key!'"); + ''; +} |