Skip to content

Commit 6bb7e55

Browse files
committed
Make testing and installing more reliable
If a pattern database is failing, it is not installed, but on subsequent run of Puppet the pattern database is not tested again and the configuration converge to a state where the expected pattern database is not installed. Rework the pattern database testing and installation so that a failling pattern database fail on each subsequent run of Puppet, so that errors can be spotted more easily. Fixes #42
1 parent a8153d6 commit 6bb7e55

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

manifests/parser.pp

+11-30
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,26 @@
2424
ensure_resource ('file', "${patterndb::temp_dir}/patterndb", {
2525
'ensure' => 'directory',
2626
})
27-
ensure_resource ('file', "patterndb::file::${name}", {
28-
'ensure' => 'present',
29-
'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"
30-
})
27+
28+
$_test_before_deploy = $test_before_deploy.lest || { $patterndb::test_before_deploy }
29+
3130
exec { "patterndb::merge::${name}":
3231
command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::pdb_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml",
3332
path => $facts['path'],
3433
logoutput => true,
3534
refreshonly => true,
3635
}
3736

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

4643
exec { "patterndb::deploy::${name}":
47-
command => "cp ${patterndb::temp_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/",
48-
logoutput => true,
49-
path => $facts['path'],
50-
refreshonly => true,
51-
}
52-
if $test_before_deploy =~ Undef {
53-
$_test_before_deploy = $patterndb::test_before_deploy
54-
} else {
55-
$_test_before_deploy = $test_before_deploy
56-
}
57-
if $_test_before_deploy {
58-
File["patterndb::file::${name}"]
59-
~> Exec["patterndb::merge::${name}"]
60-
~> Exec["patterndb::test::${name}"]
61-
~> Exec["patterndb::deploy::${name}"]
62-
} else {
63-
File["patterndb::file::${name}"]
64-
~> Exec["patterndb::merge::${name}"]
65-
# we won't 'pdbtool test' the merged file before deploying
66-
~> Exec["patterndb::deploy::${name}"]
44+
command => $deploy_command,
45+
path => $facts['path'],
46+
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 ]",
47+
require => Exec["patterndb::merge::${name}"],
6748
}
6849
}

spec/defines/parser_spec.rb

+15-22
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
context 'Catchall' do
1818
it { is_expected.to contain_class('Patterndb') }
1919
it { is_expected.to contain_exec('patterndb::merge::default') }
20-
21-
it {
22-
is_expected.to contain_file('patterndb::file::default').with(
23-
'ensure' => 'present'
24-
).that_notifies('Exec[patterndb::merge::default]')
25-
}
2620
end
2721

2822
context 'Default values (no parameters)' do
@@ -33,8 +27,8 @@
3327
end
3428

3529
it {
36-
is_expected.to contain_exec('patterndb::test::default').with(
37-
'command' => %r{patterndb/default\.xml $}m
30+
is_expected.to contain_exec('patterndb::deploy::default').with(
31+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
3832
)
3933
}
4034
end
@@ -47,8 +41,8 @@
4741
end
4842

4943
it {
50-
is_expected.to contain_exec('patterndb::test::default').with(
51-
'command' => %r{patterndb/default\.xml --module=foo --module=bar$}m
44+
is_expected.to contain_exec('patterndb::deploy::default').with(
45+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml --module=foo --module=bar && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
5246
)
5347
}
5448
end
@@ -59,14 +53,14 @@
5953
end
6054

6155
it {
62-
is_expected.to contain_exec('patterndb::test::default').with(
63-
'command' => %r{patterndb/default\.xml $}m
56+
is_expected.to contain_exec('patterndb::deploy::default').with(
57+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
6458
)
6559
}
6660

6761
it {
68-
is_expected.to contain_exec('patterndb::test::stage1').with(
69-
'command' => %r{patterndb/stage1\.xml $}m
62+
is_expected.to contain_exec('patterndb::deploy::stage1').with(
63+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/stage1.xml && cp //var/lib/syslog-ng/patterndb/stage1.xml //var/lib/syslog-ng/patterndb/stage1.xml'
7064
)
7165
}
7266
end
@@ -78,8 +72,8 @@
7872
end
7973

8074
it {
81-
is_expected.to contain_exec('patterndb::test::default').with(
82-
'command' => %r{patterndb/default\.xml --module=foo --module=bar$}m
75+
is_expected.to contain_exec('patterndb::deploy::default').with(
76+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml --module=foo --module=bar && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
8377
)
8478
}
8579
end
@@ -90,20 +84,20 @@
9084
end
9185

9286
it {
93-
is_expected.to contain_exec('patterndb::test::default').with(
94-
'command' => %r{patterndb/default\.xml $}m
87+
is_expected.to contain_exec('patterndb::deploy::default').with(
88+
'command' => 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml'
9589
)
9690
}
9791
end
9892

99-
context 'Without test_before_deploy' do
93+
context 'Without deploy' do
10094
let :params do
10195
{
10296
test_before_deploy: false,
10397
}
10498
end
10599

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

109103
context 'With test_before_deploy' do
@@ -113,8 +107,7 @@
113107
}
114108
end
115109

116-
it { is_expected.to contain_exec('patterndb::merge::default').that_notifies('Exec[patterndb::test::default]') }
117-
it { is_expected.to contain_exec('patterndb::test::default').that_notifies('Exec[patterndb::deploy::default]') }
110+
it { is_expected.to contain_exec('patterndb::deploy::default').with(command: 'pdbtool test /tmp/syslog-ng/patterndb/default.xml && cp //var/lib/syslog-ng/patterndb/default.xml //var/lib/syslog-ng/patterndb/default.xml') }
118111
end
119112
end
120113
end

0 commit comments

Comments
 (0)