diff --git a/lib/build-vms.nix b/lib/build-vms.nix index a84f55435c8..a32e1448939 100644 --- a/lib/build-vms.nix +++ b/lib/build-vms.nix @@ -45,6 +45,7 @@ rec { EOF chmod +x $out/bin/run-vms ''; # */ + passthru = { nodes = nodes_; }; }; diff --git a/lib/testing.nix b/lib/testing.nix index 3a33ca69f08..f2cc29a33eb 100644 --- a/lib/testing.nix +++ b/lib/testing.nix @@ -95,17 +95,19 @@ rec { if t ? machine then { machine = t.machine; } else { }; 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; }; - runInMachine = { - drv - , machine - , preBuild ? "" - , postBuild ? "" - , ... - }: + runInMachine = + { drv + , machine + , preBuild ? "" + , postBuild ? "" + , ... + }: let vms = buildVirtualNetwork { nodes = { client = machine; } ; }; diff --git a/tests/bittorrent.nix b/tests/bittorrent.nix index ac42fb33a85..051454da5cc 100644 --- a/tests/bittorrent.nix +++ b/tests/bittorrent.nix @@ -13,10 +13,10 @@ let # Some random file to serve. file = pkgs.nixUnstable.src; - miniupnpdConf = pkgs.writeText "miniupnpd.conf" + miniupnpdConf = nodes: pkgs.writeText "miniupnpd.conf" '' 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 ''; @@ -56,6 +56,7 @@ in }; testScript = + { nodes, ... }: '' startAll; @@ -63,11 +64,12 @@ in $router->mustSucceed( "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 -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 -A PREROUTING -i eth1 -j MINIUPNPD", "echo 1 > /proc/sys/net/ipv4/ip_forward", - "miniupnpd -f ${miniupnpdConf}" + "miniupnpd -f ${miniupnpdConf nodes}" ); # Create the torrent. diff --git a/tests/nat.nix b/tests/nat.nix index 7f2d8c6432f..88aa609774f 100644 --- a/tests/nat.nix +++ b/tests/nat.nix @@ -31,6 +31,7 @@ }; testScript = + { nodes, ... }: '' startAll; @@ -45,7 +46,8 @@ $router->mustSucceed( "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 -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" );