* Parameterize the installer test to support different partitioning

schemes.
* Added a test for installing NixOS with a separate /boot partition.

svn path=/nixos/trunk/; revision=19283
This commit is contained in:
Eelco Dolstra 2010-01-07 13:19:38 +00:00
parent fdc63c54e4
commit a776afb085
3 changed files with 102 additions and 47 deletions

View File

@ -111,6 +111,10 @@ let
minimal_install_archive = {system ? "i686-linux"}: (iso_minimal {inherit system;})
.config.system.build.minimalInstallArchive;
# the archive installer can't be tested without chroot which requires being root
# options: run in kvm or uml ?
# TODO
tests =
{ services ? ../services }:
let
@ -120,27 +124,14 @@ let
};
in {
firefox = t.firefox.test;
installer = t.installer.test;
installer.simple = t.installer.simple.test;
installer.separateBoot = t.installer.separateBoot.test;
kde4 = t.kde4.test;
quake3 = t.quake3.test;
subversion = t.subversion.report;
trac = t.trac.test;
};
/*
### tests about installing NixOS
# installs NixOs in a qemu_kvm instance using a tweaked iso.
tests.nixosInstallation =
(import ./tests/test-nixos-install-from-cd/test.nix {
inherit nixpkgs;
}).test;
*/
# the archive installer can't be tested without chroot which requires being root
# options: run in kvm or uml ?
# TODO
};

View File

@ -9,11 +9,13 @@ let
(import ../lib/build-vms.nix { inherit nixpkgs services system; }) //
(import ../lib/testing.nix { inherit nixpkgs services system; });
apply = testFun:
with testLib;
let
t = testFun { inherit pkgs nixpkgs system testLib; };
in t // rec {
in with testLib; let
call = f: f { inherit pkgs nixpkgs system testLib; };
apply = testFun: complete (call testFun);
complete = t: t // rec {
nodes =
if t ? nodes then t.nodes else
if t ? machine then { machine = t.machine; }
@ -27,7 +29,7 @@ in
{
firefox = apply (import ./firefox.nix);
installer = apply (import ./installer.nix);
installer = pkgs.lib.mapAttrs (name: complete) (call (import ./installer.nix));
kde4 = apply (import ./kde4.nix);
quake3 = apply (import ./quake3.nix);
subversion = apply (import ./subversion.nix);

View File

@ -1,6 +1,6 @@
{ pkgs, nixpkgs, system, ... }:
rec {
let
# Build the ISO. This is the regular installation CD but with test
# instrumentation.
@ -26,7 +26,7 @@ rec {
}).config.system.build.isoImage;
# The configuration to install.
config = pkgs.writeText "configuration.nix"
config = { fileSystems }: pkgs.writeText "configuration.nix"
''
{ config, pkgs, modulesPath, ... }:
@ -40,9 +40,7 @@ rec {
boot.initrd.kernelModules = [ "ext3" ];
fileSystems =
[ { mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
[ ${fileSystems}
];
swapDevices =
@ -50,9 +48,23 @@ rec {
}
'';
rootFS =
''
{ mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
'';
bootFS =
''
{ mountPoint = "/boot";
device = "/dev/disk/by-label/boot";
}
'';
# The test script boots the CD, installs NixOS on an empty hard
# disk, and then reboot from the hard disk.
testScript =
testScriptFun = { createPartitions, fileSystems }:
''
createDisk("harddisk", 4 * 1024);
@ -76,6 +88,67 @@ rec {
or die "bad `hello' output";
# Partition the disk.
${createPartitions}
# Create the NixOS configuration.
$machine->mustSucceed(
"mkdir -p /mnt/etc/nixos",
"nixos-hardware-scan > /mnt/etc/nixos/hardware.nix",
);
my $cfg = $machine->mustSucceed("cat /mnt/etc/nixos/hardware.nix");
print STDERR "Result of the hardware scan:\n$cfg\n";
$machine->copyFileFromHost(
"${ config { inherit fileSystems; } }",
"/mnt/etc/nixos/configuration.nix");
# Perform the installation.
$machine->mustSucceed("nixos-install >&2");
$machine->mustSucceed("cat /boot/grub/grub.cfg >&2");
$machine->shutdown;
# Now see if we can boot the installation.
my $machine = Machine->new({ hda => "harddisk" });
$machine->mustSucceed("echo hello");
# Did /boot get mounted, if appropriate?
$machine->mustSucceed("initctl start filesystems");
$machine->mustSucceed("test -e /boot/grub/grub.cfg");
$machine->mustSucceed("nix-env -i coreutils >&2");
$machine->mustSucceed("type -tP ls") =~ /profiles/
or die "nix-env failed";
$machine->mustSucceed("nixos-rebuild switch >&2");
$machine->mustSucceed("cat /boot/grub/grub.cfg >&2");
$machine->shutdown;
# And just to be sure, check that the machine still boots after
# "nixos-rebuild switch".
my $machine = Machine->new({ hda => "harddisk" });
$machine->mustSucceed("echo hello");
$machine->shutdown;
'';
makeTest = { createPartitions, fileSystems }:
{ inherit iso;
testScript = testScriptFun { inherit createPartitions fileSystems; };
};
in {
# The (almost) simplest partitioning scheme: a swap partition and
# one big filesystem partition.
simple = makeTest
{ createPartitions =
''
$machine->mustSucceed(
"parted /dev/vda mklabel msdos",
"parted /dev/vda -- mkpart primary linux-swap 1M 1024M",
@ -87,41 +160,30 @@ rec {
"mkfs.ext3 -L nixos /dev/vda2",
"mount LABEL=nixos /mnt",
);
# Create the NixOS configuration.
$machine->mustSucceed(
"mkdir -p /mnt/etc/nixos",
"nixos-hardware-scan > /mnt/etc/nixos/hardware.nix",
);
my $cfg = $machine->mustSucceed("cat /mnt/etc/nixos/hardware.nix");
print STDERR "Result of the hardware scan:\n$cfg\n";
$machine->copyFileFromHost("${config}", "/mnt/etc/nixos/configuration.nix");
# Perform the installation.
$machine->mustSucceed("nixos-install >&2");
$machine->shutdown;
# Now see if we can boot the installation.
my $machine = Machine->new({ hda => "harddisk" });
$machine->mustSucceed("echo hello");
$machine->mustSucceed("nix-env -i coreutils >&2");
$machine->mustSucceed("type -tP ls") =~ /profiles/
or die "nix-env failed";
$machine->mustSucceed("nixos-rebuild switch >&2");
$machine->shutdown;
# And just to be sure, check that the machine still boots after
# "nixos-rebuild switch".
my $machine = Machine->new({ hda => "harddisk" });
$machine->mustSucceed("echo hello");
$machine->shutdown;
'';
fileSystems = rootFS;
};
# Same as the previous, but now with a separate /boot partition.
separateBoot = makeTest
{ createPartitions =
''
$machine->mustSucceed(
"parted /dev/vda mklabel msdos",
"parted /dev/vda -- mkpart primary ext2 1M 50MB", # /boot
"parted /dev/vda -- mkpart primary linux-swap 50MB 1024M",
"parted /dev/vda -- mkpart primary ext2 1024M -1s", # /
"udevadm settle",
"mkswap /dev/vda2 -L swap",
"swapon -L swap",
"mkfs.ext3 -L nixos /dev/vda3",
"mount LABEL=nixos /mnt",
"mkfs.ext3 -L boot /dev/vda1",
"mkdir /mnt/boot",
"mount LABEL=boot /mnt/boot",
);
'';
fileSystems = rootFS + bootFS;
};
}