Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / spec / acceptance / default_spec.rb @ c82b960a

Historique | Voir | Annoter | Télécharger (4,57 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
      # 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
    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

    
56
  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

    
83
    describe service('nftables') do
84
      it { is_expected.to be_running }
85
      it { is_expected.to be_enabled }
86
    end
87
  end
88

    
89
  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

    
115
    describe service('nftables') do
116
      it { is_expected.to be_running }
117
      it { is_expected.to be_enabled }
118
    end
119
  end
120

    
121
  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

    
147
    describe service('nftables') do
148
      it { is_expected.to be_running }
149
      it { is_expected.to be_enabled }
150
    end
151
  end
152
end