summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2017-06-05 18:34:06 -0400
committerGitHub <noreply@github.com>2017-06-05 18:34:06 -0400
commit225a2307166145e0d24f0e130d7c109dc9c7de7b (patch)
tree1814c9183e0d5ddca9629ad02ce3eaf623a39dcf /nixos/tests
parent9e09e3d5da136c3981fd53a735b32eab02b90f7d (diff)
parent7b80f4c3442fbb0520c8596bd06f911bdfe09465 (diff)
downloadnixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar.gz
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar.bz2
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar.lz
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar.xz
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.tar.zst
nixpkgs-225a2307166145e0d24f0e130d7c109dc9c7de7b.zip
Merge pull request #23173 from nlewo/test/cloudinit
Cloudinit test
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/cloud-init.nix47
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!'");
+  '';
+}