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