Projet

Général

Profil

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

root / spec / acceptance / file_spec.rb @ d7d6d5d3

Historique | Voir | Annoter | Télécharger (1,84 ko)

1 331b8d85 Steve Traylen
# frozen_string_literal: true
2
3
require 'spec_helper_acceptance'
4
5
describe 'nftables class' do
6
  context 'configure a nftables::file raw file' 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::file{'geoip':
15
        content => "# A comment should not fail\n",
16
      }
17
      $config_path = $facts['os']['family'] ? {
18
        'Archlinux' => '/etc/nftables.conf',
19
        'Debian' => '/etc/nftables.conf',
20
        default => '/etc/sysconfig/nftables.conf',
21
      }
22
      $nft_path = $facts['os']['family'] ? {
23
        'Archlinux' => '/usr/bin/nft',
24
        default => '/usr/sbin/nft',
25
      }
26
      # nftables cannot be started in docker so replace service with a validation only.
27
      systemd::dropin_file{"zzz_docker_nft.conf":
28
        ensure  => present,
29
        unit    => "nftables.service",
30
        content => [
31
          "[Service]",
32
          "ExecStart=",
33
          "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
34
          "ExecReload=",
35
          "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
36
          "",
37
          ].join("\n"),
38
        notify  => Service["nftables"],
39
      }
40
      EOS
41
      # Run it twice and test for idempotency
42
      apply_manifest(pp, catch_failures: true)
43
      apply_manifest(pp, catch_changes: true)
44
    end
45
46
    describe package('nftables') do
47
      it { is_expected.to be_installed }
48
    end
49
50
    describe service('nftables') do
51
      it { is_expected.to be_running }
52
      it { is_expected.to be_enabled }
53
    end
54
55
    describe file('/etc/nftables/puppet/file-geoip.nft', '/etc/nftables/puppet/file-geoip.nft') do
56
      it { is_expected.to be_file }
57
    end
58
  end
59
end