1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-01 01:51:24 +00:00
nixpkgs/nixos/tests/ec2.nix

150 lines
4.8 KiB
Nix
Raw Normal View History

{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; }
}:
2015-05-27 07:12:26 +01:00
with import ../lib/testing.nix { inherit system pkgs; };
2015-05-27 07:12:26 +01:00
with pkgs.lib;
with import common/ec2.nix { inherit makeTest pkgs; };
2015-05-27 07:12:26 +01:00
let
imageCfg =
2015-05-27 07:12:26 +01:00
(import ../lib/eval-config.nix {
inherit system;
modules = [
2015-09-28 12:42:24 +01:00
../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
'';
2016-03-30 21:21:56 +01:00
# Needed by nixos-rebuild due to the lack of network
# access. Determined by trial and error.
2016-03-30 21:21:56 +01:00
system.extraDependencies =
with pkgs; (
[
# Needed for a nixos-rebuild.
busybox
stdenv
stdenvNoCC
mkinitcpio-nfs-utils
unionfs-fuse
cloud-utils
desktop-file-utils
texinfo
libxslt.bin
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
]
);
2015-09-28 12:42:24 +01:00
}
2015-05-27 07:12:26 +01:00
];
}).config;
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
2015-05-27 07:12:26 +01:00
sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
snakeOilPublicKey = sshKeys.snakeOilPublicKey;
2015-05-27 07:12:26 +01:00
in {
boot-ec2-nixops = makeEc2Test {
2015-05-27 07:12:26 +01:00
name = "nixops-userdata";
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 = ''
$machine->start;
$machine->waitForFile("/etc/ec2-metadata/user-data");
2015-05-27 07:12:26 +01:00
$machine->waitForUnit("sshd.service");
$machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
2015-05-27 07:12:26 +01:00
# 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");
2015-09-28 12:42:24 +01:00
$machine->succeed("echo '${snakeOilPrivateKey}' > ~/.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
$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");
# Test whether the root disk was resized.
my $blocks = $machine->succeed("stat -c %b -f /");
my $bsize = $machine->succeed("stat -c %S -f /");
my $size = $blocks * $bsize;
die "wrong free space $size" if $size < 9.7 * 1024 * 1024 * 1024 || $size > 10 * 1024 * 1024 * 1024;
# Just to make sure resizing is idempotent.
2015-05-27 07:12:26 +01:00
$machine->shutdown;
$machine->start;
$machine->waitForFile("/etc/ec2-metadata/user-data");
2015-05-27 07:12:26 +01:00
'';
};
boot-ec2-config = makeEc2Test {
name = "config-userdata";
inherit image;
sshPublicKey = snakeOilPublicKey;
# ### https://nixos.org/channels/nixos-unstable nixos
userData = ''
{ pkgs, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
<nixpkgs/nixos/modules/profiles/qemu-guest.nix>
];
environment.etc.testFile = {
text = "whoa";
};
networking.hostName = "ec2-test-vm"; # required by services.httpd
services.httpd = {
enable = true;
adminAddr = "test@example.org";
virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
};
networking.firewall.allowedTCPPorts = [ 80 ];
}
'';
script = ''
$machine->start;
# amazon-init must succeed. if it fails, make the test fail
# immediately instead of timing out in waitForFile.
$machine->waitForUnit('amazon-init.service');
$machine->waitForFile("/etc/testFile");
$machine->succeed("cat /etc/testFile | grep -q 'whoa'");
$machine->waitForUnit("httpd.service");
$machine->succeed("curl http://localhost | grep Valgrind");
'';
};
2015-05-27 07:12:26 +01:00
}