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).
This commit is contained in:
Antoine Eiche 2019-01-28 14:44:41 +01:00
parent 2858b35100
commit 849460f878
2 changed files with 32 additions and 7 deletions

View file

@ -8,6 +8,7 @@ with lib;
../profiles/headless.nix ../profiles/headless.nix
# The Openstack Metadata service exposes data on an EC2 API also. # The Openstack Metadata service exposes data on an EC2 API also.
./ec2-data.nix ./ec2-data.nix
./amazon-init.nix
]; ];
config = { config = {
@ -32,7 +33,7 @@ with lib;
path = [ pkgs.wget ]; path = [ pkgs.wget ];
description = "Fetch Metadata on startup"; description = "Fetch Metadata on startup";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
before = [ "apply-ec2-data.service" ]; before = [ "apply-ec2-data.service" "amazon-init.service"];
wants = [ "network-online.target" ]; wants = [ "network-online.target" ];
after = [ "network-online.target" ]; after = [ "network-online.target" ];
script = script =

View file

@ -19,12 +19,11 @@ let
]; ];
}).config.system.build.novaImage; }).config.system.build.novaImage;
in in {
makeEc2Test { metadata = makeEc2Test {
name = "nova-ec2-metadata"; name = "nova-ec2-metadata";
inherit image; inherit image;
sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key! sshPublicKey = snakeOilPublicKey;
userData = '' userData = ''
SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey} SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey} SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
@ -57,4 +56,29 @@ in
$machine->start; $machine->start;
$machine->waitForFile("/etc/ec2-metadata/user-data"); $machine->waitForFile("/etc/ec2-metadata/user-data");
''; '';
} };
userdata = makeEc2Test {
name = "nova-ec2-metadata";
inherit image;
sshPublicKey = snakeOilPublicKey;
userData = ''
{ pkgs, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/nova-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'");
'';
};
}