root / spec / acceptance / default_spec.rb @ 331b8d85
Historique | Voir | Annoter | Télécharger (5,66 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 | 8842a597 | Tim Meusel | $config_path = $facts['os']['family'] ? {
|
15 | 'Archlinux' => '/etc/nftables.conf',
|
||
16 | 008c95d7 | Kienan Stewart | 'Debian' => '/etc/nftables.conf',
|
17 | 8842a597 | Tim Meusel | default => '/etc/sysconfig/nftables.conf',
|
18 | }
|
||
19 | $nft_path = $facts['os']['family'] ? {
|
||
20 | 'Archlinux' => '/usr/bin/nft',
|
||
21 | default => '/usr/sbin/nft',
|
||
22 | 0c9bc308 | hashworks | }
|
23 | bd5145ab | Steve Traylen | # nftables cannot be started in docker so replace service with a validation only.
|
24 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
25 | ensure => present,
|
||
26 | unit => "nftables.service",
|
||
27 | content => [
|
||
28 | "[Service]",
|
||
29 | "ExecStart=",
|
||
30 | 8842a597 | Tim Meusel | "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
31 | bd5145ab | Steve Traylen | "ExecReload=",
|
32 | 8842a597 | Tim Meusel | "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
33 | bd5145ab | Steve Traylen | "",
|
34 | ].join("\n"),
|
||
35 | notify => Service["nftables"],
|
||
36 | }
|
||
37 | EOS
|
||
38 | # Run it twice and test for idempotency
|
||
39 | apply_manifest(pp, catch_failures: true) |
||
40 | apply_manifest(pp, catch_changes: true) |
||
41 | end
|
||
42 | |||
43 | describe package('nftables') do |
||
44 | it { is_expected.to be_installed } |
||
45 | end
|
||
46 | |||
47 | describe service('nftables') do |
||
48 | it { is_expected.to be_running } |
||
49 | it { is_expected.to be_enabled } |
||
50 | end
|
||
51 | |||
52 | b5874974 | Steve Traylen | describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
53 | ce22630b | Steve Traylen | it { is_expected.to be_file } |
54 | end
|
||
55 | |||
56 | bd5145ab | Steve Traylen | describe file('/etc/nftables/puppet') do |
57 | it { is_expected.to be_directory } |
||
58 | end
|
||
59 | end
|
||
60 | c82b960a | Steve Traylen | |
61 | d8752442 | Steve Traylen | context 'with bad invalid nft rules' do |
62 | it 'puppet fails but should leave nft service running' do |
||
63 | pp = <<-EOS |
||
64 | class{'nftables':
|
||
65 | firewalld_enable => false,
|
||
66 | }
|
||
67 | nftables::rule{'default_out-junk':
|
||
68 | content => 'A load of junk',
|
||
69 | }
|
||
70 | 8842a597 | Tim Meusel | $config_path = $facts['os']['family'] ? {
|
71 | 'Archlinux' => '/etc/nftables.conf',
|
||
72 | 008c95d7 | Kienan Stewart | 'Debian' => '/etc/nftables.conf',
|
73 | 8842a597 | Tim Meusel | default => '/etc/sysconfig/nftables.conf',
|
74 | }
|
||
75 | $nft_path = $facts['os']['family'] ? {
|
||
76 | 'Archlinux' => '/usr/bin/nft',
|
||
77 | default => '/usr/sbin/nft',
|
||
78 | 0c9bc308 | hashworks | }
|
79 | d8752442 | Steve Traylen | # nftables cannot be started in docker so replace service with a validation only.
|
80 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
81 | ensure => present,
|
||
82 | unit => "nftables.service",
|
||
83 | content => [
|
||
84 | "[Service]",
|
||
85 | "ExecStart=",
|
||
86 | 8842a597 | Tim Meusel | "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
87 | d8752442 | Steve Traylen | "ExecReload=",
|
88 | 8842a597 | Tim Meusel | "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
89 | d8752442 | Steve Traylen | "",
|
90 | ].join("\n"),
|
||
91 | notify => Service["nftables"],
|
||
92 | }
|
||
93 | EOS
|
||
94 | apply_manifest(pp, expect_failures: true) |
||
95 | end
|
||
96 | c82b960a | Steve Traylen | |
97 | d8752442 | Steve Traylen | describe service('nftables') do |
98 | it { is_expected.to be_running } |
||
99 | it { is_expected.to be_enabled } |
||
100 | end
|
||
101 | end
|
||
102 | c82b960a | Steve Traylen | |
103 | 7b9d6ffc | Nacho Barrientos | context 'with totally empty firewall' do |
104 | it 'no rules validate okay' do |
||
105 | pp = <<-EOS |
||
106 | class{'nftables':
|
||
107 | firewalld_enable => false,
|
||
108 | inet_filter => false,
|
||
109 | nat => false,
|
||
110 | }
|
||
111 | 8842a597 | Tim Meusel | $config_path = $facts['os']['family'] ? {
|
112 | 'Archlinux' => '/etc/nftables.conf',
|
||
113 | 008c95d7 | Kienan Stewart | 'Debian' => '/etc/nftables.conf',
|
114 | 8842a597 | Tim Meusel | default => '/etc/sysconfig/nftables.conf',
|
115 | }
|
||
116 | $nft_path = $facts['os']['family'] ? {
|
||
117 | 'Archlinux' => '/usr/bin/nft',
|
||
118 | default => '/usr/sbin/nft',
|
||
119 | 0c9bc308 | hashworks | }
|
120 | 7b9d6ffc | Nacho Barrientos | # nftables cannot be started in docker so replace service with a validation only.
|
121 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
122 | ensure => present,
|
||
123 | unit => "nftables.service",
|
||
124 | content => [
|
||
125 | "[Service]",
|
||
126 | "ExecStart=",
|
||
127 | 8842a597 | Tim Meusel | "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
128 | 7b9d6ffc | Nacho Barrientos | "ExecReload=",
|
129 | 8842a597 | Tim Meusel | "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
130 | 7b9d6ffc | Nacho Barrientos | "",
|
131 | ].join("\n"),
|
||
132 | notify => Service["nftables"],
|
||
133 | }
|
||
134 | EOS
|
||
135 | apply_manifest(pp, catch_failures: true) |
||
136 | end
|
||
137 | c82b960a | Steve Traylen | |
138 | 7b9d6ffc | Nacho Barrientos | describe service('nftables') do |
139 | it { is_expected.to be_running } |
||
140 | it { is_expected.to be_enabled } |
||
141 | end
|
||
142 | end
|
||
143 | c82b960a | Steve Traylen | |
144 | fcb79d73 | Ben Morrice | context 'with custom nat_table_name' do |
145 | it 'no rules validate okay' do |
||
146 | pp = <<-EOS |
||
147 | class{'nftables':
|
||
148 | firewalld_enable => false,
|
||
149 | nat => true,
|
||
150 | nat_table_name => 'mycustomtablename',
|
||
151 | }
|
||
152 | 8842a597 | Tim Meusel | $config_path = $facts['os']['family'] ? {
|
153 | 'Archlinux' => '/etc/nftables.conf',
|
||
154 | 008c95d7 | Kienan Stewart | 'Debian' => '/etc/nftables.conf',
|
155 | 8842a597 | Tim Meusel | default => '/etc/sysconfig/nftables.conf',
|
156 | }
|
||
157 | $nft_path = $facts['os']['family'] ? {
|
||
158 | 'Archlinux' => '/usr/bin/nft',
|
||
159 | default => '/usr/sbin/nft',
|
||
160 | 0c9bc308 | hashworks | }
|
161 | fcb79d73 | Ben Morrice | # nftables cannot be started in docker so replace service with a validation only.
|
162 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
163 | ensure => present,
|
||
164 | unit => "nftables.service",
|
||
165 | content => [
|
||
166 | "[Service]",
|
||
167 | "ExecStart=",
|
||
168 | 8842a597 | Tim Meusel | "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
169 | fcb79d73 | Ben Morrice | "ExecReload=",
|
170 | 8842a597 | Tim Meusel | "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
171 | fcb79d73 | Ben Morrice | "",
|
172 | ].join("\n"),
|
||
173 | notify => Service["nftables"],
|
||
174 | }
|
||
175 | EOS
|
||
176 | apply_manifest(pp, catch_failures: true) |
||
177 | end
|
||
178 | c82b960a | Steve Traylen | |
179 | fcb79d73 | Ben Morrice | describe service('nftables') do |
180 | it { is_expected.to be_running } |
||
181 | it { is_expected.to be_enabled } |
||
182 | end
|
||
183 | end
|
||
184 | bd5145ab | Steve Traylen | end |