about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/lxd/nftables.nix
blob: e6ce4089d719d65c7b63174d41fe5a22b3300fd0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This test makes sure that lxd stops implicitly depending on iptables when
# user enabled nftables.
#
# It has been extracted from `lxd.nix` for clarity, and because switching from
# iptables to nftables requires a full reboot, which is a bit hard inside NixOS
# tests.

import ../make-test-python.nix ({ pkgs, lib, ...} : {
  name = "lxd-nftables";

  meta = {
    maintainers = lib.teams.lxc.members;
  };

  nodes.machine = { lib, ... }: {
    virtualisation = {
      lxd.enable = true;
    };

    networking = {
      firewall.enable = false;
      nftables.enable = true;
      nftables.tables."filter".family = "inet";
      nftables.tables."filter".content = ''
          chain incoming {
            type filter hook input priority 0;
            policy accept;
          }

          chain forward {
            type filter hook forward priority 0;
            policy accept;
          }

          chain output {
            type filter hook output priority 0;
            policy accept;
          }
      '';
    };
  };

  testScript = ''
    machine.wait_for_unit("network.target")

    with subtest("When nftables are enabled, lxd doesn't depend on iptables anymore"):
        machine.succeed("lsmod | grep nf_tables")
        machine.fail("lsmod | grep ip_tables")
  '';
})