nixos/tests/ec2: return to passing state

Updates required:

- Use vpc image format (new default, supported by Amazon)
- Pass full image filename to makeEc2Test
- Increase memory allocation for nixos-rebuild
- Set a networking.hostName for services.httpd
- Add appropriate escaping in literal userdata

While I'm here, try to make it fail fast.
This commit is contained in:
Andrew Childs 2020-01-13 02:40:44 +09:00
parent c2e5ff3fe8
commit e4fa8192da
3 changed files with 34 additions and 15 deletions

View file

@ -25,7 +25,7 @@ with pkgs.lib;
my $imageDir = ($ENV{'TMPDIR'} // "/tmp") . "/vm-state-machine"; my $imageDir = ($ENV{'TMPDIR'} // "/tmp") . "/vm-state-machine";
mkdir $imageDir, 0700; mkdir $imageDir, 0700;
my $diskImage = "$imageDir/machine.qcow2"; my $diskImage = "$imageDir/machine.qcow2";
system("qemu-img create -f qcow2 -o backing_file=${image}/nixos.qcow2 $diskImage") == 0 or die; system("qemu-img create -f qcow2 -o backing_file=${image} $diskImage") == 0 or die;
system("qemu-img resize $diskImage 10G") == 0 or die; system("qemu-img resize $diskImage 10G") == 0 or die;
# Note: we use net=169.0.0.0/8 rather than # Note: we use net=169.0.0.0/8 rather than
@ -35,7 +35,7 @@ with pkgs.lib;
# again when it deletes link-local addresses.) Ideally we'd # again when it deletes link-local addresses.) Ideally we'd
# turn off the DHCP server, but qemu does not have an option # turn off the DHCP server, but qemu does not have an option
# to do that. # to do that.
my $startCommand = "qemu-kvm -m 768"; my $startCommand = "qemu-kvm -m 1024";
$startCommand .= " -device virtio-net-pci,netdev=vlan0"; $startCommand .= " -device virtio-net-pci,netdev=vlan0";
$startCommand .= " -netdev 'user,id=vlan0,net=169.0.0.0/8,guestfwd=tcp:169.254.169.254:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${metaData}'"; $startCommand .= " -netdev 'user,id=vlan0,net=169.0.0.0/8,guestfwd=tcp:169.254.169.254:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${metaData}'";
$startCommand .= " -drive file=$diskImage,if=virtio,werror=report"; $startCommand .= " -drive file=$diskImage,if=virtio,werror=report";

View file

@ -9,7 +9,7 @@ with pkgs.lib;
with import common/ec2.nix { inherit makeTest pkgs; }; with import common/ec2.nix { inherit makeTest pkgs; };
let let
image = imageCfg =
(import ../lib/eval-config.nix { (import ../lib/eval-config.nix {
inherit system; inherit system;
modules = [ modules = [
@ -26,20 +26,32 @@ let
''; '';
# Needed by nixos-rebuild due to the lack of network # Needed by nixos-rebuild due to the lack of network
# access. Mostly copied from # access. Determined by trial and error.
# modules/profiles/installation-device.nix.
system.extraDependencies = system.extraDependencies =
with pkgs; [ with pkgs; (
stdenv busybox perlPackages.ArchiveCpio unionfs-fuse mkinitcpio-nfs-utils [
# 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 # These are used in the configure-from-userdata tests
# directly by the configuration we set, and libxslt.bin is used indirectly as a build dependency # for EC2. Httpd and valgrind are requested by the
# of the derivation for dbus configuration files. # configuration.
apacheHttpd valgrind.doc libxslt.bin apacheHttpd apacheHttpd.doc apacheHttpd.man valgrind.doc
]; ]
);
} }
]; ];
}).config.system.build.amazonImage; }).config;
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
sshKeys = import ./ssh-keys.nix pkgs; sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text; snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
@ -110,16 +122,23 @@ in {
text = "whoa"; text = "whoa";
}; };
networking.hostName = "ec2-test-vm"; # required by services.httpd
services.httpd = { services.httpd = {
enable = true; enable = true;
adminAddr = "test@example.org"; adminAddr = "test@example.org";
virtualHosts.localhost.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html"; virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
}; };
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 ];
} }
''; '';
script = '' script = ''
$machine->start; $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->waitForFile("/etc/testFile");
$machine->succeed("cat /etc/testFile | grep -q 'whoa'"); $machine->succeed("cat /etc/testFile | grep -q 'whoa'");

View file

@ -17,7 +17,7 @@ let
../modules/testing/test-instrumentation.nix ../modules/testing/test-instrumentation.nix
../modules/profiles/qemu-guest.nix ../modules/profiles/qemu-guest.nix
]; ];
}).config.system.build.openstackImage; }).config.system.build.openstackImage + "/nixos.qcow2";
sshKeys = import ./ssh-keys.nix pkgs; sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text; snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;