From 849460f8789943b9758c6e782d1cc0bb8a8bd950 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Mon, 28 Jan 2019 14:44:41 +0100 Subject: [PATCH] nova-image: add amazon-init module to the nova image This allows the VM to provide a `configuration.nix` file to the VM. The test doesn't work in sandbox because it needs Internet (however it works interactively). --- nixos/modules/virtualisation/nova-config.nix | 3 +- nixos/tests/nova-image.nix | 36 ++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/nixos/modules/virtualisation/nova-config.nix b/nixos/modules/virtualisation/nova-config.nix index fef20d498e9..c944fff96a8 100644 --- a/nixos/modules/virtualisation/nova-config.nix +++ b/nixos/modules/virtualisation/nova-config.nix @@ -8,6 +8,7 @@ with lib; ../profiles/headless.nix # The Openstack Metadata service exposes data on an EC2 API also. ./ec2-data.nix + ./amazon-init.nix ]; config = { @@ -32,7 +33,7 @@ with lib; path = [ pkgs.wget ]; description = "Fetch Metadata on startup"; wantedBy = [ "multi-user.target" ]; - before = [ "apply-ec2-data.service" ]; + before = [ "apply-ec2-data.service" "amazon-init.service"]; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; script = diff --git a/nixos/tests/nova-image.nix b/nixos/tests/nova-image.nix index 488649b70e6..7934ab31c70 100644 --- a/nixos/tests/nova-image.nix +++ b/nixos/tests/nova-image.nix @@ -19,12 +19,11 @@ let ]; }).config.system.build.novaImage; -in - makeEc2Test { - name = "nova-ec2-metadata"; +in { + metadata = makeEc2Test { + name = "nova-ec2-metadata"; inherit image; - sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key! - + sshPublicKey = snakeOilPublicKey; userData = '' SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey} SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey} @@ -57,4 +56,29 @@ in $machine->start; $machine->waitForFile("/etc/ec2-metadata/user-data"); ''; - } + }; + + userdata = makeEc2Test { + name = "nova-ec2-metadata"; + inherit image; + sshPublicKey = snakeOilPublicKey; + userData = '' + { pkgs, ... }: + { + imports = [ + + + + ]; + environment.etc.testFile = { + text = "whoa"; + }; + } + ''; + script = '' + $machine->start; + $machine->waitForFile("/etc/testFile"); + $machine->succeed("cat /etc/testFile | grep -q 'whoa'"); + ''; + }; +}