about summary refs log tree commit diff
path: root/nixos/tests/openstack-image.nix
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2019-01-28 15:09:48 +0100
committerAntoine Eiche <lewo@abesis.fr>2019-02-11 20:58:44 +0100
commitd190b204f001d1446807f56eed99a73f8b89e244 (patch)
treea4611c949d4f22b5dce7846382a27b266b212570 /nixos/tests/openstack-image.nix
parent849460f8789943b9758c6e782d1cc0bb8a8bd950 (diff)
downloadnixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar.gz
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar.bz2
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar.lz
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar.xz
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.tar.zst
nixlib-d190b204f001d1446807f56eed99a73f8b89e244.zip
Rename `novaImage` to `openstackImage`
People don't necessary know `nova` is related to Openstack (it is a
component of Openstack). So, it is more explicit to call it
`openstackImage`.
Diffstat (limited to 'nixos/tests/openstack-image.nix')
-rw-r--r--nixos/tests/openstack-image.nix84
1 files changed, 84 insertions, 0 deletions
diff --git a/nixos/tests/openstack-image.nix b/nixos/tests/openstack-image.nix
new file mode 100644
index 000000000000..c7b28126e508
--- /dev/null
+++ b/nixos/tests/openstack-image.nix
@@ -0,0 +1,84 @@
+{ system ? builtins.currentSystem,
+  config ? {},
+  pkgs ? import ../.. { inherit system config; }
+}:
+
+with import ../lib/testing.nix { inherit system pkgs; };
+with pkgs.lib;
+
+with import common/ec2.nix { inherit makeTest pkgs; };
+
+let
+  image =
+    (import ../lib/eval-config.nix {
+      inherit system;
+      modules = [
+        ../maintainers/scripts/openstack/openstack-image.nix
+        ../modules/testing/test-instrumentation.nix
+        ../modules/profiles/qemu-guest.nix
+      ];
+    }).config.system.build.openstackImage;
+
+in {
+  metadata = makeEc2Test {
+    name = "openstack-ec2-metadata";
+    inherit image;
+    sshPublicKey = snakeOilPublicKey;
+    userData = ''
+      SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
+      SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
+    '';
+    script = ''
+      $machine->start;
+      $machine->waitForFile("/etc/ec2-metadata/user-data");
+      $machine->waitForUnit("sshd.service");
+
+      $machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
+
+      # We have no keys configured on the client side yet, so this should fail
+      $machine->fail("ssh -o BatchMode=yes localhost exit");
+
+      # Let's install our client private key
+      $machine->succeed("mkdir -p ~/.ssh");
+
+      $machine->succeed("echo '${snakeOilPrivateKey}' > ~/.ssh/id_ed25519");
+      $machine->succeed("chmod 600 ~/.ssh/id_ed25519");
+
+      # We haven't configured the host key yet, so this should still fail
+      $machine->fail("ssh -o BatchMode=yes localhost exit");
+
+      # Add the host key; ssh should finally succeed
+      $machine->succeed("echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts");
+      $machine->succeed("ssh -o BatchMode=yes localhost exit");
+
+      # Just to make sure resizing is idempotent.
+      $machine->shutdown;
+      $machine->start;
+      $machine->waitForFile("/etc/ec2-metadata/user-data");
+    '';
+  };
+
+  userdata = makeEc2Test {
+    name = "openstack-ec2-metadata";
+    inherit image;
+    sshPublicKey = snakeOilPublicKey;
+    userData = ''
+      { pkgs, ... }:
+      {
+        imports = [
+          <nixpkgs/nixos/modules/virtualisation/openstack-config.nix>
+          <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
+          <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
+        ];
+        environment.etc.testFile = {
+          text = "whoa";
+        };
+      }
+    '';
+    script = ''
+      $machine->start;
+      $machine->waitForFile("/etc/testFile");
+      $machine->succeed("cat /etc/testFile | grep -q 'whoa'");
+    '';
+  };
+}