Projet

Général

Profil

Révision e4c32222

IDe4c322229612b708ab6e07baf719ca4bd2f61d91
Parent 18ec6f48
Enfant 20b96360

Ajouté par Nacho Barrientos il y a plus de 4 ans

Use concat for table conf generation

This way other components of the module will be able to add extra stuff
to the table definitions like sets.

Voir les différences:

files/config/puppet-inet-filter.nft
1
table inet filter {
2 1
  include "/etc/nftables/puppet/inet-filter-chain-*.nft"
3 2

  
4 3
  # something we want for all
......
11 10
    ip protocol icmp icmp type echo-request limit rate 4/second accept
12 11
    ip6 nexthdr ipv6-icmp icmpv6 type echo-request limit rate 4/second accept
13 12
  }
14
}
files/config/puppet-ip-nat.nft
1
table ip nat {
2 1
  include "/etc/nftables/puppet/ip-nat-chain-*.nft"
3
}
files/config/puppet-ip6-nat.nft
1
table ip6 nat {
2 1
  include "/etc/nftables/puppet/ip6-nat-chain-*.nft"
3
}
manifests/config.pp
5 5
  Optional[Variant[String,Array[String,1]]]
6 6
    $source = undef,
7 7
){
8
  Package['nftables'] -> file{
9
    "/etc/nftables/puppet/${name}.nft":
10
      ensure => file,
11
      owner  => root,
12
      group  => root,
13
      mode   => '0640',
8
  $concat_name = "nftables-${name}"
9

  
10
  Package['nftables'] -> concat{
11
    $concat_name:
12
      path           => "/etc/nftables/puppet/${name}.nft",
13
      ensure_newline => true,
14
      owner          => root,
15
      group          => root,
16
      mode           => '0640',
14 17
  } ~> Service['nftables']
15 18

  
19
  $data = split($name, '-')
20

  
21
  concat::fragment {
22
    "${concat_name}-header":
23
      target  => $concat_name,
24
      order   => '00',
25
      content => "table ${data[0]} ${data[1]} {",
26
  }
27

  
16 28
  if $source {
17
    File["/etc/nftables/puppet/${name}.nft"]{
18
      source => $source,
29
    concat::fragment {
30
      "${concat_name}-body":
31
        target => $concat_name,
32
        order  => 98,
33
        source => $source,
19 34
    }
20 35
  } else {
21
    File["/etc/nftables/puppet/${name}.nft"]{
22
      content => $content,
36
    concat::fragment {
37
      "${concat_name}-body":
38
        target  => $concat_name,
39
        order   => '98',
40
        content => $content,
23 41
    }
24 42
  }
43

  
44
  concat::fragment {
45
    "${concat_name}-footer":
46
      target  => $concat_name,
47
      order   => '99',
48
      content => '}',
49
  }
25 50
}
spec/classes/inet_filter_spec.rb
10 10
      it { is_expected.to compile }
11 11

  
12 12
      it {
13
        is_expected.to contain_file('/etc/nftables/puppet/inet-filter.nft').with(
14
          ensure: 'file',
13
        is_expected.to contain_concat('nftables-inet-filter').with(
14
          path:   '/etc/nftables/puppet/inet-filter.nft',
15
          ensure: 'present',
15 16
          owner:  'root',
16 17
          group:  'root',
17 18
          mode:   '0640',
18 19
        )
19 20
      }
20 21

  
22
      it {
23
        is_expected.to contain_concat__fragment('nftables-inet-filter-header').with(
24
          target:  'nftables-inet-filter',
25
          content: %r{^table inet filter \{$},
26
          order:   '00',
27
        )
28
      }
29

  
30
      it {
31
        is_expected.to contain_concat__fragment('nftables-inet-filter-body').with(
32
          target:  'nftables-inet-filter',
33
          order:   '98',
34
        )
35
      }
36

  
37
      it {
38
        is_expected.to contain_concat__fragment('nftables-inet-filter-footer').with(
39
          target:  'nftables-inet-filter',
40
          content: %r{^\}$},
41
          order:   '99',
42
        )
43
      }
44

  
21 45
      context 'chain input' do
22 46
        it {
23 47
          is_expected.to contain_concat('nftables-inet-filter-chain-INPUT').with(
spec/classes/ip_nat_spec.rb
10 10
      it { is_expected.to compile }
11 11

  
12 12
      it {
13
        is_expected.to contain_file('/etc/nftables/puppet/ip-nat.nft').with(
14
          ensure: 'file',
13
        is_expected.to contain_concat('nftables-ip-nat').with(
14
          path:   '/etc/nftables/puppet/ip-nat.nft',
15
          ensure: 'present',
15 16
          owner:  'root',
16 17
          group:  'root',
17 18
          mode:   '0640',
......
19 20
      }
20 21

  
21 22
      it {
22
        is_expected.to contain_file('/etc/nftables/puppet/ip6-nat.nft').with(
23
          ensure: 'file',
23
        is_expected.to contain_concat__fragment('nftables-ip-nat-header').with(
24
          target:  'nftables-ip-nat',
25
          content: %r{^table ip nat \{$},
26
          order:   '00',
27
        )
28
      }
29

  
30
      it {
31
        is_expected.to contain_concat__fragment('nftables-ip-nat-body').with(
32
          target:  'nftables-ip-nat',
33
          order:   '98',
34
        )
35
      }
36

  
37
      it {
38
        is_expected.to contain_concat__fragment('nftables-ip-nat-footer').with(
39
          target:  'nftables-ip-nat',
40
          content: %r{^\}$},
41
          order:   '99',
42
        )
43
      }
44

  
45
      it {
46
        is_expected.to contain_concat('nftables-ip6-nat').with(
47
          path:   '/etc/nftables/puppet/ip6-nat.nft',
48
          ensure: 'present',
24 49
          owner:  'root',
25 50
          group:  'root',
26 51
          mode:   '0640',
27 52
        )
28 53
      }
29 54

  
55
      it {
56
        is_expected.to contain_concat__fragment('nftables-ip6-nat-header').with(
57
          target:  'nftables-ip6-nat',
58
          content: %r{^table ip6 nat \{$},
59
          order:   '00',
60
        )
61
      }
62

  
63
      it {
64
        is_expected.to contain_concat__fragment('nftables-ip6-nat-body').with(
65
          target:  'nftables-ip6-nat',
66
          order:   '98',
67
        )
68
      }
69

  
70
      it {
71
        is_expected.to contain_concat__fragment('nftables-ip6-nat-footer').with(
72
          target:  'nftables-ip6-nat',
73
          content: %r{^\}$},
74
          order:   '99',
75
        )
76
      }
77

  
30 78
      context 'table ip nat chain prerouting' do
31 79
        it {
32 80
          is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(

Formats disponibles : Unified diff