Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / spec / acceptance / set_spec.rb @ master

Historique | Voir | Annoter | Télécharger (2,55 ko)

1 8bc8fe98 Steve Traylen
# frozen_string_literal: true
2
3
require 'spec_helper_acceptance'
4
5
describe 'nftables class' do
6
  context 'configure an nftables set' do
7
    it 'works idempotently with no errors' do
8
      pending 'Debian 11 bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1063690' if (fact('os.family') == 'Debian') && (fact('os.release.major') == '11')
9 0ea401a5 Steve Traylen
      # If this Debian 11 bug is fixed remove the special Debian 11 case in "all_rules_spec.rb" also.
10 8bc8fe98 Steve Traylen
      pp = <<-EOS
11
      # default mask of firewalld service fails if service is not installed.
12
      # https://tickets.puppetlabs.com/browse/PUP-10814
13
      # Disable all default rules and include below explicitly
14
      class { 'nftables':
15
        firewalld_enable => false,
16
        out_ntp          => false,
17
        out_http         => false,
18
        out_https        => false,
19
        out_icmp         => false,
20
        in_ssh           => false,
21
        in_icmp          => false,
22
      }
23
      nftables::set{'my_test_set':
24
        type       => 'ipv4_addr',
25
        elements   => ['192.168.0.1', '10.0.0.2'],
26
        table      => ['inet-filter', 'ip-nat'],
27
      }
28
      $config_path = $facts['os']['family'] ? {
29
        'Archlinux' => '/etc/nftables.conf',
30
        'Debian' => '/etc/nftables.conf',
31
        default => '/etc/sysconfig/nftables.conf',
32
      }
33
      $nft_path = $facts['os']['family'] ? {
34
        'Archlinux' => '/usr/bin/nft',
35
        default => '/usr/sbin/nft',
36
      }
37
      # nftables cannot be started in docker so replace service with a validation only.
38
      systemd::dropin_file{"zzz_docker_nft.conf":
39
        ensure  => present,
40
        unit    => "nftables.service",
41
        content => [
42
          "[Service]",
43
          "ExecStart=",
44
          "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
45
          "ExecReload=",
46
          "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
47
          "",
48
          ].join("\n"),
49
        notify  => Service["nftables"],
50
      }
51
      EOS
52
      # Run it twice and test for idempotency
53
      apply_manifest(pp, catch_failures: true)
54
      apply_manifest(pp, catch_changes: true)
55
    end
56
57
    describe package('nftables') do
58
      it { is_expected.to be_installed }
59
    end
60
61
    describe service('nftables') do
62
      it {
63
        is_expected.to be_enabled
64
        is_expected.to be_running
65
      }
66
    end
67
68
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
69
      it { is_expected.to be_file }
70
    end
71
72
    describe file('/etc/nftables/puppet') do
73
      it { is_expected.to be_directory }
74
    end
75
  end
76
end