* Remove "nix-build tests -A foo.vms; ./result/bin/run-vms" as a way
to run the VMs of a test. Instead, you can do $ nix-build tests -A foo.driver $ ./result/bin/nixos-run-vms This uses the test driver infrastructure, which is necessary in order to set up the VDE switches. svn path=/nixos/trunk/; revision=25586
This commit is contained in:
parent
ef54cd3d1f
commit
066f76e65f
@ -12,42 +12,10 @@ rec {
|
||||
|
||||
# Build a virtual network from an attribute set `{ machine1 =
|
||||
# config1; ... machineN = configN; }', where `machineX' is the
|
||||
# hostname and `configX' is a NixOS system configuration. The
|
||||
# result is a script that starts a QEMU instance for each virtual
|
||||
# machine. Each machine is given an arbitrary IP address in the
|
||||
# virtual network.
|
||||
# hostname and `configX' is a NixOS system configuration. Each
|
||||
# machine is given an arbitrary IP address in the virtual network.
|
||||
buildVirtualNetwork =
|
||||
{ nodes }:
|
||||
|
||||
let nodes_ = lib.mapAttrs (n: buildVM nodes_) (assignIPAddresses nodes); in
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "vms";
|
||||
buildCommand =
|
||||
''
|
||||
ensureDir $out/vms
|
||||
${
|
||||
lib.concatMapStrings (vm:
|
||||
''
|
||||
ln -sn ${vm.config.system.build.vm} $out/vms/${vm.config.networking.hostName}
|
||||
''
|
||||
) (lib.attrValues nodes_)
|
||||
}
|
||||
|
||||
ensureDir $out/bin
|
||||
cat > $out/bin/run-vms <<EOF
|
||||
#! ${stdenv.shell}
|
||||
port=8080
|
||||
for i in $out/vms/*; do
|
||||
port2=\$((port++))
|
||||
echo "forwarding localhost:\$port2 to \$(basename \$i):80"
|
||||
QEMU_OPTS="-redir tcp:\$port2::80" \$i/bin/run-*-vm &
|
||||
done
|
||||
EOF
|
||||
chmod +x $out/bin/run-vms
|
||||
''; # */
|
||||
passthru = { nodes = nodes_; };
|
||||
};
|
||||
nodes: let nodesOut = lib.mapAttrs (n: buildVM nodesOut) (assignIPAddresses nodes); in nodesOut;
|
||||
|
||||
|
||||
buildVM =
|
||||
|
@ -121,21 +121,24 @@ rec {
|
||||
call = f: f { inherit pkgs nixpkgs system; };
|
||||
|
||||
complete = t: t // rec {
|
||||
nodes =
|
||||
nodes = buildVirtualNetwork (
|
||||
if t ? nodes then t.nodes else
|
||||
if t ? machine then { machine = t.machine; }
|
||||
else { };
|
||||
|
||||
vms = buildVirtualNetwork { inherit nodes; };
|
||||
|
||||
else { } );
|
||||
|
||||
testScript =
|
||||
# Call the test script with the computed nodes.
|
||||
if builtins.isFunction t.testScript
|
||||
then t.testScript { inherit (vms) nodes; }
|
||||
then t.testScript { inherit nodes; }
|
||||
else t.testScript;
|
||||
|
||||
# Generate a convenience wrapper for running the test driver
|
||||
# interactively with the specified network.
|
||||
vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
|
||||
|
||||
vms = map (m: m.config.system.build.vm) (lib.attrValues nodes);
|
||||
|
||||
# Generate onvenience wrappers for running the test driver
|
||||
# interactively with the specified network, and for starting the
|
||||
# VMs from the command line.
|
||||
driver = runCommand "nixos-test-driver"
|
||||
{ buildInputs = [ makeWrapper];
|
||||
inherit testScript;
|
||||
@ -143,13 +146,18 @@ rec {
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
echo "$testScript" > $out/test-script
|
||||
ln -s ${vms}/bin/* $out/bin/
|
||||
ln -s ${testDriver}/bin/* $out/bin/
|
||||
ln -s ${testDriver}/bin/nixos-test-driver $out/bin/
|
||||
vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)"
|
||||
wrapProgram $out/bin/nixos-test-driver \
|
||||
--add-flags "${vms}/vms/*/bin/run-*-vm" \
|
||||
--add-flags "$vms" \
|
||||
--run "testScript=\"\$(cat $out/test-script)\"" \
|
||||
--set testScript '"$testScript"' \
|
||||
--set VLANS '"${toString (map (m: m.config.virtualisation.vlans) (lib.attrValues vms.nodes))}"' \
|
||||
--set VLANS '"${toString vlans}"'
|
||||
ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms
|
||||
wrapProgram $out/bin/nixos-run-vms \
|
||||
--add-flags "$vms" \
|
||||
--set tests '"startAll; sleep 1e9;"' \
|
||||
--set VLANS '"${toString vlans}"'
|
||||
''; # "
|
||||
|
||||
test = runTests driver;
|
||||
|
Loading…
Reference in New Issue
Block a user