diff --git a/lib/qemu-flags.nix b/lib/qemu-flags.nix new file mode 100644 index 000000000000..05edc1d2cc6c --- /dev/null +++ b/lib/qemu-flags.nix @@ -0,0 +1,15 @@ +# QEMU flags shared between various Nix expressions. + +{ + + qemuNICFlags = nic: net: + "-net nic,vlan=${toString nic},model=virtio " + + # Use 232.0.1. as the multicast address to connect VMs on + # the same vlan, but allow it to be overriden using the + # $QEMU_MCAST_ADDR_ environment variable. The test driver + # sets this variable to prevent collisions between parallel + # builds. + "-net socket,vlan=${toString nic},mcast=" + + "\${QEMU_MCAST_ADDR_${toString net}:-232.0.1.${toString net}:1234} "; + +} diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index ed43d8d255a4..5ff7bf6cea19 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -34,6 +34,7 @@ sub new { if defined $args->{hda}; $startCommand .= "-cdrom $args->{cdrom} " if defined $args->{cdrom}; + $startCommand .= $args->{qemuFlags} || ""; } my $name = $args->{name}; diff --git a/tests/installer.nix b/tests/installer.nix index 26423cd9d061..883138f17608 100644 --- a/tests/installer.nix +++ b/tests/installer.nix @@ -1,6 +1,7 @@ { pkgs, nixpkgs, system, ... }: with pkgs.lib; +with import ../lib/qemu-flags.nix; let @@ -104,7 +105,7 @@ let '' createDisk("harddisk", 4 * 1024); - my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") }); + my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso"), qemuFlags => '${qemuNICFlags 1 1}' }); $machine->start; ${optionalString testChannel ''