2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
2015-05-27 07:12:26 +01:00
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2015-05-27 07:12:26 +01:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2019-01-28 10:59:18 +00:00
|
|
|
with import common/ec2.nix { inherit makeTest pkgs; };
|
|
|
|
|
2015-05-27 07:12:26 +01:00
|
|
|
let
|
2020-02-02 08:48:11 +00:00
|
|
|
imageCfg = (import ../lib/eval-config.nix {
|
|
|
|
inherit system;
|
|
|
|
modules = [
|
|
|
|
../maintainers/scripts/ec2/amazon-image.nix
|
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
../modules/profiles/qemu-guest.nix
|
|
|
|
{
|
|
|
|
ec2.hvm = true;
|
|
|
|
|
|
|
|
# Hack to make the partition resizing work in QEMU.
|
|
|
|
boot.initrd.postDeviceCommands = mkBefore ''
|
|
|
|
ln -s vda /dev/xvda
|
|
|
|
ln -s vda1 /dev/xvda1
|
|
|
|
'';
|
|
|
|
|
2021-09-22 08:19:46 +01:00
|
|
|
# In a NixOS test the serial console is occupied by the "backdoor"
|
|
|
|
# (see testing/test-instrumentation.nix) and is incompatible with
|
|
|
|
# the configuration in virtualisation/amazon-image.nix.
|
|
|
|
systemd.services."serial-getty@ttyS0".enable = mkForce false;
|
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
# Needed by nixos-rebuild due to the lack of network
|
|
|
|
# access. Determined by trial and error.
|
|
|
|
system.extraDependencies = with pkgs; ( [
|
|
|
|
# Needed for a nixos-rebuild.
|
|
|
|
busybox
|
|
|
|
cloud-utils
|
|
|
|
desktop-file-utils
|
|
|
|
libxslt.bin
|
|
|
|
mkinitcpio-nfs-utils
|
|
|
|
stdenv
|
|
|
|
stdenvNoCC
|
|
|
|
texinfo
|
|
|
|
unionfs-fuse
|
|
|
|
xorg.lndir
|
|
|
|
|
|
|
|
# These are used in the configure-from-userdata tests
|
|
|
|
# for EC2. Httpd and valgrind are requested by the
|
|
|
|
# configuration.
|
|
|
|
apacheHttpd
|
|
|
|
apacheHttpd.doc
|
|
|
|
apacheHttpd.man
|
|
|
|
valgrind.doc
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}).config;
|
2020-01-12 17:40:44 +00:00
|
|
|
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
|
2015-05-27 07:12:26 +01:00
|
|
|
|
2019-02-08 08:20:40 +00:00
|
|
|
sshKeys = import ./ssh-keys.nix pkgs;
|
|
|
|
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
|
2020-02-02 08:48:11 +00:00
|
|
|
snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey;
|
2019-02-08 08:20:40 +00:00
|
|
|
snakeOilPublicKey = sshKeys.snakeOilPublicKey;
|
|
|
|
|
2015-05-27 07:12:26 +01:00
|
|
|
in {
|
2015-04-10 05:06:52 +01:00
|
|
|
boot-ec2-nixops = makeEc2Test {
|
2015-05-27 07:12:26 +01:00
|
|
|
name = "nixops-userdata";
|
2019-01-28 10:59:18 +00:00
|
|
|
inherit image;
|
2015-05-27 07:12:26 +01:00
|
|
|
sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key!
|
|
|
|
|
|
|
|
userData = ''
|
2015-09-28 12:42:24 +01:00
|
|
|
SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
|
|
|
|
SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
|
2015-05-27 07:12:26 +01:00
|
|
|
'';
|
|
|
|
script = ''
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_file("/etc/ec2-metadata/user-data")
|
|
|
|
machine.wait_for_unit("sshd.service")
|
2015-05-27 07:12:26 +01:00
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
|
2016-02-02 18:03:13 +00:00
|
|
|
|
2015-05-27 07:12:26 +01:00
|
|
|
# We have no keys configured on the client side yet, so this should fail
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.fail("ssh -o BatchMode=yes localhost exit")
|
2015-05-27 07:12:26 +01:00
|
|
|
|
|
|
|
# Let's install our client private key
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.succeed("mkdir -p ~/.ssh")
|
2015-09-28 12:42:24 +01:00
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.copy_from_host_via_shell(
|
|
|
|
"${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519"
|
|
|
|
)
|
|
|
|
machine.succeed("chmod 600 ~/.ssh/id_ed25519")
|
2015-05-27 07:12:26 +01:00
|
|
|
|
|
|
|
# We haven't configured the host key yet, so this should still fail
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.fail("ssh -o BatchMode=yes localhost exit")
|
2015-05-27 07:12:26 +01:00
|
|
|
|
|
|
|
# Add the host key; ssh should finally succeed
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.succeed(
|
|
|
|
"echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
|
|
|
|
)
|
|
|
|
machine.succeed("ssh -o BatchMode=yes localhost exit")
|
2015-05-27 07:12:26 +01:00
|
|
|
|
2015-09-28 19:25:10 +01:00
|
|
|
# Test whether the root disk was resized.
|
2020-02-02 08:48:11 +00:00
|
|
|
blocks, block_size = map(int, machine.succeed("stat -c %b:%S -f /").split(":"))
|
|
|
|
GB = 1024 ** 3
|
|
|
|
assert 9.7 * GB <= blocks * block_size <= 10 * GB
|
2015-09-28 19:25:10 +01:00
|
|
|
|
|
|
|
# Just to make sure resizing is idempotent.
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.shutdown()
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_file("/etc/ec2-metadata/user-data")
|
2015-05-27 07:12:26 +01:00
|
|
|
'';
|
|
|
|
};
|
2015-04-10 05:06:52 +01:00
|
|
|
|
|
|
|
boot-ec2-config = makeEc2Test {
|
|
|
|
name = "config-userdata";
|
2020-08-23 09:31:58 +01:00
|
|
|
meta.broken = true; # amazon-init wants to download from the internet while building the system
|
2019-01-28 10:59:18 +00:00
|
|
|
inherit image;
|
2015-04-10 05:06:52 +01:00
|
|
|
sshPublicKey = snakeOilPublicKey;
|
|
|
|
|
2020-04-18 21:51:19 +01:00
|
|
|
# ### https://nixos.org/channels/nixos-unstable nixos
|
2015-04-10 05:06:52 +01:00
|
|
|
userData = ''
|
2017-02-27 16:51:36 +00:00
|
|
|
{ pkgs, ... }:
|
|
|
|
|
2015-04-10 05:06:52 +01:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
<nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
|
|
|
|
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
|
2016-03-30 20:48:12 +01:00
|
|
|
<nixpkgs/nixos/modules/profiles/qemu-guest.nix>
|
2015-04-10 05:06:52 +01:00
|
|
|
];
|
|
|
|
environment.etc.testFile = {
|
|
|
|
text = "whoa";
|
|
|
|
};
|
2017-02-27 16:51:36 +00:00
|
|
|
|
2020-01-12 17:40:44 +00:00
|
|
|
networking.hostName = "ec2-test-vm"; # required by services.httpd
|
|
|
|
|
2017-02-27 16:51:36 +00:00
|
|
|
services.httpd = {
|
|
|
|
enable = true;
|
|
|
|
adminAddr = "test@example.org";
|
2020-01-12 17:40:44 +00:00
|
|
|
virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
|
2017-02-27 16:51:36 +00:00
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
2015-04-10 05:06:52 +01:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
script = ''
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.start()
|
2020-01-12 17:40:44 +00:00
|
|
|
|
|
|
|
# amazon-init must succeed. if it fails, make the test fail
|
2020-02-02 08:48:11 +00:00
|
|
|
# immediately instead of timing out in wait_for_file.
|
|
|
|
machine.wait_for_unit("amazon-init.service")
|
2020-01-12 17:40:44 +00:00
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.wait_for_file("/etc/testFile")
|
|
|
|
assert "whoa" in machine.succeed("cat /etc/testFile")
|
2017-02-27 16:51:36 +00:00
|
|
|
|
2020-02-02 08:48:11 +00:00
|
|
|
machine.wait_for_unit("httpd.service")
|
|
|
|
assert "Valgrind" in machine.succeed("curl http://localhost")
|
2015-04-10 05:06:52 +01:00
|
|
|
'';
|
|
|
|
};
|
2015-05-27 07:12:26 +01:00
|
|
|
}
|