From 89c7ea8c8b6b3996f2ccc5412faa0b065122dff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 15:15:34 -1000 Subject: [PATCH] Rely on Hiera to get var directory --- data/default.yaml | 1 + data/osfamily/FreeBSD.yaml | 1 + manifests/init.pp | 18 ++++++++---------- manifests/parser.pp | 4 ++-- spec/defines/raw_ruleset_spec.rb | 10 +++++----- spec/defines/simple_action_spec.rb | 2 +- spec/defines/simple_rule_spec.rb | 6 +++--- spec/defines/simple_ruleset_spec.rb | 18 +++++++++--------- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/data/default.yaml b/data/default.yaml index 91348fd..a72a3e9 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -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 diff --git a/data/osfamily/FreeBSD.yaml b/data/osfamily/FreeBSD.yaml index b4b0ef7..ec4f07d 100644 --- a/data/osfamily/FreeBSD.yaml +++ b/data/osfamily/FreeBSD.yaml @@ -1,2 +1,3 @@ --- patterndb::config_dir: /usr/local/etc/patterndb.d +patterndb::var_dir: /var/syslog-ng diff --git a/manifests/init.pp b/manifests/init.pp index d439f86..3d41364 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, @@ -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, diff --git a/manifests/parser.pp b/manifests/parser.pp index af2261f..dde73b9 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -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", @@ -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, diff --git a/spec/defines/raw_ruleset_spec.rb b/spec/defines/raw_ruleset_spec.rb index f2ea1cb..0cab2b2 100644 --- a/spec/defines/raw_ruleset_spec.rb +++ b/spec/defines/raw_ruleset_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/defines/simple_action_spec.rb b/spec/defines/simple_action_spec.rb index 7a5ab10..6a65606 100644 --- a/spec/defines/simple_action_spec.rb +++ b/spec/defines/simple_action_spec.rb @@ -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", diff --git a/spec/defines/simple_rule_spec.rb b/spec/defines/simple_rule_spec.rb index f65d0f2..ce2470b 100644 --- a/spec/defines/simple_rule_spec.rb +++ b/spec/defines/simple_rule_spec.rb @@ -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", @@ -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 diff --git a/spec/defines/simple_ruleset_spec.rb b/spec/defines/simple_ruleset_spec.rb index 3f94b3a..10a5a9f 100644 --- a/spec/defines/simple_ruleset_spec.rb +++ b/spec/defines/simple_ruleset_spec.rb @@ -20,7 +20,7 @@ } end let :pre_condition do - 'class { "patterndb": base_dir => "/BASEDIR", } + 'class { "patterndb": } Exec { path => ["/bin","/usr/bin"] }' end @@ -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( @@ -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( @@ -147,9 +147,9 @@ it { is_expected.to contain_patterndb__parser('PARSER') } 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 { @@ -321,9 +321,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(