0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

Fix the EC2 test

We now generate a qcow2 image to prevent hitting Hydra's output size
limit. Also updated /root/user-data -> /etc/ec2-metadata/user-data.

http://hydra.nixos.org/build/33843133
This commit is contained in:
Eelco Dolstra 2016-03-30 21:48:12 +02:00
parent 184b7ba3c6
commit 0d3738cdcc
4 changed files with 13 additions and 11 deletions

View file

@ -23,6 +23,8 @@
postVM ? "" postVM ? ""
, name ? "nixos-disk-image" , name ? "nixos-disk-image"
, format ? "raw"
}: }:
with lib; with lib;
@ -32,8 +34,8 @@ pkgs.vmTools.runInLinuxVM (
{ preVM = { preVM =
'' ''
mkdir $out mkdir $out
diskImage=$out/nixos.img diskImage=$out/nixos.${if format == "qcow2" then "qcow2" else "img"}
${pkgs.vmTools.qemu}/bin/qemu-img create -f raw $diskImage "${toString diskSize}M" ${pkgs.vmTools.qemu}/bin/qemu-img create -f ${format} $diskImage "${toString diskSize}M"
mv closure xchg/ mv closure xchg/
''; '';
buildInputs = [ pkgs.utillinux pkgs.perl pkgs.e2fsprogs pkgs.parted ]; buildInputs = [ pkgs.utillinux pkgs.perl pkgs.e2fsprogs pkgs.parted ];

View file

@ -10,9 +10,11 @@ with lib;
]; ];
system.build.amazonImage = import ../../../lib/make-disk-image.nix { system.build.amazonImage = import ../../../lib/make-disk-image.nix {
inherit pkgs lib config; inherit lib config;
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
partitioned = config.ec2.hvm; partitioned = config.ec2.hvm;
diskSize = if config.ec2.hvm then 2048 else 8192; diskSize = if config.ec2.hvm then 2048 else 8192;
format = "qcow2";
configFile = pkgs.writeText "configuration.nix" configFile = pkgs.writeText "configuration.nix"
'' ''
{ {

View file

@ -65,8 +65,7 @@ let cfg = config.ec2; in
fi fi
if ! [ -e "$metaDir/user-data" ]; then if ! [ -e "$metaDir/user-data" ]; then
wget -q -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data wget -q -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data && chmod 600 "$metaDir/user-data"
chmod 600 "$metaDir/user-data"
fi fi
if ! [ -e "$metaDir/hostname" ]; then if ! [ -e "$metaDir/hostname" ]; then

View file

@ -11,7 +11,6 @@ let
modules = [ modules = [
../maintainers/scripts/ec2/amazon-image.nix ../maintainers/scripts/ec2/amazon-image.nix
../modules/testing/test-instrumentation.nix ../modules/testing/test-instrumentation.nix
../modules/profiles/minimal.nix
../modules/profiles/qemu-guest.nix ../modules/profiles/qemu-guest.nix
{ ec2.hvm = true; { ec2.hvm = true;
@ -30,9 +29,8 @@ let
metaData = pkgs.stdenv.mkDerivation { metaData = pkgs.stdenv.mkDerivation {
name = "metadata"; name = "metadata";
buildCommand = '' buildCommand = ''
mkdir -p $out/2011-01-01
ln -s ${pkgs.writeText "userData" userData} $out/2011-01-01/user-data
mkdir -p $out/1.0/meta-data mkdir -p $out/1.0/meta-data
ln -s ${pkgs.writeText "userData" userData} $out/1.0/user-data
echo "${hostname}" > $out/1.0/meta-data/hostname echo "${hostname}" > $out/1.0/meta-data/hostname
echo "(unknown)" > $out/1.0/meta-data/ami-manifest-path echo "(unknown)" > $out/1.0/meta-data/ami-manifest-path
'' + optionalString (sshPublicKey != null) '' '' + optionalString (sshPublicKey != null) ''
@ -48,7 +46,7 @@ let
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.img $diskImage") == 0 or die; system("qemu-img create -f qcow2 -o backing_file=${image}/nixos.qcow2 $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
@ -91,7 +89,7 @@ in {
''; '';
script = '' script = ''
$machine->start; $machine->start;
$machine->waitForFile("/root/user-data"); $machine->waitForFile("/etc/ec2-metadata/user-data");
$machine->waitForUnit("sshd.service"); $machine->waitForUnit("sshd.service");
$machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path"); $machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
@ -121,7 +119,7 @@ in {
# Just to make sure resizing is idempotent. # Just to make sure resizing is idempotent.
$machine->shutdown; $machine->shutdown;
$machine->start; $machine->start;
$machine->waitForFile("/root/user-data"); $machine->waitForFile("/etc/ec2-metadata/user-data");
''; '';
}; };
@ -135,6 +133,7 @@ in {
imports = [ imports = [
<nixpkgs/nixos/modules/virtualisation/amazon-image.nix> <nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
<nixpkgs/nixos/modules/testing/test-instrumentation.nix> <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
<nixpkgs/nixos/modules/profiles/qemu-guest.nix>
]; ];
environment.etc.testFile = { environment.etc.testFile = {
text = "whoa"; text = "whoa";