2018-09-27 16:03:23 +01:00
|
|
|
{ system
|
|
|
|
, # Use a minimal kernel?
|
|
|
|
minimal ? false
|
|
|
|
, # Ignored
|
|
|
|
config ? null
|
2020-06-02 15:27:07 +01:00
|
|
|
, # Nixpkgs, for qemu, lib and more
|
|
|
|
pkgs
|
|
|
|
, # !!! See comment about args in lib/modules.nix
|
|
|
|
specialArgs ? {}
|
2018-09-27 16:03:23 +01:00
|
|
|
, # 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 15:25:12 +01: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 15:25:12 +01:00
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
inherit pkgs;
|
|
|
|
|
|
|
|
# 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 15:25:12 +01: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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
buildVM =
|
2009-09-15 01:18:00 +01: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 15:25:12 +01:00
|
|
|
|
2010-01-05 11:18:43 +00:00
|
|
|
import ./eval-config.nix {
|
2020-06-02 15:27:07 +01:00
|
|
|
inherit system specialArgs;
|
2019-05-25 23:52:52 +01: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 20:17:48 +01:00
|
|
|
{ key = "no-manual"; documentation.nixos.enable = false; }
|
2019-05-25 23:15:10 +01:00
|
|
|
{ key = "nodes"; _module.args.nodes = nodes; }
|
2019-05-25 23:52:52 +01: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 15:25:12 +01: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 19:20:50 +01: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 15:25:12 +01:00
|
|
|
|
2015-07-28 13:56:27 +01:00
|
|
|
machinesNumbered = zipLists machines (range 1 254);
|
2010-05-20 22:07:32 +01:00
|
|
|
|
2019-08-05 12:03:38 +01:00
|
|
|
nodes_ = forEach machinesNumbered (m: nameValuePair m.fst
|
2018-07-20 21:56:59 +01:00
|
|
|
[ ( { config, nodes, ... }:
|
2010-05-20 22:07:32 +01:00
|
|
|
let
|
2015-07-28 13:56:27 +01:00
|
|
|
interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255);
|
2019-08-05 12:03:38 +01:00
|
|
|
interfaces = forEach interfacesNumbered ({ fst, snd }:
|
2017-12-03 04:13:14 +00:00
|
|
|
nameValuePair "eth${toString snd}" { ipv4.addresses =
|
2015-07-28 13:56:27 +01:00
|
|
|
[ { address = "192.168.${toString fst}.${toString m.snd}";
|
2014-08-31 17:46:16 +01:00
|
|
|
prefixLength = 24;
|
|
|
|
} ];
|
2014-08-31 17:46:26 +01:00
|
|
|
});
|
2010-05-20 22:07:32 +01:00
|
|
|
in
|
|
|
|
{ key = "ip-address";
|
|
|
|
config =
|
2019-08-07 09:31:13 +01:00
|
|
|
{ networking.hostName = mkDefault m.fst;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
networking.interfaces = listToAttrs interfaces;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-05-20 22:07:32 +01:00
|
|
|
networking.primaryIPAddress =
|
2017-12-03 04:13:14 +00:00
|
|
|
optionalString (interfaces != []) (head (head interfaces).value.ipv4.addresses).address;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-05-20 22:07:32 +01: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 22:07:32 +01: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 22:07:32 +01:00
|
|
|
"${config.networking.hostName}\n"));
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-05-20 22:07:32 +01:00
|
|
|
virtualisation.qemu.options =
|
2019-08-05 12:03:38 +01:00
|
|
|
forEach interfacesNumbered
|
2015-07-28 13:56:27 +01:00
|
|
|
({ fst, snd }: qemuNICFlags snd fst m.snd);
|
2010-05-20 22:07:32 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
2015-07-28 13:56:27 +01:00
|
|
|
(getAttr m.fst nodes)
|
2010-05-20 22:07:32 +01: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 15:25:12 +01: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 15:25:12 +01:00
|
|
|
|
|
|
|
}
|