From 5a2607a7d10e072e8b052590d4979b9baaa87538 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 19 Oct 2015 20:57:55 -0400 Subject: [PATCH] Update aodh::logging Synchronize logging class with other modules. Change-Id: I4b13bf8de4cf51ab64ef6e9fd92732e1a5023bcf --- manifests/logging.pp | 62 +++++++++++++++++++++++++++---- spec/classes/aodh_logging_spec.rb | 36 ++++++++++++++++++ 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/manifests/logging.pp b/manifests/logging.pp index 0c452efd..88f7cb60 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -1,9 +1,34 @@ # Class aodh::logging # -# aodh extended logging configuration +# aodh logging configuration # # == parameters # +# [*verbose*] +# (Optional) Should the daemons log verbose messages +# Defaults to 'false' +# +# [*debug*] +# (Optional) Should the daemons log debug messages +# Defaults to 'false' +# +# [*use_syslog*] +# (Optional) Use syslog for logging. +# Defaults to 'false' +# +# [*use_stderr*] +# (optional) Use stderr for logging +# Defaults to 'true' +# +# [*log_facility*] +# (Optional) Syslog facility to receive log lines. +# Defaults to 'LOG_USER' +# +# [*log_dir*] +# (optional) Directory where logs should be stored. +# If set to boolean false, it will not log to any directory. +# Defaults to '/var/log/aodh' +# # [*logging_context_format_string*] # (optional) Format string to use for log messages with context. # Defaults to undef. @@ -35,13 +60,10 @@ # (optional) Hash of logger (keys) and level (values) pairs. # Defaults to undef. # Example: -# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', -# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', -# 'oslo.messaging' => 'INFO', 'iso8601' => 'WARN', -# 'requests.packages.urllib3.connectionpool' => 'WARN', -# 'urllib3.connectionpool' => 'WARN', -# 'websocket' => 'WARN', 'aodhmiddleware' => 'WARN', -# 'routes.middleware' => 'WARN', stevedore => 'WARN' } +# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', +# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', +# 'iso8601' => 'WARN', +# 'requests.packages.urllib3.connectionpool' => 'WARN' } # # [*publish_errors*] # (optional) Publish error events (boolean value). @@ -69,6 +91,12 @@ # Example: 'Y-%m-%d %H:%M:%S' class aodh::logging( + $use_syslog = false, + $use_stderr = true, + $log_facility = 'LOG_USER', + $log_dir = '/var/log/aodh', + $verbose = false, + $debug = false, $logging_context_format_string = undef, $logging_default_format_string = undef, $logging_debug_format_suffix = undef, @@ -82,6 +110,24 @@ class aodh::logging( $log_date_format = undef, ) { + # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function + # to use aodh:: first then aodh::logging::. + $use_syslog_real = pick($::aodh::use_syslog,$use_syslog) + $use_stderr_real = pick($::aodh::use_stderr,$use_stderr) + $log_facility_real = pick($::aodh::log_facility,$log_facility) + $log_dir_real = pick($::aodh::log_dir,$log_dir) + $verbose_real = pick($::aodh::verbose,$verbose) + $debug_real = pick($::aodh::debug,$debug) + + aodh_config { + 'DEFAULT/debug' : value => $debug_real; + 'DEFAULT/verbose' : value => $verbose_real; + 'DEFAULT/use_stderr' : value => $use_stderr_real; + 'DEFAULT/use_syslog' : value => $use_syslog_real; + 'DEFAULT/log_dir' : value => $log_dir_real; + 'DEFAULT/syslog_log_facility': value => $log_facility_real; + } + if $logging_context_format_string { aodh_config { 'DEFAULT/logging_context_format_string' : diff --git a/spec/classes/aodh_logging_spec.rb b/spec/classes/aodh_logging_spec.rb index 1ab1f4e0..17d5e000 100644 --- a/spec/classes/aodh_logging_spec.rb +++ b/spec/classes/aodh_logging_spec.rb @@ -24,11 +24,26 @@ describe 'aodh::logging' do :instance_format => '[instance: %(uuid)s] ', :instance_uuid_format => '[instance: %(uuid)s] ', :log_date_format => '%Y-%m-%d %H:%M:%S', + :use_syslog => true, + :use_stderr => false, + :log_facility => 'LOG_FOO', + :log_dir => '/var/log', + :verbose => true, + :debug => true, } end shared_examples_for 'aodh-logging' do + context 'with basic logging options and default settings' do + it_configures 'basic default logging settings' + end + + context 'with basic logging options and non-default settings' do + before { params.merge!( log_params ) } + it_configures 'basic non-default logging settings' + end + context 'with extended logging options' do before { params.merge!( log_params ) } it_configures 'logging params set' @@ -40,6 +55,27 @@ describe 'aodh::logging' do end + shared_examples 'basic default logging settings' do + it 'configures aodh logging settins with default values' do + is_expected.to contain_aodh_config('DEFAULT/use_syslog').with(:value => 'false') + is_expected.to contain_aodh_config('DEFAULT/use_stderr').with(:value => 'true') + is_expected.to contain_aodh_config('DEFAULT/log_dir').with(:value => '/var/log/aodh') + is_expected.to contain_aodh_config('DEFAULT/verbose').with(:value => 'false') + is_expected.to contain_aodh_config('DEFAULT/debug').with(:value => 'false') + end + end + + shared_examples 'basic non-default logging settings' do + it 'configures aodh logging settins with non-default values' do + is_expected.to contain_aodh_config('DEFAULT/use_syslog').with(:value => 'true') + is_expected.to contain_aodh_config('DEFAULT/use_stderr').with(:value => 'false') + is_expected.to contain_aodh_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO') + is_expected.to contain_aodh_config('DEFAULT/log_dir').with(:value => '/var/log') + is_expected.to contain_aodh_config('DEFAULT/verbose').with(:value => 'true') + is_expected.to contain_aodh_config('DEFAULT/debug').with(:value => 'true') + end + end + shared_examples_for 'logging params set' do it 'enables logging params' do is_expected.to contain_aodh_config('DEFAULT/logging_context_format_string').with_value(