* 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;}) minimal_install_archive = {system ? "i686-linux"}: (iso_minimal {inherit system;})
.config.system.build.minimalInstallArchive; .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 = tests =
{ services ? ../services }: { services ? ../services }:
let let
@ -120,27 +124,14 @@ let
}; };
in { in {
firefox = t.firefox.test; firefox = t.firefox.test;
installer = t.installer.test; installer.simple = t.installer.simple.test;
installer.separateBoot = t.installer.separateBoot.test;
kde4 = t.kde4.test; kde4 = t.kde4.test;
quake3 = t.quake3.test; quake3 = t.quake3.test;
subversion = t.subversion.report; subversion = t.subversion.report;
trac = t.trac.test; 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/build-vms.nix { inherit nixpkgs services system; }) //
(import ../lib/testing.nix { inherit nixpkgs services system; }); (import ../lib/testing.nix { inherit nixpkgs services system; });
apply = testFun: in with testLib; let
with testLib;
let call = f: f { inherit pkgs nixpkgs system testLib; };
t = testFun { inherit pkgs nixpkgs system testLib; };
in t // rec { apply = testFun: complete (call testFun);
complete = t: t // rec {
nodes = nodes =
if t ? nodes then t.nodes else if t ? nodes then t.nodes else
if t ? machine then { machine = t.machine; } if t ? machine then { machine = t.machine; }
@ -27,7 +29,7 @@ in
{ {
firefox = apply (import ./firefox.nix); 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); kde4 = apply (import ./kde4.nix);
quake3 = apply (import ./quake3.nix); quake3 = apply (import ./quake3.nix);
subversion = apply (import ./subversion.nix); subversion = apply (import ./subversion.nix);

View File

@ -1,6 +1,6 @@
{ pkgs, nixpkgs, system, ... }: { pkgs, nixpkgs, system, ... }:
rec { let
# Build the ISO. This is the regular installation CD but with test # Build the ISO. This is the regular installation CD but with test
# instrumentation. # instrumentation.
@ -26,7 +26,7 @@ rec {
}).config.system.build.isoImage; }).config.system.build.isoImage;
# The configuration to install. # The configuration to install.
config = pkgs.writeText "configuration.nix" config = { fileSystems }: pkgs.writeText "configuration.nix"
'' ''
{ config, pkgs, modulesPath, ... }: { config, pkgs, modulesPath, ... }:
@ -40,9 +40,7 @@ rec {
boot.initrd.kernelModules = [ "ext3" ]; boot.initrd.kernelModules = [ "ext3" ];
fileSystems = fileSystems =
[ { mountPoint = "/"; [ ${fileSystems}
device = "/dev/disk/by-label/nixos";
}
]; ];
swapDevices = 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 # The test script boots the CD, installs NixOS on an empty hard
# disk, and then reboot from the hard disk. # disk, and then reboot from the hard disk.
testScript = testScriptFun = { createPartitions, fileSystems }:
'' ''
createDisk("harddisk", 4 * 1024); createDisk("harddisk", 4 * 1024);
@ -76,6 +88,67 @@ rec {
or die "bad `hello' output"; or die "bad `hello' output";
# Partition the disk. # 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( $machine->mustSucceed(
"parted /dev/vda mklabel msdos", "parted /dev/vda mklabel msdos",
"parted /dev/vda -- mkpart primary linux-swap 1M 1024M", "parted /dev/vda -- mkpart primary linux-swap 1M 1024M",
@ -87,41 +160,30 @@ rec {
"mkfs.ext3 -L nixos /dev/vda2", "mkfs.ext3 -L nixos /dev/vda2",
"mount LABEL=nixos /mnt", "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;
};
} }