* 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:
Eelco Dolstra 2011-01-16 14:21:47 +00:00
parent ef54cd3d1f
commit 066f76e65f
2 changed files with 23 additions and 47 deletions

View File

@ -12,42 +12,10 @@ rec {
# Build a virtual network from an attribute set `{ machine1 = # Build a virtual network from an attribute set `{ machine1 =
# config1; ... machineN = configN; }', where `machineX' is the # config1; ... machineN = configN; }', where `machineX' is the
# hostname and `configX' is a NixOS system configuration. The # hostname and `configX' is a NixOS system configuration. Each
# result is a script that starts a QEMU instance for each virtual # machine is given an arbitrary IP address in the virtual network.
# machine. Each machine is given an arbitrary IP address in the
# virtual network.
buildVirtualNetwork = buildVirtualNetwork =
{ nodes }: nodes: let nodesOut = lib.mapAttrs (n: buildVM nodesOut) (assignIPAddresses nodes); in nodesOut;
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_; };
};
buildVM = buildVM =

View File

@ -121,21 +121,24 @@ rec {
call = f: f { inherit pkgs nixpkgs system; }; call = f: f { inherit pkgs nixpkgs system; };
complete = t: t // rec { complete = t: t // rec {
nodes = nodes = buildVirtualNetwork (
if t ? nodes then t.nodes else if t ? nodes then t.nodes else
if t ? machine then { machine = t.machine; } if t ? machine then { machine = t.machine; }
else { }; else { } );
vms = buildVirtualNetwork { inherit nodes; };
testScript = testScript =
# Call the test script with the computed nodes. # Call the test script with the computed nodes.
if builtins.isFunction t.testScript if builtins.isFunction t.testScript
then t.testScript { inherit (vms) nodes; } then t.testScript { inherit nodes; }
else t.testScript; else t.testScript;
# Generate a convenience wrapper for running the test driver vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
# interactively with the specified network.
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" driver = runCommand "nixos-test-driver"
{ buildInputs = [ makeWrapper]; { buildInputs = [ makeWrapper];
inherit testScript; inherit testScript;
@ -143,13 +146,18 @@ rec {
'' ''
mkdir -p $out/bin mkdir -p $out/bin
echo "$testScript" > $out/test-script echo "$testScript" > $out/test-script
ln -s ${vms}/bin/* $out/bin/ ln -s ${testDriver}/bin/nixos-test-driver $out/bin/
ln -s ${testDriver}/bin/* $out/bin/ vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)"
wrapProgram $out/bin/nixos-test-driver \ wrapProgram $out/bin/nixos-test-driver \
--add-flags "${vms}/vms/*/bin/run-*-vm" \ --add-flags "$vms" \
--run "testScript=\"\$(cat $out/test-script)\"" \ --run "testScript=\"\$(cat $out/test-script)\"" \
--set testScript '"$testScript"' \ --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; test = runTests driver;