Projet

Général

Profil

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

root / spec / acceptance / default_spec.rb @ b5874974

Historique | Voir | Annoter | Télécharger (4,51 ko)

1 c82b960a Steve Traylen
# frozen_string_literal: true
2
3 bd5145ab Steve Traylen
require 'spec_helper_acceptance'
4
5
describe 'nftables class' do
6
  context 'configure default nftables service' do
7
    it 'works idempotently with no errors' do
8
      pp = <<-EOS
9
      # default mask of firewalld service fails if service is not installed.
10
      # https://tickets.puppetlabs.com/browse/PUP-10814
11
      class { 'nftables':
12
        firewalld_enable => false,
13
      }
14
      # nftables cannot be started in docker so replace service with a validation only.
15
      systemd::dropin_file{"zzz_docker_nft.conf":
16
        ensure  => present,
17
        unit    => "nftables.service",
18
        content => [
19
          "[Service]",
20
          "ExecStart=",
21
          "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
22
          "ExecReload=",
23
          "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
24
          "",
25
          ].join("\n"),
26
        notify  => Service["nftables"],
27
      }
28
      EOS
29
      # Run it twice and test for idempotency
30
      apply_manifest(pp, catch_failures: true)
31
      apply_manifest(pp, catch_changes: true)
32
    end
33
34
    describe package('nftables') do
35
      it { is_expected.to be_installed }
36
    end
37
38
    describe service('nftables') do
39
      it { is_expected.to be_running }
40
      it { is_expected.to be_enabled }
41
    end
42
43 b5874974 Steve Traylen
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
44 ce22630b Steve Traylen
      it { is_expected.to be_file }
45
    end
46
47 bd5145ab Steve Traylen
    describe file('/etc/nftables/puppet') do
48
      it { is_expected.to be_directory }
49
    end
50
  end
51 c82b960a Steve Traylen
52 d8752442 Steve Traylen
  context 'with bad invalid nft rules' do
53
    it 'puppet fails but should leave nft service running' do
54
      pp = <<-EOS
55
      class{'nftables':
56
        firewalld_enable => false,
57
      }
58
      nftables::rule{'default_out-junk':
59
        content => 'A load of junk',
60
      }
61
      # nftables cannot be started in docker so replace service with a validation only.
62
      systemd::dropin_file{"zzz_docker_nft.conf":
63
        ensure  => present,
64
        unit    => "nftables.service",
65
        content => [
66
          "[Service]",
67
          "ExecStart=",
68
          "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
69
          "ExecReload=",
70
          "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
71
          "",
72
          ].join("\n"),
73
        notify  => Service["nftables"],
74
      }
75
      EOS
76
      apply_manifest(pp, expect_failures: true)
77
    end
78 c82b960a Steve Traylen
79 d8752442 Steve Traylen
    describe service('nftables') do
80
      it { is_expected.to be_running }
81
      it { is_expected.to be_enabled }
82
    end
83
  end
84 c82b960a Steve Traylen
85 7b9d6ffc Nacho Barrientos
  context 'with totally empty firewall' do
86
    it 'no rules validate okay' do
87
      pp = <<-EOS
88
      class{'nftables':
89
        firewalld_enable => false,
90
        inet_filter => false,
91
        nat => false,
92
      }
93
      # nftables cannot be started in docker so replace service with a validation only.
94
      systemd::dropin_file{"zzz_docker_nft.conf":
95
        ensure  => present,
96
        unit    => "nftables.service",
97
        content => [
98
          "[Service]",
99
          "ExecStart=",
100
          "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
101
          "ExecReload=",
102
          "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
103
          "",
104
          ].join("\n"),
105
        notify  => Service["nftables"],
106
      }
107
      EOS
108
      apply_manifest(pp, catch_failures: true)
109
    end
110 c82b960a Steve Traylen
111 7b9d6ffc Nacho Barrientos
    describe service('nftables') do
112
      it { is_expected.to be_running }
113
      it { is_expected.to be_enabled }
114
    end
115
  end
116 c82b960a Steve Traylen
117 fcb79d73 Ben Morrice
  context 'with custom nat_table_name' do
118
    it 'no rules validate okay' do
119
      pp = <<-EOS
120
      class{'nftables':
121
        firewalld_enable => false,
122
        nat => true,
123
        nat_table_name => 'mycustomtablename',
124
      }
125
      # nftables cannot be started in docker so replace service with a validation only.
126
      systemd::dropin_file{"zzz_docker_nft.conf":
127
        ensure  => present,
128
        unit    => "nftables.service",
129
        content => [
130
          "[Service]",
131
          "ExecStart=",
132
          "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
133
          "ExecReload=",
134
          "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
135
          "",
136
          ].join("\n"),
137
        notify  => Service["nftables"],
138
      }
139
      EOS
140
      apply_manifest(pp, catch_failures: true)
141
    end
142 c82b960a Steve Traylen
143 fcb79d73 Ben Morrice
    describe service('nftables') do
144
      it { is_expected.to be_running }
145
      it { is_expected.to be_enabled }
146
    end
147
  end
148 bd5145ab Steve Traylen
end