root / spec / acceptance / default_spec.rb @ c82b960a
Historique | Voir | Annoter | Télécharger (4,57 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 | describe file('/etc/nftables/puppet.nft') do |
||
44 | it { is_expected.to be_file } |
||
45 | end
|
||
46 | |||
47 | ce22630b | Steve Traylen | describe file('/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
48 | it { is_expected.to be_file } |
||
49 | end
|
||
50 | |||
51 | bd5145ab | Steve Traylen | describe file('/etc/nftables/puppet') do |
52 | it { is_expected.to be_directory } |
||
53 | end
|
||
54 | end
|
||
55 | c82b960a | Steve Traylen | |
56 | d8752442 | Steve Traylen | context 'with bad invalid nft rules' do |
57 | it 'puppet fails but should leave nft service running' do |
||
58 | pp = <<-EOS |
||
59 | class{'nftables':
|
||
60 | firewalld_enable => false,
|
||
61 | }
|
||
62 | nftables::rule{'default_out-junk':
|
||
63 | content => 'A load of junk',
|
||
64 | }
|
||
65 | # nftables cannot be started in docker so replace service with a validation only.
|
||
66 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
67 | ensure => present,
|
||
68 | unit => "nftables.service",
|
||
69 | content => [
|
||
70 | "[Service]",
|
||
71 | "ExecStart=",
|
||
72 | "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
73 | "ExecReload=",
|
||
74 | "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
75 | "",
|
||
76 | ].join("\n"),
|
||
77 | notify => Service["nftables"],
|
||
78 | }
|
||
79 | EOS
|
||
80 | apply_manifest(pp, expect_failures: true) |
||
81 | end
|
||
82 | c82b960a | Steve Traylen | |
83 | d8752442 | Steve Traylen | describe service('nftables') do |
84 | it { is_expected.to be_running } |
||
85 | it { is_expected.to be_enabled } |
||
86 | end
|
||
87 | end
|
||
88 | c82b960a | Steve Traylen | |
89 | 7b9d6ffc | Nacho Barrientos | context 'with totally empty firewall' do |
90 | it 'no rules validate okay' do |
||
91 | pp = <<-EOS |
||
92 | class{'nftables':
|
||
93 | firewalld_enable => false,
|
||
94 | inet_filter => false,
|
||
95 | nat => false,
|
||
96 | }
|
||
97 | # nftables cannot be started in docker so replace service with a validation only.
|
||
98 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
99 | ensure => present,
|
||
100 | unit => "nftables.service",
|
||
101 | content => [
|
||
102 | "[Service]",
|
||
103 | "ExecStart=",
|
||
104 | "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
105 | "ExecReload=",
|
||
106 | "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
107 | "",
|
||
108 | ].join("\n"),
|
||
109 | notify => Service["nftables"],
|
||
110 | }
|
||
111 | EOS
|
||
112 | apply_manifest(pp, catch_failures: true) |
||
113 | end
|
||
114 | c82b960a | Steve Traylen | |
115 | 7b9d6ffc | Nacho Barrientos | describe service('nftables') do |
116 | it { is_expected.to be_running } |
||
117 | it { is_expected.to be_enabled } |
||
118 | end
|
||
119 | end
|
||
120 | c82b960a | Steve Traylen | |
121 | fcb79d73 | Ben Morrice | context 'with custom nat_table_name' do |
122 | it 'no rules validate okay' do |
||
123 | pp = <<-EOS |
||
124 | class{'nftables':
|
||
125 | firewalld_enable => false,
|
||
126 | nat => true,
|
||
127 | nat_table_name => 'mycustomtablename',
|
||
128 | }
|
||
129 | # nftables cannot be started in docker so replace service with a validation only.
|
||
130 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
131 | ensure => present,
|
||
132 | unit => "nftables.service",
|
||
133 | content => [
|
||
134 | "[Service]",
|
||
135 | "ExecStart=",
|
||
136 | "ExecStart=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
137 | "ExecReload=",
|
||
138 | "ExecReload=/sbin/nft -c -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf",
|
||
139 | "",
|
||
140 | ].join("\n"),
|
||
141 | notify => Service["nftables"],
|
||
142 | }
|
||
143 | EOS
|
||
144 | apply_manifest(pp, catch_failures: true) |
||
145 | end
|
||
146 | c82b960a | Steve Traylen | |
147 | fcb79d73 | Ben Morrice | describe service('nftables') do |
148 | it { is_expected.to be_running } |
||
149 | it { is_expected.to be_enabled } |
||
150 | end
|
||
151 | end
|
||
152 | bd5145ab | Steve Traylen | end |