Skip to content

Commit

Permalink
Rely on Hiera to get the config directory
Browse files Browse the repository at this point in the history
This directory is operating-system dependant.
  • Loading branch information
smortex committed Sep 3, 2024
1 parent a65a89a commit cee5229
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion data/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ patterndb::use_hiera: false
patterndb::_manage_top_dirs: true
patterndb::test_before_deploy: &test_before_deploy true
patterndb::parser::test_before_deploy: *test_before_deploy

patterndb::config_dir: /etc/syslog-ng/patterndb.d
2 changes: 2 additions & 0 deletions data/osfamily/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
patterndb::config_dir: /usr/local/etc/patterndb.d
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
class patterndb (
String[1] $package_name,
Stdlib::Absolutepath $config_dir,
String[1] $base_dir = '/',
String[1] $temp_dir = "${base_dir}/tmp/syslog-ng",
Boolean $manage_package = true,
Expand Down Expand Up @@ -35,8 +36,7 @@
recurse => true
}
)
$pdb_dir = "${base_dir}/etc/syslog-ng/patterndb.d"
file { $pdb_dir:
file { $config_dir:
ensure => directory,
purge => true,
force => true,
Expand Down
4 changes: 2 additions & 2 deletions manifests/parser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$tmp = join($_modules,' --module=')
$modules = "--module=${tmp}"
}
ensure_resource('file', "${patterndb::pdb_dir}/${name}", {
ensure_resource('file', "${patterndb::config_dir}/${name}", {
'ensure' => 'directory',
'purge' => true,
'force' => true,
Expand All @@ -29,7 +29,7 @@
'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
})
exec { "patterndb::merge::${name}":
command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::pdb_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml",
command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml",
path => $facts['path'],
logoutput => true,
refreshonly => true,
Expand Down
4 changes: 2 additions & 2 deletions manifests/raw/ruleset.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

if $ensure == 'directory' {
file { "${patterndb::pdb_dir}/${parser}/${name}":
file { "${patterndb::config_dir}/${parser}/${name}":
ensure => $ensure,
recurse => $recurse,
mode => '0644',
Expand All @@ -31,7 +31,7 @@
notify => Exec["patterndb::merge::${parser}"],
}
} else {
file { "${patterndb::pdb_dir}/${parser}/${name}.pdb":
file { "${patterndb::config_dir}/${parser}/${name}.pdb":
ensure => $ensure,
mode => '0644',
source => $source,
Expand Down
2 changes: 1 addition & 1 deletion manifests/simple/ruleset.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}

$pdb_file = "${patterndb::pdb_dir}/${parser}/${order}${name}.pdb"
$pdb_file = "${patterndb::config_dir}/${parser}/${order}${name}.pdb"

concat { "patterndb_simple_ruleset-${title}":
path => $pdb_file,
Expand Down
20 changes: 12 additions & 8 deletions spec/defines/raw_ruleset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
}
end

it {
is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb')
}
case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset.pdb') }
else
it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb') }
end
end

context 'Raw rulesets with directory' do
Expand All @@ -44,11 +47,12 @@
}
end

it {
is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset').with(
ensure: 'directory'
)
}
case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') }
else
it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') }
end
end
end
end
Expand Down
17 changes: 14 additions & 3 deletions spec/defines/simple_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,21 @@
)
}

case facts[:osfamily]
when 'FreeBSD'
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with(
path: '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb'
)
}
else
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with(
path: '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb'
)
}
end
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with(
path: '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb'
)
is_expected.to contain_concat__fragment('patterndb_simple_rule-myrule-header').with(
target: 'patterndb_simple_ruleset-myruleset'
).with_content(
Expand Down
29 changes: 25 additions & 4 deletions spec/defines/simple_ruleset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@

it { is_expected.to contain_patterndb__parser('default') }

case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') }
else
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') }
end
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb')
is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content(
%r{<patterns>.*<pattern>P1</pattern>.*</patterns>}m
)
Expand All @@ -79,8 +84,13 @@

it { is_expected.to contain_patterndb__parser('default') }

case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') }
else
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') }
end
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb')
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').that_notifies(
'Exec[patterndb::merge::default]'
)
Expand Down Expand Up @@ -135,7 +145,13 @@

it { is_expected.not_to contain_patterndb__parser('default') }
it { is_expected.to contain_patterndb__parser('PARSER') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') }

case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/PARSER/myruleset.pdb') }
else
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') }
end

it {
is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with(
Expand Down Expand Up @@ -304,8 +320,13 @@

it { is_expected.to contain_patterndb__parser('default') }

case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/123myruleset.pdb') }
else
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') }
end
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/123myruleset.pdb')
is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content(
%r{<patterns>.*<pattern>P1</pattern>.*</patterns>}m
)
Expand Down

0 comments on commit cee5229

Please sign in to comment.