nixos/tests/nat: use specialisations instead of multiple machines
This commit is contained in:
parent
cc536b4cb8
commit
fe0a640a85
@ -6,17 +6,6 @@
|
|||||||
import ./make-test-python.nix ({ pkgs, lib, withFirewall, nftables ? false, ... }:
|
import ./make-test-python.nix ({ pkgs, lib, withFirewall, nftables ? false, ... }:
|
||||||
let
|
let
|
||||||
unit = if nftables then "nftables" else (if withFirewall then "firewall" else "nat");
|
unit = if nftables then "nftables" else (if withFirewall then "firewall" else "nat");
|
||||||
|
|
||||||
routerBase =
|
|
||||||
lib.mkMerge [
|
|
||||||
{ virtualisation.vlans = [ 2 1 ];
|
|
||||||
networking.firewall.enable = withFirewall;
|
|
||||||
networking.firewall.filterForward = nftables;
|
|
||||||
networking.nftables.enable = nftables;
|
|
||||||
networking.nat.internalIPs = [ "192.168.1.0/24" ];
|
|
||||||
networking.nat.externalInterface = "eth1";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
name = "nat" + (lib.optionalString nftables "Nftables")
|
name = "nat" + (lib.optionalString nftables "Nftables")
|
||||||
@ -26,27 +15,27 @@ import ./make-test-python.nix ({ pkgs, lib, withFirewall, nftables ? false, ...
|
|||||||
};
|
};
|
||||||
|
|
||||||
nodes =
|
nodes =
|
||||||
{ client =
|
{
|
||||||
{ pkgs, nodes, ... }:
|
client = { lib, nodes, ... }: {
|
||||||
lib.mkMerge [
|
virtualisation.vlans = [ 1 ];
|
||||||
{ virtualisation.vlans = [ 1 ];
|
networking.defaultGateway =
|
||||||
networking.defaultGateway =
|
(lib.head nodes.router.networking.interfaces.eth2.ipv4.addresses).address;
|
||||||
(pkgs.lib.head nodes.router.networking.interfaces.eth2.ipv4.addresses).address;
|
networking.nftables.enable = nftables;
|
||||||
networking.nftables.enable = nftables;
|
};
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
router =
|
router = { lib, ... }: {
|
||||||
{ ... }: lib.mkMerge [
|
virtualisation.vlans = [ 2 1 ];
|
||||||
routerBase
|
networking.firewall.enable = withFirewall;
|
||||||
{ networking.nat.enable = true; }
|
networking.firewall.filterForward = nftables;
|
||||||
];
|
networking.nftables.enable = nftables;
|
||||||
|
networking.nat.enable = true;
|
||||||
|
networking.nat.internalIPs = [ "192.168.1.0/24" ];
|
||||||
|
networking.nat.externalInterface = "eth1";
|
||||||
|
|
||||||
routerDummyNoNat =
|
specialisation.no-nat.configuration = {
|
||||||
{ ... }: lib.mkMerge [
|
networking.nat.enable = lib.mkForce false;
|
||||||
routerBase
|
};
|
||||||
{ networking.nat.enable = false; }
|
};
|
||||||
];
|
|
||||||
|
|
||||||
server =
|
server =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
@ -59,11 +48,7 @@ import ./make-test-python.nix ({ pkgs, lib, withFirewall, nftables ? false, ...
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript =
|
testScript = ''
|
||||||
{ nodes, ... }: let
|
|
||||||
routerDummyNoNatClosure = nodes.routerDummyNoNat.system.build.toplevel;
|
|
||||||
routerClosure = nodes.router.system.build.toplevel;
|
|
||||||
in ''
|
|
||||||
client.start()
|
client.start()
|
||||||
router.start()
|
router.start()
|
||||||
server.start()
|
server.start()
|
||||||
@ -94,14 +79,14 @@ import ./make-test-python.nix ({ pkgs, lib, withFirewall, nftables ? false, ...
|
|||||||
|
|
||||||
# If we turn off NAT, the client shouldn't be able to reach the server.
|
# If we turn off NAT, the client shouldn't be able to reach the server.
|
||||||
router.succeed(
|
router.succeed(
|
||||||
"${routerDummyNoNatClosure}/bin/switch-to-configuration test 2>&1"
|
"/run/booted-system/specialisation/no-nat/bin/switch-to-configuration test 2>&1"
|
||||||
)
|
)
|
||||||
client.fail("curl -4 --fail --connect-timeout 5 http://server/ >&2")
|
client.fail("curl -4 --fail --connect-timeout 5 http://server/ >&2")
|
||||||
client.fail("ping -4 -c 1 server >&2")
|
client.fail("ping -4 -c 1 server >&2")
|
||||||
|
|
||||||
# And make sure that reloading the NAT job works.
|
# And make sure that reloading the NAT job works.
|
||||||
router.succeed(
|
router.succeed(
|
||||||
"${routerClosure}/bin/switch-to-configuration test 2>&1"
|
"/run/booted-system/bin/switch-to-configuration test 2>&1"
|
||||||
)
|
)
|
||||||
# FIXME: this should not be necessary, but nat.service is not started because
|
# FIXME: this should not be necessary, but nat.service is not started because
|
||||||
# network.target is not triggered
|
# network.target is not triggered
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user