Skip to content

Commit

Permalink
Auto fill simple table configuration
Browse files Browse the repository at this point in the history
nbarrientos committed Dec 10, 2020
1 parent f0bd879 commit fcb1d35
Showing 6 changed files with 41 additions and 10 deletions.
1 change: 0 additions & 1 deletion files/config/puppet-ip-nat.nft

This file was deleted.

1 change: 0 additions & 1 deletion files/config/puppet-ip6-nat.nft

This file was deleted.

7 changes: 6 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
@@ -38,11 +38,16 @@
source => $source,
}
} else {
if $content {
$_content = $content
} else {
$_content = " include \"${name}-chain-*.nft\""
}
concat::fragment {
"${concat_name}-body":
target => $concat_name,
order => '98',
content => $content,
content => $_content,
}
}

7 changes: 1 addition & 6 deletions manifests/ip_nat.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# manage basic chains in table ip nat
class nftables::ip_nat inherits nftables {
nftables::config {
'ip-nat':
source => 'puppet:///modules/nftables/config/puppet-ip-nat.nft';
'ip6-nat':
source => 'puppet:///modules/nftables/config/puppet-ip6-nat.nft';
}
nftables::config { ['ip-nat', 'ip6-nat']: }

nftables::chain {
[
2 changes: 2 additions & 0 deletions spec/classes/ip_nat_spec.rb
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
it {
is_expected.to contain_concat__fragment('nftables-ip-nat-body').with(
target: 'nftables-ip-nat',
content: %r{^\s+include "ip-nat-chain-\*\.nft"$},
order: '98',
)
}
@@ -63,6 +64,7 @@
it {
is_expected.to contain_concat__fragment('nftables-ip6-nat-body').with(
target: 'nftables-ip6-nat',
content: %r{^\s+include "ip6-nat-chain-\*\.nft"$},
order: '98',
)
}
33 changes: 32 additions & 1 deletion spec/defines/config_spec.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,38 @@
end

context 'with source and content both unset' do
it { is_expected.not_to compile }
it { is_expected.to compile }
it { is_expected.to contain_concat('nftables-FOO-BAR') }
it {
is_expected.to contain_concat('nftables-FOO-BAR').with(
path: '/etc/nftables/puppet-preflight/FOO-BAR.nft',
ensure_newline: true,
mode: '0640',
)
}
it { is_expected.to contain_file('/etc/nftables/puppet/FOO-BAR.nft') }
it {
is_expected.to contain_file('/etc/nftables/puppet/FOO-BAR.nft').with(
ensure: 'file',
source: '/etc/nftables/puppet-preflight/FOO-BAR.nft',
mode: '0640',
)
}
it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
it {
is_expected.to contain_concat_fragment('nftables-FOO-BAR-header').with(
target: 'nftables-FOO-BAR',
order: '00',
content: 'table FOO BAR {',
)
}
it {
is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
target: 'nftables-FOO-BAR',
order: '98',
content: ' include "FOO-BAR-chain-*.nft"',
)
}
end

context 'with a non hyphenated title' do

0 comments on commit fcb1d35

Please sign in to comment.