2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; },
|
|
|
|
debug ? false,
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
enableUnfree ? false,
|
|
|
|
# Nested KVM virtualization (https://www.linux-kvm.org/page/Nested_Guests)
|
|
|
|
# requires a modprobe flag on the build machine: (kvm-amd for AMD CPUs)
|
|
|
|
# boot.extraModprobeConfig = "options kvm-intel nested=Y";
|
|
|
|
# Without this VirtualBox will use SW virtualization and will only be able
|
|
|
|
# to run 32-bit guests.
|
|
|
|
useKvmNestedVirt ? false,
|
|
|
|
# Whether to run 64-bit guests instead of 32-bit. Requires nested KVM.
|
2019-09-03 20:59:50 +01:00
|
|
|
use64bitGuest ? false
|
2018-11-11 08:41:11 +00:00
|
|
|
}:
|
2014-12-13 10:15:48 +00:00
|
|
|
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
assert use64bitGuest -> useKvmNestedVirt;
|
|
|
|
|
2018-11-11 08:41:11 +00:00
|
|
|
with import ../lib/testing.nix { inherit system pkgs; };
|
2016-02-29 18:15:36 +00:00
|
|
|
with pkgs.lib;
|
2014-12-18 12:43:18 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
let
|
2016-08-23 12:05:14 +01:00
|
|
|
testVMConfig = vmName: attrs: { config, pkgs, lib, ... }: let
|
2015-09-17 10:02:43 +01:00
|
|
|
guestAdditions = pkgs.linuxPackages.virtualboxGuestAdditions;
|
|
|
|
|
|
|
|
miniInit = ''
|
|
|
|
#!${pkgs.stdenv.shell} -xe
|
2016-08-23 12:05:14 +01:00
|
|
|
export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.utillinux ]}"
|
2015-09-17 10:02:43 +01:00
|
|
|
|
2016-10-24 11:43:42 +01:00
|
|
|
mkdir -p /run/dbus
|
2015-09-17 10:02:43 +01:00
|
|
|
cat > /etc/passwd <<EOF
|
|
|
|
root:x:0:0::/root:/bin/false
|
2016-10-24 11:43:42 +01:00
|
|
|
messagebus:x:1:1::/run/dbus:/bin/false
|
2015-09-17 10:02:43 +01:00
|
|
|
EOF
|
|
|
|
cat > /etc/group <<EOF
|
|
|
|
root:x:0:
|
|
|
|
messagebus:x:1:
|
|
|
|
EOF
|
2016-05-26 15:45:43 +01:00
|
|
|
|
|
|
|
"${pkgs.dbus.daemon}/bin/dbus-daemon" --fork \
|
|
|
|
--config-file="${pkgs.dbus.daemon}/share/dbus-1/system.conf"
|
2015-09-17 10:02:43 +01:00
|
|
|
|
|
|
|
${guestAdditions}/bin/VBoxService
|
|
|
|
${(attrs.vmScript or (const "")) pkgs}
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while [ ! -e /mnt-root/shutdown ]; do
|
|
|
|
sleep 10
|
|
|
|
i=$(($i + 10))
|
|
|
|
[ $i -le 120 ] || fail
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f /mnt-root/boot-done /mnt-root/shutdown
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
boot.kernelParams = [
|
2014-12-13 10:15:48 +00:00
|
|
|
"console=tty0" "console=ttyS0" "ignore_loglevel"
|
|
|
|
"boot.trace" "panic=1" "boot.panic_on_fail"
|
2014-12-15 07:58:12 +00:00
|
|
|
"init=${pkgs.writeScript "mini-init.sh" miniInit}"
|
2014-12-13 10:15:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
fileSystems."/" = {
|
|
|
|
device = "vboxshare";
|
|
|
|
fsType = "vboxsf";
|
|
|
|
};
|
|
|
|
|
2015-08-13 11:17:32 +01:00
|
|
|
virtualisation.virtualbox.guest.enable = true;
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
boot.initrd.kernelModules = [
|
|
|
|
"af_packet" "vboxsf"
|
|
|
|
"virtio" "virtio_pci" "virtio_ring" "virtio_net" "vboxguest"
|
|
|
|
];
|
2014-12-13 10:15:48 +00:00
|
|
|
|
|
|
|
boot.initrd.extraUtilsCommands = ''
|
2015-09-17 10:02:43 +01:00
|
|
|
copy_bin_and_libs "${guestAdditions}/bin/mount.vboxsf"
|
2015-03-29 00:15:41 +00:00
|
|
|
copy_bin_and_libs "${pkgs.utillinux}/bin/unshare"
|
2014-12-15 07:58:12 +00:00
|
|
|
${(attrs.extraUtilsCommands or (const "")) pkgs}
|
2014-12-13 10:15:48 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
boot.initrd.postMountCommands = ''
|
|
|
|
touch /mnt-root/boot-done
|
2014-12-15 07:58:12 +00:00
|
|
|
hostname "${vmName}"
|
|
|
|
mkdir -p /nix/store
|
nixos/tests/virtualbox: Fix @shell@ expansion
This has surfaced since f803270b7e00fa7124282809838d5652083b6aad.
The commit bumped bash to version 4.4, which caused to change the order
of --subst-var flags in substituteAll, which this test was relying on,
because it added a @shell@ to boot.initrd.postMountCommands.
Our substituter is currently working a bit like this:
original.replace('@var1@', 'val1').replace('@var2@', 'val2')...
Unfortunately, this means that if @var2@ occurs within @var1@ it is
replaced by the new value, so the order of the substvars actually
matter. I highly doubt that we want a behaviour like this and I'm
wondering why it didn't occur to me as a problem while writing the
initial implementation of the VirtualBox tests.
Whether to get rid of this and disallowing substitution of substvars
within substvars is another topic which I think needs discussion in a
different place.
As for now, I'm using stdenv.shell, because the closure size of this
should fit within the initrd, so it's fine especially because it's just
a test.
Tested with the net-hostonlyif and systemd-detect-virt tests and they
both succeed with this change.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Reported-by: @globin on IRC
2017-03-27 03:15:44 +01:00
|
|
|
unshare -m ${escapeShellArg pkgs.stdenv.shell} -c '
|
2014-12-15 07:58:12 +00:00
|
|
|
mount -t vboxsf nixstore /nix/store
|
|
|
|
exec "$stage2Init"
|
|
|
|
'
|
2014-12-13 10:15:48 +00:00
|
|
|
poweroff -f
|
|
|
|
'';
|
|
|
|
|
|
|
|
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
|
|
|
(isYes "SERIAL_8250_CONSOLE")
|
|
|
|
(isYes "SERIAL_8250")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2014-12-15 18:17:38 +00:00
|
|
|
mkLog = logfile: tag: let
|
|
|
|
rotated = map (i: "${logfile}.${toString i}") (range 1 9);
|
|
|
|
all = concatMapStringsSep " " (f: "\"${f}\"") ([logfile] ++ rotated);
|
|
|
|
logcmd = "tail -F ${all} 2> /dev/null | logger -t \"${tag}\"";
|
2014-12-18 12:43:18 +00:00
|
|
|
in optionalString debug "$machine->execute(ru '${logcmd} & disown');";
|
2014-12-15 18:17:38 +00:00
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
testVM = vmName: vmScript: let
|
2014-12-13 10:15:48 +00:00
|
|
|
cfg = (import ../lib/eval-config.nix {
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
system = if use64bitGuest then "x86_64-linux" else "i686-linux";
|
2014-12-13 10:15:48 +00:00
|
|
|
modules = [
|
|
|
|
../modules/profiles/minimal.nix
|
2014-12-15 07:58:12 +00:00
|
|
|
(testVMConfig vmName vmScript)
|
2014-12-13 10:15:48 +00:00
|
|
|
];
|
|
|
|
}).config;
|
|
|
|
in pkgs.vmTools.runInLinuxVM (pkgs.runCommand "virtualbox-image" {
|
|
|
|
preVM = ''
|
|
|
|
mkdir -p "$out"
|
|
|
|
diskImage="$(pwd)/qimage"
|
|
|
|
${pkgs.vmTools.qemu}/bin/qemu-img create -f raw "$diskImage" 100M
|
|
|
|
'';
|
|
|
|
|
|
|
|
postVM = ''
|
|
|
|
echo "creating VirtualBox disk image..."
|
|
|
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vdi \
|
|
|
|
"$diskImage" "$out/disk.vdi"
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildInputs = [ pkgs.utillinux pkgs.perl ];
|
|
|
|
} ''
|
2017-10-08 14:35:47 +01:00
|
|
|
${pkgs.parted}/sbin/parted --script /dev/vda mklabel msdos
|
|
|
|
${pkgs.parted}/sbin/parted --script /dev/vda -- mkpart primary ext2 1M -1s
|
2014-12-13 10:15:48 +00:00
|
|
|
${pkgs.e2fsprogs}/sbin/mkfs.ext4 /dev/vda1
|
|
|
|
${pkgs.e2fsprogs}/sbin/tune2fs -c 0 -i 0 /dev/vda1
|
|
|
|
mkdir /mnt
|
|
|
|
mount /dev/vda1 /mnt
|
|
|
|
cp "${cfg.system.build.kernel}/bzImage" /mnt/linux
|
|
|
|
cp "${cfg.system.build.initialRamdisk}/initrd" /mnt/initrd
|
|
|
|
|
|
|
|
${pkgs.grub2}/bin/grub-install --boot-directory=/mnt /dev/vda
|
|
|
|
|
|
|
|
cat > /mnt/grub/grub.cfg <<GRUB
|
|
|
|
set root=hd0,1
|
2014-12-13 11:13:30 +00:00
|
|
|
linux /linux ${concatStringsSep " " cfg.boot.kernelParams}
|
2014-12-13 10:15:48 +00:00
|
|
|
initrd /initrd
|
|
|
|
boot
|
|
|
|
GRUB
|
|
|
|
umount /mnt
|
|
|
|
'');
|
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
createVM = name: attrs: let
|
2014-12-13 11:13:30 +00:00
|
|
|
mkFlags = concatStringsSep " ";
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sharePath = "/home/alice/vboxshare-${name}";
|
2014-12-13 10:15:48 +00:00
|
|
|
|
|
|
|
createFlags = mkFlags [
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
"--ostype ${if use64bitGuest then "Linux26_64" else "Linux26"}"
|
2014-12-13 10:15:48 +00:00
|
|
|
"--register"
|
|
|
|
];
|
|
|
|
|
2019-09-03 20:59:50 +01:00
|
|
|
vmFlags = mkFlags ([
|
|
|
|
"--uart1 0x3F8 4"
|
|
|
|
"--uartmode1 client /run/virtualbox-log-${name}.sock"
|
2015-09-22 08:24:10 +01:00
|
|
|
"--memory 768"
|
2016-09-13 22:17:47 +01:00
|
|
|
"--audio none"
|
2014-12-15 07:58:12 +00:00
|
|
|
] ++ (attrs.vmFlags or []));
|
2014-12-13 10:15:48 +00:00
|
|
|
|
|
|
|
controllerFlags = mkFlags [
|
|
|
|
"--name SATA"
|
|
|
|
"--add sata"
|
|
|
|
"--bootable on"
|
|
|
|
"--hostiocache on"
|
|
|
|
];
|
|
|
|
|
|
|
|
diskFlags = mkFlags [
|
|
|
|
"--storagectl SATA"
|
|
|
|
"--port 0"
|
|
|
|
"--device 0"
|
|
|
|
"--type hdd"
|
|
|
|
"--mtype immutable"
|
2014-12-15 07:58:12 +00:00
|
|
|
"--medium ${testVM name attrs}/disk.vdi"
|
2014-12-13 10:15:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
sharedFlags = mkFlags [
|
|
|
|
"--name vboxshare"
|
2014-12-13 11:13:30 +00:00
|
|
|
"--hostpath ${sharePath}"
|
2014-12-13 10:15:48 +00:00
|
|
|
];
|
2014-12-15 07:58:12 +00:00
|
|
|
|
|
|
|
nixstoreFlags = mkFlags [
|
|
|
|
"--name nixstore"
|
|
|
|
"--hostpath /nix/store"
|
|
|
|
"--readonly"
|
|
|
|
];
|
2014-12-13 11:13:30 +00:00
|
|
|
in {
|
|
|
|
machine = {
|
2019-09-03 20:59:50 +01:00
|
|
|
systemd.sockets."vboxtestlog-${name}" = {
|
2015-09-17 10:32:05 +01:00
|
|
|
description = "VirtualBox Test Machine Log Socket For ${name}";
|
2015-09-17 10:25:37 +01:00
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
before = [ "multi-user.target" ];
|
|
|
|
socketConfig.ListenStream = "/run/virtualbox-log-${name}.sock";
|
|
|
|
socketConfig.Accept = true;
|
|
|
|
};
|
|
|
|
|
2019-09-03 20:59:50 +01:00
|
|
|
systemd.services."vboxtestlog-${name}@" = {
|
2015-09-17 10:32:05 +01:00
|
|
|
description = "VirtualBox Test Machine Log For ${name}";
|
2015-09-17 10:25:37 +01:00
|
|
|
serviceConfig.StandardInput = "socket";
|
|
|
|
serviceConfig.StandardOutput = "syslog";
|
|
|
|
serviceConfig.SyslogIdentifier = "GUEST-${name}";
|
|
|
|
serviceConfig.ExecStart = "${pkgs.coreutils}/bin/cat";
|
|
|
|
};
|
2014-12-13 11:13:30 +00:00
|
|
|
};
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
testSubs = ''
|
2015-09-17 13:12:24 +01:00
|
|
|
my ${"$" + name}_sharepath = '${sharePath}';
|
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
sub checkRunning_${name} {
|
|
|
|
my $cmd = 'VBoxManage list runningvms | grep -q "^\"${name}\""';
|
|
|
|
my ($status, $out) = $machine->execute(ru $cmd);
|
|
|
|
return $status == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cleanup_${name} {
|
|
|
|
$machine->execute(ru "VBoxManage controlvm ${name} poweroff")
|
|
|
|
if checkRunning_${name};
|
|
|
|
$machine->succeed("rm -rf ${sharePath}");
|
|
|
|
$machine->succeed("mkdir -p ${sharePath}");
|
|
|
|
$machine->succeed("chown alice.users ${sharePath}");
|
|
|
|
}
|
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sub createVM_${name} {
|
|
|
|
vbm("createvm --name ${name} ${createFlags}");
|
|
|
|
vbm("modifyvm ${name} ${vmFlags}");
|
2014-12-15 07:58:12 +00:00
|
|
|
vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1");
|
2014-12-13 11:13:30 +00:00
|
|
|
vbm("storagectl ${name} ${controllerFlags}");
|
|
|
|
vbm("storageattach ${name} ${diskFlags}");
|
|
|
|
vbm("sharedfolder add ${name} ${sharedFlags}");
|
2014-12-15 07:58:12 +00:00
|
|
|
vbm("sharedfolder add ${name} ${nixstoreFlags}");
|
|
|
|
cleanup_${name};
|
2014-12-15 18:17:38 +00:00
|
|
|
|
|
|
|
${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"}
|
2014-12-15 07:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub destroyVM_${name} {
|
|
|
|
cleanup_${name};
|
|
|
|
vbm("unregistervm ${name} --delete");
|
2014-12-13 11:13:30 +00:00
|
|
|
}
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sub waitForVMBoot_${name} {
|
|
|
|
$machine->execute(ru(
|
|
|
|
'set -e; i=0; '.
|
|
|
|
'while ! test -e ${sharePath}/boot-done; do '.
|
|
|
|
'sleep 10; i=$(($i + 10)); [ $i -le 3600 ]; '.
|
|
|
|
'VBoxManage list runningvms | grep -q "^\"${name}\""; '.
|
|
|
|
'done'
|
|
|
|
));
|
|
|
|
}
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
sub waitForIP_${name} ($) {
|
|
|
|
my $property = "/VirtualBox/GuestInfo/Net/$_[0]/V4/IP";
|
|
|
|
my $getip = "VBoxManage guestproperty get ${name} $property | ".
|
|
|
|
"sed -n -e 's/^Value: //p'";
|
|
|
|
my $ip = $machine->succeed(ru(
|
|
|
|
'for i in $(seq 1000); do '.
|
|
|
|
'if ipaddr="$('.$getip.')" && [ -n "$ipaddr" ]; then '.
|
|
|
|
'echo "$ipaddr"; exit 0; '.
|
|
|
|
'fi; '.
|
|
|
|
'sleep 1; '.
|
|
|
|
'done; '.
|
|
|
|
'echo "Could not get IPv4 address for ${name}!" >&2; '.
|
|
|
|
'exit 1'
|
|
|
|
));
|
|
|
|
chomp $ip;
|
|
|
|
return $ip;
|
2014-12-13 10:15:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sub waitForStartup_${name} {
|
|
|
|
for (my $i = 0; $i <= 120; $i += 10) {
|
|
|
|
$machine->sleep(10);
|
|
|
|
return if checkRunning_${name};
|
2015-04-04 06:51:46 +01:00
|
|
|
eval { $_[0]->() } if defined $_[0];
|
2014-12-13 11:13:30 +00:00
|
|
|
}
|
|
|
|
die "VirtualBox VM didn't start up within 2 minutes";
|
2014-12-13 10:15:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sub waitForShutdown_${name} {
|
|
|
|
for (my $i = 0; $i <= 120; $i += 10) {
|
|
|
|
$machine->sleep(10);
|
|
|
|
return unless checkRunning_${name};
|
|
|
|
}
|
|
|
|
die "VirtualBox VM didn't shut down within 2 minutes";
|
|
|
|
}
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-13 11:13:30 +00:00
|
|
|
sub shutdownVM_${name} {
|
|
|
|
$machine->succeed(ru "touch ${sharePath}/shutdown");
|
2016-09-13 13:52:49 +01:00
|
|
|
$machine->execute(
|
|
|
|
'set -e; i=0; '.
|
|
|
|
'while test -e ${sharePath}/shutdown '.
|
|
|
|
' -o -e ${sharePath}/boot-done; do '.
|
|
|
|
'sleep 1; i=$(($i + 1)); [ $i -le 3600 ]; '.
|
|
|
|
'done'
|
2014-12-13 11:13:30 +00:00
|
|
|
);
|
|
|
|
waitForShutdown_${name};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
hostonlyVMFlags = [
|
|
|
|
"--nictype1 virtio"
|
|
|
|
"--nictype2 virtio"
|
|
|
|
"--nic2 hostonly"
|
|
|
|
"--hostonlyadapter2 vboxnet0"
|
|
|
|
];
|
|
|
|
|
2018-08-13 01:25:43 +01:00
|
|
|
# The VirtualBox Oracle Extension Pack lets you use USB 3.0 (xHCI).
|
|
|
|
enableExtensionPackVMFlags = [
|
|
|
|
"--usbxhci on"
|
|
|
|
];
|
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
dhcpScript = pkgs: ''
|
|
|
|
${pkgs.dhcp}/bin/dhclient \
|
|
|
|
-lf /run/dhcp.leases \
|
|
|
|
-pf /run/dhclient.pid \
|
|
|
|
-v eth0 eth1
|
|
|
|
|
2016-10-30 01:52:47 +01:00
|
|
|
otherIP="$(${pkgs.netcat}/bin/nc -l 1234 || :)"
|
2014-12-15 07:58:12 +00:00
|
|
|
${pkgs.iputils}/bin/ping -I eth1 -c1 "$otherIP"
|
2016-10-30 01:52:47 +01:00
|
|
|
echo "$otherIP reachable" | ${pkgs.netcat}/bin/nc -l 5678 || :
|
2014-12-15 07:58:12 +00:00
|
|
|
'';
|
|
|
|
|
2015-09-17 13:12:24 +01:00
|
|
|
sysdDetectVirt = pkgs: ''
|
|
|
|
${pkgs.systemd}/bin/systemd-detect-virt > /mnt-root/result
|
|
|
|
'';
|
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
vboxVMs = mapAttrs createVM {
|
|
|
|
simple = {};
|
|
|
|
|
2015-09-17 13:12:24 +01:00
|
|
|
detectvirt.vmScript = sysdDetectVirt;
|
|
|
|
|
2014-12-15 07:58:12 +00:00
|
|
|
test1.vmFlags = hostonlyVMFlags;
|
|
|
|
test1.vmScript = dhcpScript;
|
|
|
|
|
|
|
|
test2.vmFlags = hostonlyVMFlags;
|
|
|
|
test2.vmScript = dhcpScript;
|
2016-09-01 19:54:58 +01:00
|
|
|
|
|
|
|
headless.virtualisation.virtualbox.headless = true;
|
|
|
|
headless.services.xserver.enable = false;
|
2014-12-15 07:58:12 +00:00
|
|
|
};
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2018-08-13 01:25:43 +01:00
|
|
|
vboxVMsWithExtpack = mapAttrs createVM {
|
|
|
|
testExtensionPack.vmFlags = enableExtensionPackVMFlags;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkVBoxTest = useExtensionPack: vms: name: testScript: makeTest {
|
2016-02-29 18:15:36 +00:00
|
|
|
name = "virtualbox-${name}";
|
|
|
|
|
|
|
|
machine = { lib, config, ... }: {
|
|
|
|
imports = let
|
|
|
|
mkVMConf = name: val: val.machine // { key = "${name}-config"; };
|
2018-08-13 01:25:43 +01:00
|
|
|
vmConfigs = mapAttrsToList mkVMConf vms;
|
2016-02-29 18:15:36 +00:00
|
|
|
in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs;
|
|
|
|
virtualisation.memorySize = 2048;
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
virtualisation.qemu.options =
|
|
|
|
if useKvmNestedVirt then ["-cpu" "kvm64,vmx=on"] else [];
|
2016-02-29 18:15:36 +00:00
|
|
|
virtualisation.virtualbox.host.enable = true;
|
2020-01-26 22:41:19 +00:00
|
|
|
test-support.displayManager.auto.user = "alice";
|
2018-06-30 00:55:42 +01:00
|
|
|
users.users.alice.extraGroups = let
|
2016-02-29 18:15:36 +00:00
|
|
|
inherit (config.virtualisation.virtualbox.host) enableHardening;
|
|
|
|
in lib.mkIf enableHardening (lib.singleton "vboxusers");
|
2018-08-13 01:25:43 +01:00
|
|
|
virtualisation.virtualbox.host.enableExtensionPack = useExtensionPack;
|
|
|
|
nixpkgs.config.allowUnfree = useExtensionPack;
|
2016-02-29 18:15:36 +00:00
|
|
|
};
|
2014-12-13 11:13:30 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
testScript = ''
|
|
|
|
sub ru ($) {
|
|
|
|
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
|
|
|
|
return "su - alice -c '$esc'";
|
|
|
|
}
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
sub vbm {
|
|
|
|
$machine->succeed(ru("VBoxManage ".$_[0]));
|
|
|
|
};
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
sub removeUUIDs {
|
|
|
|
return join("\n", grep { $_ !~ /^UUID:/ } split(/\n/, $_[0]))."\n";
|
|
|
|
}
|
2014-12-13 11:13:30 +00:00
|
|
|
|
2018-08-13 01:25:43 +01:00
|
|
|
${concatStrings (mapAttrsToList (_: getAttr "testSubs") vms)}
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
$machine->waitForX;
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
${mkLog "$HOME/.config/VirtualBox/VBoxSVC.log" "HOST-SVC"}
|
2014-12-15 18:17:38 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
${testScript}
|
|
|
|
'';
|
2014-12-13 11:13:30 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
2019-01-26 10:01:09 +00:00
|
|
|
maintainers = [ aszlig cdepillabout ];
|
2014-12-13 10:15:48 +00:00
|
|
|
};
|
2016-02-29 18:15:36 +00:00
|
|
|
};
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2018-08-28 21:28:47 +01:00
|
|
|
unfreeTests = mapAttrs (mkVBoxTest true vboxVMsWithExtpack) {
|
|
|
|
enable-extension-pack = ''
|
|
|
|
createVM_testExtensionPack;
|
|
|
|
vbm("startvm testExtensionPack");
|
|
|
|
waitForStartup_testExtensionPack;
|
|
|
|
$machine->screenshot("cli_started");
|
|
|
|
waitForVMBoot_testExtensionPack;
|
|
|
|
$machine->screenshot("cli_booted");
|
|
|
|
|
|
|
|
$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'");
|
|
|
|
});
|
|
|
|
|
|
|
|
shutdownVM_testExtensionPack;
|
|
|
|
destroyVM_testExtensionPack;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-13 01:25:43 +01:00
|
|
|
in mapAttrs (mkVBoxTest false vboxVMs) {
|
2016-02-29 18:15:36 +00:00
|
|
|
simple-gui = ''
|
|
|
|
createVM_simple;
|
|
|
|
$machine->succeed(ru "VirtualBox &");
|
2016-05-26 15:27:16 +01:00
|
|
|
$machine->waitUntilSucceeds(
|
|
|
|
ru "xprop -name 'Oracle VM VirtualBox Manager'"
|
|
|
|
);
|
2016-02-29 18:15:36 +00:00
|
|
|
$machine->sleep(5);
|
|
|
|
$machine->screenshot("gui_manager_started");
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
# Home to select Tools, down to move to the VM, enter to start it.
|
|
|
|
$machine->sendKeys("home");
|
|
|
|
$machine->sendKeys("down");
|
2016-02-29 18:15:36 +00:00
|
|
|
$machine->sendKeys("ret");
|
|
|
|
$machine->screenshot("gui_manager_sent_startup");
|
|
|
|
waitForStartup_simple (sub {
|
virtualbox: 5.2.28 -> 6.0.6
Quite some fixing was needed to get this to work.
Changes in VirtualBox and additions:
- VirtualBox is no longer officially supported on 32-bit hosts so i686-linux is removed from platforms
for VirtualBox and the extension pack. 32-bit additions still work.
- There was a refactoring of kernel module makefiles and two resulting bugs affected us which had to be patched.
These bugs were reported to the bug tracker (see comments near patches).
- The Qt5X11Extras makefile patch broke. Fixed it to apply again, making the libraries logic simpler
and more correct (it just uses a different base path instead of always linking to Qt5X11Extras).
- Added a patch to remove "test1" and "test2" kernel messages due to forgotten debugging code.
- virtualbox-host NixOS module: the VirtualBoxVM executable should be setuid not VirtualBox.
This matches how the official installer sets it up.
- Additions: replaced a for loop for installing kernel modules with just a "make install",
which seems to work without any of the things done in the previous code.
- Additions: The package defined buildCommand which resulted in phases not running, including RUNPATH
stripping in fixupPhase, and installPhase was defined which was not even run. Fixed this by
refactoring using phases. Had to set dontStrip otherwise binaries were broken by stripping.
The libdbus path had to be added later in fixupPhase because it is used via dlopen not directly linked.
- Additions: Added zlib and libc to patchelf, otherwise runtime library errors result from some binaries.
For some reason the missing libc only manifested itself for mount.vboxsf when included in the initrd.
Changes in nixos/tests/virtualbox:
- Update the simple-gui test to send the right keys to start the VM. With VirtualBox 5
it was enough to just send "return", but with 6 the Tools thing may be selected by
default. Send "home" to reliably select Tools, "down" to move to the VM and "return"
to start it.
- Disable the VirtualBox UART by default because it causes a crash due to a regression
in VirtualBox (specific to software virtualization and serial port usage). It can
still be enabled using an option but there is an assert that KVM nested virtualization
is enabled, which works around the problem (see below).
- Add an option to enable nested KVM virtualization, allowing VirtualBox to use hardware
virtualization. This works around the UART problem and also allows using 64-bit
guests, but requires a kernel module parameter.
- Add an option to run 64-bit guests. Tested that the tests pass with that. As mentioned
this requires KVM nested virtualization.
2019-05-04 15:18:39 +01:00
|
|
|
$machine->sendKeys("home");
|
|
|
|
$machine->sendKeys("down");
|
2016-02-29 18:15:36 +00:00
|
|
|
$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");
|
2016-09-14 01:12:16 +01:00
|
|
|
destroyVM_simple;
|
2016-02-29 18:15:36 +00:00
|
|
|
'';
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
simple-cli = ''
|
|
|
|
createVM_simple;
|
|
|
|
vbm("startvm simple");
|
|
|
|
waitForStartup_simple;
|
|
|
|
$machine->screenshot("cli_started");
|
|
|
|
waitForVMBoot_simple;
|
|
|
|
$machine->screenshot("cli_booted");
|
2014-12-13 10:15:48 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
$machine->nest("Checking for privilege escalation", sub {
|
2014-12-15 07:58:12 +00:00
|
|
|
$machine->fail("test -e '/root/VirtualBox VMs'");
|
2014-12-15 18:12:58 +00:00
|
|
|
$machine->fail("test -e '/root/.config/VirtualBox'");
|
2014-12-15 07:58:12 +00:00
|
|
|
$machine->succeed("test -e '/home/alice/VirtualBox VMs'");
|
2016-02-29 18:15:36 +00:00
|
|
|
});
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
shutdownVM_simple;
|
2016-09-14 01:12:16 +01:00
|
|
|
destroyVM_simple;
|
2016-02-29 18:15:36 +00:00
|
|
|
'';
|
2015-09-17 22:47:33 +01:00
|
|
|
|
2016-09-01 19:54:58 +01:00
|
|
|
headless = ''
|
|
|
|
createVM_headless;
|
|
|
|
$machine->succeed(ru("VBoxHeadless --startvm headless & disown %1"));
|
|
|
|
waitForStartup_headless;
|
|
|
|
waitForVMBoot_headless;
|
|
|
|
shutdownVM_headless;
|
2016-09-14 01:12:16 +01:00
|
|
|
destroyVM_headless;
|
2016-09-01 19:54:58 +01:00
|
|
|
'';
|
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
host-usb-permissions = ''
|
|
|
|
my $userUSB = removeUUIDs vbm("list usbhost");
|
|
|
|
print STDERR $userUSB;
|
|
|
|
my $rootUSB = removeUUIDs $machine->succeed("VBoxManage list usbhost");
|
|
|
|
print STDERR $rootUSB;
|
2015-09-17 22:47:33 +01:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
die "USB host devices differ for root and normal user"
|
|
|
|
if $userUSB ne $rootUSB;
|
|
|
|
die "No USB host devices found" if $userUSB =~ /<none>/;
|
|
|
|
'';
|
2015-09-17 22:47:33 +01:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
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";
|
|
|
|
'';
|
2015-09-17 13:12:24 +01:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
net-hostonlyif = ''
|
|
|
|
createVM_test1;
|
|
|
|
createVM_test2;
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
vbm("startvm test1");
|
|
|
|
waitForStartup_test1;
|
|
|
|
waitForVMBoot_test1;
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
vbm("startvm test2");
|
|
|
|
waitForStartup_test2;
|
|
|
|
waitForVMBoot_test2;
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
$machine->screenshot("net_booted");
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
my $test1IP = waitForIP_test1 1;
|
|
|
|
my $test2IP = waitForIP_test2 1;
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2017-09-21 01:38:52 +01:00
|
|
|
$machine->succeed("echo '$test2IP' | nc -N '$test1IP' 1234");
|
|
|
|
$machine->succeed("echo '$test1IP' | nc -N '$test2IP' 1234");
|
2014-12-13 11:13:30 +00:00
|
|
|
|
2017-09-21 01:38:52 +01:00
|
|
|
$machine->waitUntilSucceeds("nc -N '$test1IP' 5678 < /dev/null >&2");
|
|
|
|
$machine->waitUntilSucceeds("nc -N '$test2IP' 5678 < /dev/null >&2");
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
shutdownVM_test1;
|
|
|
|
shutdownVM_test2;
|
2014-12-15 07:58:12 +00:00
|
|
|
|
2016-02-29 18:15:36 +00:00
|
|
|
destroyVM_test1;
|
|
|
|
destroyVM_test2;
|
2014-12-13 10:15:48 +00:00
|
|
|
'';
|
2018-08-28 21:28:47 +01:00
|
|
|
} // (if enableUnfree then unfreeTests else {})
|