nixos/tests/virtualbox: Split up subtests

Now subtests are separate derivations, because the individual tests do
not depend on state from previous test runs.

This has the advantage that it's easier to run individiual tests and
it's also easier to pinpoint individual tests that randomly fail.

I ran all of these tests locally and they still succeed.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig 5bab623f 11327ac8

Changed files
+118 -109
nixos
+6 -1
nixos/release.nix
···
tests.simple = callTest tests/simple.nix {};
tests.tomcat = callTest tests/tomcat.nix {};
tests.udisks2 = callTest tests/udisks2.nix {};
-
tests.virtualbox = hydraJob (import tests/virtualbox.nix { system = "x86_64-linux"; });
+
tests.virtualbox = let
+
testsOnly = filterAttrs (const (t: t ? test));
+
vboxTests = testsOnly (import tests/virtualbox.nix {
+
system = "x86_64-linux";
+
});
+
in mapAttrs (const (t: hydraJob t.test)) vboxTests;
tests.xfce = callTest tests/xfce.nix {};
tests.bootBiosCdrom = forAllSystems (system: hydraJob (import tests/boot.nix { inherit system; }).bootBiosCdrom);
tests.bootBiosUsb = forAllSystems (system: hydraJob (import tests/boot.nix { inherit system; }).bootBiosUsb);
+112 -108
nixos/tests/virtualbox.nix
···
-
{ debug ? false, ... } @ args:
+
{ system ? builtins.currentSystem, debug ? false }:
-
import ./make-test.nix ({ pkgs, ... }: with pkgs.lib; let
+
with import ../lib/testing.nix { inherit system; };
+
with pkgs.lib;
+
let
testVMConfig = vmName: attrs: { config, pkgs, ... }: let
guestAdditions = pkgs.linuxPackages.virtualboxGuestAdditions;
···
test2.vmScript = dhcpScript;
};
-
in {
-
name = "virtualbox";
-
meta = with pkgs.stdenv.lib.maintainers; {
-
maintainers = [ aszlig wkennington ];
-
};
+
mkVBoxTest = name: testScript: makeTest {
+
name = "virtualbox-${name}";
-
machine = { pkgs, lib, config, ... }: {
-
imports = let
-
mkVMConf = name: val: val.machine // { key = "${name}-config"; };
-
vmConfigs = mapAttrsToList mkVMConf vboxVMs;
-
in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs;
-
virtualisation.memorySize = 2048;
-
virtualisation.virtualbox.host.enable = true;
-
users.extraUsers.alice.extraGroups = let
-
inherit (config.virtualisation.virtualbox.host) enableHardening;
-
in lib.mkIf enableHardening (lib.singleton "vboxusers");
-
};
+
machine = { lib, config, ... }: {
+
imports = let
+
mkVMConf = name: val: val.machine // { key = "${name}-config"; };
+
vmConfigs = mapAttrsToList mkVMConf vboxVMs;
+
in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs;
+
virtualisation.memorySize = 2048;
+
virtualisation.virtualbox.host.enable = true;
+
users.extraUsers.alice.extraGroups = let
+
inherit (config.virtualisation.virtualbox.host) enableHardening;
+
in lib.mkIf enableHardening (lib.singleton "vboxusers");
+
};
-
testScript = ''
-
sub ru ($) {
-
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
-
return "su - alice -c '$esc'";
-
}
+
testScript = ''
+
sub ru ($) {
+
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
+
return "su - alice -c '$esc'";
+
}
+
+
sub vbm {
+
$machine->succeed(ru("VBoxManage ".$_[0]));
+
};
-
sub vbm {
-
$machine->succeed(ru("VBoxManage ".$_[0]));
-
};
+
sub removeUUIDs {
+
return join("\n", grep { $_ !~ /^UUID:/ } split(/\n/, $_[0]))."\n";
+
}
-
${concatStrings (mapAttrsToList (_: getAttr "testSubs") vboxVMs)}
+
${concatStrings (mapAttrsToList (_: getAttr "testSubs") vboxVMs)}
-
$machine->waitForX;
+
$machine->waitForX;
-
${mkLog "$HOME/.config/VirtualBox/VBoxSVC.log" "HOST-SVC"}
+
${mkLog "$HOME/.config/VirtualBox/VBoxSVC.log" "HOST-SVC"}
-
createVM_simple;
+
${testScript}
+
'';
-
subtest "simple-gui", sub {
-
$machine->succeed(ru "VirtualBox &");
-
$machine->waitForWindow(qr/Oracle VM VirtualBox Manager/);
-
$machine->sleep(5);
-
$machine->screenshot("gui_manager_started");
-
$machine->sendKeys("ret");
-
$machine->screenshot("gui_manager_sent_startup");
-
waitForStartup_simple (sub {
-
$machine->sendKeys("ret");
-
});
-
$machine->screenshot("gui_started");
-
waitForVMBoot_simple;
-
$machine->screenshot("gui_booted");
-
shutdownVM_simple;
-
$machine->sleep(5);
-
$machine->screenshot("gui_stopped");
-
$machine->sendKeys("ctrl-q");
-
$machine->sleep(5);
-
$machine->screenshot("gui_manager_stopped");
+
meta = with pkgs.stdenv.lib.maintainers; {
+
maintainers = [ aszlig wkennington ];
};
+
};
-
cleanup_simple;
+
in mapAttrs mkVBoxTest {
+
simple-gui = ''
+
createVM_simple;
+
$machine->succeed(ru "VirtualBox &");
+
$machine->waitForWindow(qr/Oracle VM VirtualBox Manager/);
+
$machine->sleep(5);
+
$machine->screenshot("gui_manager_started");
+
$machine->sendKeys("ret");
+
$machine->screenshot("gui_manager_sent_startup");
+
waitForStartup_simple (sub {
+
$machine->sendKeys("ret");
+
});
+
$machine->screenshot("gui_started");
+
waitForVMBoot_simple;
+
$machine->screenshot("gui_booted");
+
shutdownVM_simple;
+
$machine->sleep(5);
+
$machine->screenshot("gui_stopped");
+
$machine->sendKeys("ctrl-q");
+
$machine->sleep(5);
+
$machine->screenshot("gui_manager_stopped");
+
'';
-
subtest "simple-cli", sub {
-
vbm("startvm simple");
-
waitForStartup_simple;
-
$machine->screenshot("cli_started");
-
waitForVMBoot_simple;
-
$machine->screenshot("cli_booted");
-
shutdownVM_simple;
-
};
+
simple-cli = ''
+
createVM_simple;
+
vbm("startvm simple");
+
waitForStartup_simple;
+
$machine->screenshot("cli_started");
+
waitForVMBoot_simple;
+
$machine->screenshot("cli_booted");
-
subtest "privilege-escalation", sub {
+
$machine->nest("Checking for privilege escalation", sub {
$machine->fail("test -e '/root/VirtualBox VMs'");
$machine->fail("test -e '/root/.config/VirtualBox'");
$machine->succeed("test -e '/home/alice/VirtualBox VMs'");
-
};
+
});
-
destroyVM_simple;
+
shutdownVM_simple;
+
'';
-
sub removeUUIDs {
-
return join("\n", grep { $_ !~ /^UUID:/ } split(/\n/, $_[0]))."\n";
-
}
+
host-usb-permissions = ''
+
my $userUSB = removeUUIDs vbm("list usbhost");
+
print STDERR $userUSB;
+
my $rootUSB = removeUUIDs $machine->succeed("VBoxManage list usbhost");
+
print STDERR $rootUSB;
-
subtest "host-usb-permissions", sub {
-
my $userUSB = removeUUIDs vbm("list usbhost");
-
print STDERR $userUSB;
-
my $rootUSB = removeUUIDs $machine->succeed("VBoxManage list usbhost");
-
print STDERR $rootUSB;
+
die "USB host devices differ for root and normal user"
+
if $userUSB ne $rootUSB;
+
die "No USB host devices found" if $userUSB =~ /<none>/;
+
'';
-
die "USB host devices differ for root and normal user"
-
if $userUSB ne $rootUSB;
-
die "No USB host devices found" if $userUSB =~ /<none>/;
-
};
+
systemd-detect-virt = ''
+
createVM_detectvirt;
+
vbm("startvm detectvirt");
+
waitForStartup_detectvirt;
+
waitForVMBoot_detectvirt;
+
shutdownVM_detectvirt;
+
my $result = $machine->succeed("cat '$detectvirt_sharepath/result'");
+
chomp $result;
+
destroyVM_detectvirt;
+
die "systemd-detect-virt returned \"$result\" instead of \"oracle\""
+
if $result ne "oracle";
+
'';
-
subtest "systemd-detect-virt", sub {
-
createVM_detectvirt;
-
vbm("startvm detectvirt");
-
waitForStartup_detectvirt;
-
waitForVMBoot_detectvirt;
-
shutdownVM_detectvirt;
-
my $result = $machine->succeed("cat '$detectvirt_sharepath/result'");
-
chomp $result;
-
destroyVM_detectvirt;
-
die "systemd-detect-virt returned \"$result\" instead of \"oracle\""
-
if $result ne "oracle";
-
};
+
net-hostonlyif = ''
+
createVM_test1;
+
createVM_test2;
-
subtest "net-hostonlyif", sub {
-
createVM_test1;
-
createVM_test2;
+
vbm("startvm test1");
+
waitForStartup_test1;
+
waitForVMBoot_test1;
-
vbm("startvm test1");
-
waitForStartup_test1;
-
waitForVMBoot_test1;
+
vbm("startvm test2");
+
waitForStartup_test2;
+
waitForVMBoot_test2;
-
vbm("startvm test2");
-
waitForStartup_test2;
-
waitForVMBoot_test2;
+
$machine->screenshot("net_booted");
-
$machine->screenshot("net_booted");
+
my $test1IP = waitForIP_test1 1;
+
my $test2IP = waitForIP_test2 1;
-
my $test1IP = waitForIP_test1 1;
-
my $test2IP = waitForIP_test2 1;
+
$machine->succeed("echo '$test2IP' | netcat -c '$test1IP' 1234");
+
$machine->succeed("echo '$test1IP' | netcat -c '$test2IP' 1234");
-
$machine->succeed("echo '$test2IP' | netcat -c '$test1IP' 1234");
-
$machine->succeed("echo '$test1IP' | netcat -c '$test2IP' 1234");
-
-
$machine->waitUntilSucceeds("netcat -c '$test1IP' 5678 >&2");
-
$machine->waitUntilSucceeds("netcat -c '$test2IP' 5678 >&2");
+
$machine->waitUntilSucceeds("netcat -c '$test1IP' 5678 >&2");
+
$machine->waitUntilSucceeds("netcat -c '$test2IP' 5678 >&2");
-
shutdownVM_test1;
-
shutdownVM_test2;
+
shutdownVM_test1;
+
shutdownVM_test2;
-
destroyVM_test1;
-
destroyVM_test2;
-
};
+
destroyVM_test1;
+
destroyVM_test2;
'';
-
}) args
+
}