* Optionally pass the computed `nodes' to the test script as a

function argument, so that the test script can refer to computed
  values such as the assigned IP addresses of the virtual machines.

svn path=/nixos/trunk/; revision=21939
This commit is contained in:
Eelco Dolstra 2010-05-21 14:31:05 +00:00
parent fa183e5472
commit dd81311714
4 changed files with 20 additions and 13 deletions

View File

@ -45,6 +45,7 @@ rec {
EOF EOF
chmod +x $out/bin/run-vms chmod +x $out/bin/run-vms
''; # */ ''; # */
passthru = { nodes = nodes_; };
}; };

View File

@ -95,17 +95,19 @@ rec {
if t ? machine then { machine = t.machine; } if t ? machine then { machine = t.machine; }
else { }; else { };
vms = buildVirtualNetwork { inherit nodes; }; vms = buildVirtualNetwork { inherit nodes; };
test = runTests vms t.testScript; test = runTests vms
# Call the test script with the computed nodes.
(if builtins.isFunction t.testScript then t.testScript { inherit (vms) nodes; } else t.testScript);
report = makeReport test; report = makeReport test;
}; };
runInMachine = { runInMachine =
drv { drv
, machine , machine
, preBuild ? "" , preBuild ? ""
, postBuild ? "" , postBuild ? ""
, ... , ...
}: }:
let let
vms = vms =
buildVirtualNetwork { nodes = { client = machine; } ; }; buildVirtualNetwork { nodes = { client = machine; } ; };

View File

@ -13,10 +13,10 @@ let
# Some random file to serve. # Some random file to serve.
file = pkgs.nixUnstable.src; file = pkgs.nixUnstable.src;
miniupnpdConf = pkgs.writeText "miniupnpd.conf" miniupnpdConf = nodes: pkgs.writeText "miniupnpd.conf"
'' ''
ext_ifname=eth1 ext_ifname=eth1
listening_ip=192.168.2.3/24 listening_ip=${nodes.router.config.networking.ifaces.eth2.ipAddress}/24
allow 1024-65535 192.168.2.0/24 1024-65535 allow 1024-65535 192.168.2.0/24 1024-65535
''; '';
@ -56,6 +56,7 @@ in
}; };
testScript = testScript =
{ nodes, ... }:
'' ''
startAll; startAll;
@ -63,11 +64,12 @@ in
$router->mustSucceed( $router->mustSucceed(
"iptables -t nat -F", "iptables -t nat -F",
"iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -d 192.168.2.0/24 -j ACCEPT", "iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -d 192.168.2.0/24 -j ACCEPT",
"iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 192.168.1.3", # !!! ugly "iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT "
. "--to-source ${nodes.router.config.networking.ifaces.eth1.ipAddress}",
"iptables -t nat -N MINIUPNPD", "iptables -t nat -N MINIUPNPD",
"iptables -t nat -A PREROUTING -i eth1 -j MINIUPNPD", "iptables -t nat -A PREROUTING -i eth1 -j MINIUPNPD",
"echo 1 > /proc/sys/net/ipv4/ip_forward", "echo 1 > /proc/sys/net/ipv4/ip_forward",
"miniupnpd -f ${miniupnpdConf}" "miniupnpd -f ${miniupnpdConf nodes}"
); );
# Create the torrent. # Create the torrent.

View File

@ -31,6 +31,7 @@
}; };
testScript = testScript =
{ nodes, ... }:
'' ''
startAll; startAll;
@ -45,7 +46,8 @@
$router->mustSucceed( $router->mustSucceed(
"iptables -t nat -F", "iptables -t nat -F",
"iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 192.168.1.0/24 -j ACCEPT", "iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 192.168.1.0/24 -j ACCEPT",
"iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 192.168.2.2", # !!! ugly "iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT "
. "--to-source ${nodes.router.config.networking.ifaces.eth1.ipAddress}",
"echo 1 > /proc/sys/net/ipv4/ip_forward" "echo 1 > /proc/sys/net/ipv4/ip_forward"
); );