Make rsyslog file_input bulletproof

This patch makes rsyslog::file_input accept also $sources as single hash.
Currently when $sources is not array deployment fails.

Change-Id: I91d9f8ffb1e0c8bbdbc90696950aafd797ff380c
(cherry picked from commit 8c813bc8ac)
This commit is contained in:
Martin Magr 2020-01-13 11:07:05 +01:00
parent 6247b7a4bb
commit becddfad8f
2 changed files with 26 additions and 10 deletions

View File

@ -17,7 +17,8 @@ define tripleo::profile::base::logging::rsyslog::file_input (
$default_startmsg = '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]+ [0-9]+)? (DEBUG|INFO|WARNING|ERROR) '
) {
if $sources {
$rsyslog_sources = $sources.reduce([]) |$memo, $config| {
$sources_array = Array($sources, true)
$rsyslog_sources = $sources_array.reduce([]) |$memo, $config| {
if ! $config['startmsg.regex'] {
$record = $config + {'startmsg.regex' => $default_startmsg}
} else {

View File

@ -24,17 +24,17 @@ describe 'tripleo::profile::base::logging::rsyslog::file_input' do
'include ::rsyslog::server'
end
let :params do {
'sources' => [
{'file' => '/path/to/foo.log', 'tag' => 'foo'},
{'file' => '/path/to/bar.log', 'tag' => 'bar', 'startmsg.regex' => 'baz'}
],
'default_startmsg' => 'test'
}
end
shared_examples_for 'tripleo::profile::base::logging::rsyslog::file_input' do
context 'with basic parameters to configure rsyslog file inputs' do
let :params do {
'sources' => [
{'file' => '/path/to/foo.log', 'tag' => 'foo'},
{'file' => '/path/to/bar.log', 'tag' => 'bar', 'startmsg.regex' => 'baz'}
],
'default_startmsg' => 'test'
}
end
it 'should configure the given file inputs' do
should contain_concat__fragment('rsyslog::component::input::foobar_foo').with({
:target => '/etc/rsyslog.d/50_rsyslog.conf',
@ -46,6 +46,21 @@ describe 'tripleo::profile::base::logging::rsyslog::file_input' do
})
end
end
context 'with non-array sources to configure rsyslog file input' do
let :params do {
'sources' => {'file' => '/path/to/foo.log', 'tag' => 'foo'},
'default_startmsg' => 'test'
}
end
it 'should configure the given file inputs' do
should contain_concat__fragment('rsyslog::component::input::foobar_foo').with({
:target => '/etc/rsyslog.d/50_rsyslog.conf',
:content => foo_log_conf,
})
end
end
end
on_supported_os.each do |os, facts|