Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make testing and installing rulesets more reliable #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions manifests/init.pp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why drop the purge ?

Copy link
Collaborator Author

@smortex smortex Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have managed file resources in this directory anymore. They used to be created in manifests/parser.pp on line 27. I removed them because when validation fail, we had empty files which can be merged successfully.

I think we can revert the purge / file resources if we add a dependency Exec["patterndb::deploy::${name}"] -> File["patterndb::file::${name}"] (i.e. manage the file at the very end, instead of using it to trigger validation and deployment).

I'll test this and report my findings.

Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@
'file', "${base_dir}/var/lib/syslog-ng",
{ ensure => 'directory' }
)
ensure_resource (
'file', "${base_dir}/var/lib/syslog-ng/patterndb",
{
ensure => 'directory',
purge => true,
recurse => true
}
)
file { "${base_dir}/var/lib/syslog-ng/patterndb":
ensure => 'directory',
}
$pdb_dir = "${base_dir}/etc/syslog-ng/patterndb.d"
file { $pdb_dir:
ensure => directory,
Expand Down
56 changes: 20 additions & 36 deletions manifests/parser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,38 @@
$tmp = join($_modules,' --module=')
$modules = "--module=${tmp}"
}
ensure_resource('file', "${patterndb::pdb_dir}/${name}", {
'ensure' => 'directory',
'purge' => true,
'force' => true,
'recurse' => true,
})

file { "${patterndb::pdb_dir}/${name}":
ensure => 'directory',
force => true,
recurse => true,
purge => true,
}

ensure_resource ('file', "${patterndb::temp_dir}/patterndb", {
'ensure' => 'directory',
})
ensure_resource ('file', "patterndb::file::${name}", {
'ensure' => 'present',
'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
})

$_test_before_deploy = $test_before_deploy.lest || { $patterndb::test_before_deploy }

exec { "patterndb::merge::${name}":
command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::pdb_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml",
path => $facts['path'],
logoutput => true,
refreshonly => true,
}

exec { "patterndb::test::${name}":
#command => "/usr/bin/pdbtool --validate test ${::patterndb::temp_dir}/patterndb/${name}.xml $modules",
command => "pdbtool test ${patterndb::temp_dir}/patterndb/${name}.xml ${modules}",
path => $facts['path'],
logoutput => true,
refreshonly => true,
$deploy_command = if $_test_before_deploy {
"pdbtool test ${patterndb::temp_dir}/patterndb/${name}.xml ${modules} && cp ${patterndb::temp_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
} else {
"cp ${patterndb::temp_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
}

exec { "patterndb::deploy::${name}":
command => "cp ${patterndb::temp_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/",
logoutput => true,
path => $facts['path'],
refreshonly => true,
}
if $test_before_deploy =~ Undef {
$_test_before_deploy = $patterndb::test_before_deploy
} else {
$_test_before_deploy = $test_before_deploy
}
if $_test_before_deploy {
File["patterndb::file::${name}"]
~> Exec["patterndb::merge::${name}"]
~> Exec["patterndb::test::${name}"]
~> Exec["patterndb::deploy::${name}"]
} else {
File["patterndb::file::${name}"]
~> Exec["patterndb::merge::${name}"]
# we won't 'pdbtool test' the merged file before deploying
~> Exec["patterndb::deploy::${name}"]
command => $deploy_command,
path => $facts['path'],
logoutput => true,
onlyif => "[ ! -f ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml -o ${patterndb::temp_dir}/patterndb/${name}.xml -nt ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml ]",
require => Exec["patterndb::merge::${name}"],
}
}
37 changes: 15 additions & 22 deletions spec/defines/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
context 'Catchall' do
it { is_expected.to contain_class('Patterndb') }
it { is_expected.to contain_exec('patterndb::merge::default') }

it {
is_expected.to contain_file('patterndb::file::default').with(
'ensure' => 'present'
).that_notifies('Exec[patterndb::merge::default]')
}
end

context 'Default values (no parameters)' do
Expand All @@ -33,8 +27,8 @@
end

it {
is_expected.to contain_exec('patterndb::test::default').with(
'command' => %r{patterndb/default\.xml $}m
is_expected.to contain_exec('patterndb::deploy::default').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
)
}
end
Expand All @@ -47,8 +41,8 @@
end

it {
is_expected.to contain_exec('patterndb::test::default').with(
'command' => %r{patterndb/default\.xml --module=foo --module=bar$}m
is_expected.to contain_exec('patterndb::deploy::default').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml --module=foo --module=bar && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
)
}
end
Expand All @@ -59,14 +53,14 @@
end

it {
is_expected.to contain_exec('patterndb::test::default').with(
'command' => %r{patterndb/default\.xml $}m
is_expected.to contain_exec('patterndb::deploy::default').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
)
}

it {
is_expected.to contain_exec('patterndb::test::stage1').with(
'command' => %r{patterndb/stage1\.xml $}m
is_expected.to contain_exec('patterndb::deploy::stage1').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/stage1.xml && cp /tmp/syslog-ng/patterndb/stage1.xml //var/lib/syslog-ng/patterndb/stage1.xml'
)
}
end
Expand All @@ -78,8 +72,8 @@
end

it {
is_expected.to contain_exec('patterndb::test::default').with(
'command' => %r{patterndb/default\.xml --module=foo --module=bar$}m
is_expected.to contain_exec('patterndb::deploy::default').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml --module=foo --module=bar && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
)
}
end
Expand All @@ -90,20 +84,20 @@
end

it {
is_expected.to contain_exec('patterndb::test::default').with(
'command' => %r{patterndb/default\.xml $}m
is_expected.to contain_exec('patterndb::deploy::default').with(
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
)
}
end

context 'Without test_before_deploy' do
context 'Without deploy' do
let :params do
{
test_before_deploy: false,
}
end

it { is_expected.to contain_exec('patterndb::merge::default').that_notifies('Exec[patterndb::deploy::default]') }
it { is_expected.to contain_exec('patterndb::deploy::default').with(command: 'cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml') }
end

context 'With test_before_deploy' do
Expand All @@ -113,8 +107,7 @@
}
end

it { is_expected.to contain_exec('patterndb::merge::default').that_notifies('Exec[patterndb::test::default]') }
it { is_expected.to contain_exec('patterndb::test::default').that_notifies('Exec[patterndb::deploy::default]') }
it { is_expected.to contain_exec('patterndb::deploy::default').with(command: 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp /tmp/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml') }
end
end
end
Expand Down