root / spec / acceptance / set_spec.rb @ 9d02e9f8
Historique | Voir | Annoter | Télécharger (2,45 ko)
1 | 8bc8fe98 | Steve Traylen | # frozen_string_literal: true
|
---|---|---|---|
2 | |||
3 | require 'spec_helper_acceptance'
|
||
4 | |||
5 | describe 'nftables class' do |
||
6 | context 'configure an nftables set' do |
||
7 | it 'works idempotently with no errors' do |
||
8 | pending 'Debian 11 bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1063690' if (fact('os.family') == 'Debian') && (fact('os.release.major') == '11') |
||
9 | pp = <<-EOS |
||
10 | # default mask of firewalld service fails if service is not installed.
|
||
11 | # https://tickets.puppetlabs.com/browse/PUP-10814
|
||
12 | # Disable all default rules and include below explicitly
|
||
13 | class { 'nftables':
|
||
14 | firewalld_enable => false,
|
||
15 | out_ntp => false,
|
||
16 | out_http => false,
|
||
17 | out_https => false,
|
||
18 | out_icmp => false,
|
||
19 | in_ssh => false,
|
||
20 | in_icmp => false,
|
||
21 | }
|
||
22 | nftables::set{'my_test_set':
|
||
23 | type => 'ipv4_addr',
|
||
24 | elements => ['192.168.0.1', '10.0.0.2'],
|
||
25 | table => ['inet-filter', 'ip-nat'],
|
||
26 | }
|
||
27 | $config_path = $facts['os']['family'] ? {
|
||
28 | 'Archlinux' => '/etc/nftables.conf',
|
||
29 | 'Debian' => '/etc/nftables.conf',
|
||
30 | default => '/etc/sysconfig/nftables.conf',
|
||
31 | }
|
||
32 | $nft_path = $facts['os']['family'] ? {
|
||
33 | 'Archlinux' => '/usr/bin/nft',
|
||
34 | default => '/usr/sbin/nft',
|
||
35 | }
|
||
36 | # nftables cannot be started in docker so replace service with a validation only.
|
||
37 | systemd::dropin_file{"zzz_docker_nft.conf":
|
||
38 | ensure => present,
|
||
39 | unit => "nftables.service",
|
||
40 | content => [
|
||
41 | "[Service]",
|
||
42 | "ExecStart=",
|
||
43 | "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
||
44 | "ExecReload=",
|
||
45 | "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
||
46 | "",
|
||
47 | ].join("\n"),
|
||
48 | notify => Service["nftables"],
|
||
49 | }
|
||
50 | EOS
|
||
51 | # Run it twice and test for idempotency
|
||
52 | apply_manifest(pp, catch_failures: true) |
||
53 | apply_manifest(pp, catch_changes: true) |
||
54 | end
|
||
55 | |||
56 | describe package('nftables') do |
||
57 | it { is_expected.to be_installed } |
||
58 | end
|
||
59 | |||
60 | describe service('nftables') do |
||
61 | it { |
||
62 | is_expected.to be_enabled |
||
63 | is_expected.to be_running |
||
64 | } |
||
65 | end
|
||
66 | |||
67 | describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
||
68 | it { is_expected.to be_file } |
||
69 | end
|
||
70 | |||
71 | describe file('/etc/nftables/puppet') do |
||
72 | it { is_expected.to be_directory } |
||
73 | end
|
||
74 | end
|
||
75 | end |