2019-01-28 10:59:18 +00:00
|
|
|
{ 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 = [
|
2019-01-28 14:09:48 +00:00
|
|
|
../maintainers/scripts/openstack/openstack-image.nix
|
2019-01-28 10:59:18 +00:00
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
../modules/profiles/qemu-guest.nix
|
|
|
|
];
|
2019-01-28 14:09:48 +00:00
|
|
|
}).config.system.build.openstackImage;
|
2019-01-28 10:59:18 +00:00
|
|
|
|
2019-02-08 08:20:40 +00:00
|
|
|
sshKeys = import ./ssh-keys.nix pkgs;
|
|
|
|
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
|
|
|
|
snakeOilPublicKey = sshKeys.snakeOilPublicKey;
|
|
|
|
|
2019-01-28 13:44:41 +00:00
|
|
|
in {
|
|
|
|
metadata = makeEc2Test {
|
2019-01-28 14:09:48 +00:00
|
|
|
name = "openstack-ec2-metadata";
|
2019-01-28 10:59:18 +00:00
|
|
|
inherit image;
|
2019-01-28 13:44:41 +00:00
|
|
|
sshPublicKey = snakeOilPublicKey;
|
2019-01-28 10:59:18 +00:00
|
|
|
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");
|
|
|
|
'';
|
2019-01-28 13:44:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
userdata = makeEc2Test {
|
2019-01-28 14:09:48 +00:00
|
|
|
name = "openstack-ec2-metadata";
|
2019-01-28 13:44:41 +00:00
|
|
|
inherit image;
|
|
|
|
sshPublicKey = snakeOilPublicKey;
|
|
|
|
userData = ''
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
2019-01-28 14:09:48 +00:00
|
|
|
<nixpkgs/nixos/modules/virtualisation/openstack-config.nix>
|
2019-01-28 13:44:41 +00:00
|
|
|
<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'");
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|