Skip to content

Commit

Permalink
Rely on Hiera to get var directory
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Sep 3, 2024
1 parent c8e98b6 commit b320c7a
Show file tree
Hide file tree
Showing 28 changed files with 30 additions and 50 deletions.
1 change: 1 addition & 0 deletions data/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ 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
patterndb::var_dir: /var/lib/syslog-ng
1 change: 1 addition & 0 deletions data/osfamily/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
patterndb::config_dir: /usr/local/etc/patterndb.d
patterndb::var_dir: /var/syslog-ng
1 change: 0 additions & 1 deletion examples/NOK_mismatching_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_getent.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => ['tfgetent'],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_hiera.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
use_hiera => true,
Expand Down
1 change: 0 additions & 1 deletion examples/OK_hiera_puppet5.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
use_hiera => true,
Expand Down
1 change: 0 additions & 1 deletion examples/OK_hybrid.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::raw::ruleset { 'raw':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_ltgt.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
}
Expand Down
1 change: 0 additions & 1 deletion examples/OK_modules.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => ['basicfuncs'],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_multiple_pdb.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_notest.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => ['pdbtool_test_would_fail_with_this_module'],
test_before_deploy => false,
}
Expand Down
1 change: 0 additions & 1 deletion examples/OK_raw.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => [],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_s.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Patterndb::Simple::Rule {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_rules.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'empty_ruleset':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_rules_and_actions.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_coerce.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'plop':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_context.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_empty.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'empty':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_yum.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp',
syslogng_modules => [],
test_before_deploy => true,
}
Expand Down
18 changes: 8 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class patterndb (
String[1] $package_name,
Stdlib::Absolutepath $config_dir,
Stdlib::Absolutepath $var_dir,
Stdlib::Absolutepath $cache_dir = '/var/cache/syslog-ng',
String[1] $base_dir = '/',
Boolean $manage_package = true,
Array[String[1]] $syslogng_modules = [],
Boolean $use_hiera = false,
Expand All @@ -15,17 +15,15 @@
}
ensure_resource ( 'file', $cache_dir, { ensure => directory })
ensure_resource (
'file', "${base_dir}/var/lib/syslog-ng",
'file', $var_dir,
{ ensure => 'directory' }
)
ensure_resource (
'file', "${base_dir}/var/lib/syslog-ng/patterndb",
{
ensure => 'directory',
purge => true,
recurse => true
}
)
file { "${var_dir}/patterndb":
ensure => 'directory',
purge => true,
recurse => true,
}

file { $config_dir:
ensure => directory,
purge => true,
Expand Down
4 changes: 2 additions & 2 deletions manifests/parser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
})
ensure_resource ('file', "patterndb::file::${name}", {
'ensure' => 'present',
'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
'path' => "${patterndb::var_dir}/patterndb/${name}.xml"
})
exec { "patterndb::merge::${name}":
command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::cache_dir}/patterndb/${name}.xml",
Expand All @@ -44,7 +44,7 @@
}

exec { "patterndb::deploy::${name}":
command => "cp ${patterndb::cache_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/",
command => "cp ${patterndb::cache_dir}/patterndb/${name}.xml ${patterndb::var_dir}/patterndb/",
logoutput => true,
path => $facts['path'],
refreshonly => true,
Expand Down
10 changes: 5 additions & 5 deletions spec/defines/raw_ruleset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'myrawruleset'
end
let :pre_condition do
'class { "patterndb": base_dir => "BASEDIR", }'
'class { "patterndb": }'
end

context 'Raw ruleset with no params' do
Expand All @@ -33,9 +33,9 @@

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

Expand All @@ -49,9 +49,9 @@

case facts[:osfamily]
when 'FreeBSD'
it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') }
it { is_expected.to contain_file('/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') }
it { is_expected.to contain_file('/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/simple_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
end
let :pre_condition do
'class { "patterndb": base_dir => "/BASEDIR", }
'class { "patterndb": }
patterndb::simple::ruleset { "myruleset":
id => "RULESET_ID",
pubdate => "1970-01-01",
Expand Down
6 changes: 3 additions & 3 deletions spec/defines/simple_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
end
let :pre_condition do
'class { "patterndb": base_dir => "/BASEDIR", }
'class { "patterndb": }
patterndb::simple::ruleset { "myruleset":
id => "RULESET_ID",
pubdate => "1970-01-01",
Expand Down Expand Up @@ -78,13 +78,13 @@
when 'FreeBSD'
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with(
path: '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb'
path: '/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'
path: '/etc/syslog-ng/patterndb.d/default/myruleset.pdb'
)
}
end
Expand Down
18 changes: 9 additions & 9 deletions spec/defines/simple_ruleset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
end
let :pre_condition do
'class { "patterndb": base_dir => "/BASEDIR", }
'class { "patterndb": }
Exec { path => ["/bin","/usr/bin"] }'
end

Expand Down Expand Up @@ -61,9 +61,9 @@

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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/myruleset.pdb') }
end
it {
is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content(
Expand All @@ -86,9 +86,9 @@

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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/myruleset.pdb') }
end
it {
is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').that_notifies(
Expand Down Expand Up @@ -148,9 +148,9 @@

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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') }
end

it {
Expand Down Expand Up @@ -322,9 +322,9 @@

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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/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') }
it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') }
end
it {
is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content(
Expand Down

0 comments on commit b320c7a

Please sign in to comment.