From becddfad8fff6953cc199917baafe79e59cd930d Mon Sep 17 00:00:00 2001 From: Martin Magr Date: Mon, 13 Jan 2020 11:07:05 +0100 Subject: [PATCH] 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 8c813bc8ac6b1541ce32a82bdc0992c16464acf4) --- .../base/logging/rsyslog/file_input.pp | 3 +- ...le_base_logging_rsyslog_file_input_spec.rb | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/manifests/profile/base/logging/rsyslog/file_input.pp b/manifests/profile/base/logging/rsyslog/file_input.pp index 3ee01ea53..0c58f1128 100644 --- a/manifests/profile/base/logging/rsyslog/file_input.pp +++ b/manifests/profile/base/logging/rsyslog/file_input.pp @@ -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 { diff --git a/spec/defines/tripleo_profile_base_logging_rsyslog_file_input_spec.rb b/spec/defines/tripleo_profile_base_logging_rsyslog_file_input_spec.rb index ca293ce57..38dbc28c3 100644 --- a/spec/defines/tripleo_profile_base_logging_rsyslog_file_input_spec.rb +++ b/spec/defines/tripleo_profile_base_logging_rsyslog_file_input_spec.rb @@ -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|