root / spec / acceptance / default_spec.rb @ 04176b0e
Historique | Voir | Annoter | Télécharger (2,72 ko)
1 |
require 'spec_helper_acceptance'
|
---|---|
2 |
|
3 |
describe 'nftables class' do |
4 |
context 'configure default nftables service' do |
5 |
it 'works idempotently with no errors' do |
6 |
pp = <<-EOS |
7 |
# default mask of firewalld service fails if service is not installed.
|
8 |
# https://tickets.puppetlabs.com/browse/PUP-10814
|
9 |
class { 'nftables':
|
10 |
firewalld_enable => false,
|
11 |
}
|
12 |
# nftables cannot be started in docker so replace service with a validation only.
|
13 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
14 |
ensure => present,
|
15 |
unit => "nftables.service",
|
16 |
content => [
|
17 |
"[Service]",
|
18 |
"ExecStart=",
|
19 |
"ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
20 |
"ExecReload=",
|
21 |
"ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
22 |
"",
|
23 |
].join("\n"),
|
24 |
notify => Service["nftables"],
|
25 |
}
|
26 |
# Puppet 5 only to ensure ordering.
|
27 |
Class['systemd::systemctl::daemon_reload'] -> Service['nftables']
|
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 |
describe file('/etc/nftables/puppet.nft') do |
44 |
it { is_expected.to be_file } |
45 |
end
|
46 |
|
47 |
describe file('/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
48 |
it { is_expected.to be_file } |
49 |
end
|
50 |
|
51 |
describe file('/etc/nftables/puppet') do |
52 |
it { is_expected.to be_directory } |
53 |
end
|
54 |
end
|
55 |
context 'with bad invalid nft rules' do |
56 |
it 'puppet fails but should leave nft service running' do |
57 |
pp = <<-EOS |
58 |
class{'nftables':
|
59 |
firewalld_enable => false,
|
60 |
}
|
61 |
nftables::rule{'default_out-junk':
|
62 |
content => 'A load of junk',
|
63 |
}
|
64 |
# nftables cannot be started in docker so replace service with a validation only.
|
65 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
66 |
ensure => present,
|
67 |
unit => "nftables.service",
|
68 |
content => [
|
69 |
"[Service]",
|
70 |
"ExecStart=",
|
71 |
"ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
72 |
"ExecReload=",
|
73 |
"ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
74 |
"",
|
75 |
].join("\n"),
|
76 |
notify => Service["nftables"],
|
77 |
}
|
78 |
EOS
|
79 |
apply_manifest(pp, expect_failures: true) |
80 |
end
|
81 |
describe service('nftables') do |
82 |
it { is_expected.to be_running } |
83 |
it { is_expected.to be_enabled } |
84 |
end
|
85 |
end
|
86 |
end
|