2018-09-27 15:03:23 +00:00
|
|
|
{ system
|
|
|
|
, # Use a minimal kernel?
|
|
|
|
minimal ? false
|
|
|
|
, # Ignored
|
|
|
|
config ? null
|
|
|
|
# Nixpkgs, for qemu, lib and more
|
|
|
|
, pkgs
|
|
|
|
, # NixOS configuration to add to the VMs
|
|
|
|
extraConfigurations ? []
|
|
|
|
}:
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
with pkgs.lib;
|
2018-01-30 09:22:41 +00:00
|
|
|
with import ../lib/qemu-flags.nix { inherit pkgs; };
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
inherit pkgs;
|
|
|
|
|
2016-12-15 13:05:54 +00:00
|
|
|
qemu = pkgs.qemu_test;
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
# Build a virtual network from an attribute set `{ machine1 =
|
|
|
|
# config1; ... machineN = configN; }', where `machineX' is the
|
2011-01-16 14:21:47 +00:00
|
|
|
# hostname and `configX' is a NixOS system configuration. Each
|
|
|
|
# machine is given an arbitrary IP address in the virtual network.
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
buildVirtualNetwork =
|
2012-11-02 16:08:11 +00:00
|
|
|
nodes: let nodesOut = mapAttrs (n: buildVM nodesOut) (assignIPAddresses nodes); in nodesOut;
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
buildVM =
|
2009-09-15 00:18:00 +00:00
|
|
|
nodes: configurations:
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
2010-01-05 11:18:43 +00:00
|
|
|
import ./eval-config.nix {
|
2012-03-02 12:38:22 +00:00
|
|
|
inherit system;
|
2019-05-25 22:52:52 +00:00
|
|
|
modules = configurations ++ extraConfigurations;
|
|
|
|
baseModules = (import ../modules/module-list.nix) ++
|
2010-01-05 17:08:57 +00:00
|
|
|
[ ../modules/virtualisation/qemu-vm.nix
|
2010-01-05 11:18:43 +00:00
|
|
|
../modules/testing/test-instrumentation.nix # !!! should only get added for automated test runs
|
2018-09-06 19:17:48 +00:00
|
|
|
{ key = "no-manual"; documentation.nixos.enable = false; }
|
2016-12-15 13:05:54 +00:00
|
|
|
{ key = "qemu"; system.build.qemu = qemu; }
|
2019-05-25 22:15:10 +00:00
|
|
|
{ key = "nodes"; _module.args.nodes = nodes; }
|
2019-05-25 22:52:52 +00:00
|
|
|
] ++ optional minimal ../modules/testing/minimal-kernel.nix;
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# Given an attribute set { machine1 = config1; ... machineN =
|
|
|
|
# configN; }, sequentially assign IP addresses in the 192.168.1.0/24
|
|
|
|
# range to each machine, and set the hostname to the attribute name.
|
|
|
|
assignIPAddresses = nodes:
|
|
|
|
|
|
|
|
let
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
machines = attrNames nodes;
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
2015-07-28 12:56:27 +00:00
|
|
|
machinesNumbered = zipLists machines (range 1 254);
|
2010-05-20 21:07:32 +00:00
|
|
|
|
2019-08-05 11:03:38 +00:00
|
|
|
nodes_ = forEach machinesNumbered (m: nameValuePair m.fst
|
2018-07-20 20:56:59 +00:00
|
|
|
[ ( { config, nodes, ... }:
|
2010-05-20 21:07:32 +00:00
|
|
|
let
|
2015-07-28 12:56:27 +00:00
|
|
|
interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255);
|
2019-08-05 11:03:38 +00:00
|
|
|
interfaces = forEach interfacesNumbered ({ fst, snd }:
|
2017-12-03 04:13:14 +00:00
|
|
|
nameValuePair "eth${toString snd}" { ipv4.addresses =
|
2015-07-28 12:56:27 +00:00
|
|
|
[ { address = "192.168.${toString fst}.${toString m.snd}";
|
2014-08-31 16:46:16 +00:00
|
|
|
prefixLength = 24;
|
|
|
|
} ];
|
2014-08-31 16:46:26 +00:00
|
|
|
});
|
2010-05-20 21:07:32 +00:00
|
|
|
in
|
|
|
|
{ key = "ip-address";
|
|
|
|
config =
|
2019-08-07 08:31:13 +00:00
|
|
|
{ networking.hostName = mkDefault m.fst;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
networking.interfaces = listToAttrs interfaces;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-05-20 21:07:32 +00:00
|
|
|
networking.primaryIPAddress =
|
2017-12-03 04:13:14 +00:00
|
|
|
optionalString (interfaces != []) (head (head interfaces).value.ipv4.addresses).address;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-05-20 21:07:32 +00:00
|
|
|
# Put the IP addresses of all VMs in this machine's
|
|
|
|
# /etc/hosts file. If a machine has multiple
|
|
|
|
# interfaces, use the IP address corresponding to
|
|
|
|
# the first interface (i.e. the first network in its
|
|
|
|
# virtualisation.vlans option).
|
2012-11-02 16:08:11 +00:00
|
|
|
networking.extraHosts = flip concatMapStrings machines
|
2013-11-26 17:52:34 +00:00
|
|
|
(m': let config = (getAttr m' nodes).config; in
|
2015-02-19 21:13:49 +00:00
|
|
|
optionalString (config.networking.primaryIPAddress != "")
|
2010-05-20 21:07:32 +00:00
|
|
|
("${config.networking.primaryIPAddress} " +
|
2018-12-07 13:22:21 +00:00
|
|
|
optionalString (config.networking.domain != null)
|
|
|
|
"${config.networking.hostName}.${config.networking.domain} " +
|
2010-05-20 21:07:32 +00:00
|
|
|
"${config.networking.hostName}\n"));
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-05-20 21:07:32 +00:00
|
|
|
virtualisation.qemu.options =
|
2019-08-05 11:03:38 +00:00
|
|
|
forEach interfacesNumbered
|
2015-07-28 12:56:27 +00:00
|
|
|
({ fst, snd }: qemuNICFlags snd fst m.snd);
|
2010-05-20 21:07:32 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
2015-07-28 12:56:27 +00:00
|
|
|
(getAttr m.fst nodes)
|
2010-05-20 21:07:32 +00:00
|
|
|
] );
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
in listToAttrs nodes_;
|
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 14:25:12 +00:00
|
|
|
|
|
|
|
}
|