Improvements for oslo::log define

* Deprecated options 'use_syslog_rfc_format' and
  'log_format' were removed. It can be done because
  this module wasn't released;
* Call of create_resources was reworked (one common call was left
  with hash of parameters);
* Create unit tests for this define.

Change-Id: Idfd98545e3a1341cf0fd46f7ddad65c11069ff68
This commit is contained in:
iberezovskiy 2016-03-30 16:32:22 +03:00
parent 151b16141a
commit 8ae52af64a
2 changed files with 133 additions and 42 deletions

View File

@ -43,10 +43,6 @@
# (Optional) Use syslog for logging (boolean value).
# Defaults to $::os_service_default
#
# [*use_syslog_rfc_format*]
# (Optional) Enables or disables syslog rfc5424 format for logging (boolean value).
# Defaults to $::os_service_default
#
# [*syslog_log_facility*]
# (Optional) Syslog facility to receive log lines.
# This option is ignored if log_config_append is set.
@ -95,7 +91,7 @@
#
# [*publish_errors*]
# (Optional) Enables or disables publication of error events (boolean value).
# Defaults to $::os_service_default.
# Defaults to $::os_service_default
#
# [*instance_format*]
# (Optional) The format for an instance that is passed with the log message.
@ -109,13 +105,7 @@
#
# [*fatal_deprecations*]
# (Optional) Enables or disables fatal status of deprecations (boolean value).
# Defaults to $::os_service_default.
#
# DEPRECATED:
# [*log_format*]
# (Optional) DEPRECATED. A logging.Formatter log message format string which may use
# any of the available logging.LogRecord attributes.
# Defauls to $::os_service_default
# Defaults to $::os_service_default
#
define oslo::log(
$debug = $::os_service_default,
@ -126,7 +116,6 @@ define oslo::log(
$log_dir = $::os_service_default,
$watch_log_file = $::os_service_default,
$use_syslog = $::os_service_default,
$use_syslog_rfc_format = $::os_service_default,
$syslog_log_facility = $::os_service_default,
$use_stderr = $::os_service_default,
$logging_context_format_string = $::os_service_default,
@ -139,15 +128,8 @@ define oslo::log(
$instance_format = $::os_service_default,
$instance_uuid_format = $::os_service_default,
$fatal_deprecations = $::os_service_default,
# DEPRECATED
$log_format = $::os_service_default,
){
# Deprecated options
if ! is_service_default($log_format) {
warnning('This option is deprecated. Please use logging_context_format_string and logging_default_format_string instead.')
}
if is_service_default($default_log_levels) {
$default_log_levels_real = $default_log_levels
} else {
@ -155,26 +137,28 @@ define oslo::log(
$default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',')
}
create_resources($name, {'DEFAULT/debug' => { value => $debug }})
create_resources($name, {'DEFAULT/verbose' => { value => $verbose }})
create_resources($name, {'DEFAULT/log_config_append' => { value => $log_config_append }})
create_resources($name, {'DEFAULT/log_date_format' => { value => $log_date_format }})
create_resources($name, {'DEFAULT/log_file' => { value => $log_file }})
create_resources($name, {'DEFAULT/log_dir' => { value => $log_dir }})
create_resources($name, {'DEFAULT/watch_log_file' => { value => $watch_log_file }})
create_resources($name, {'DEFAULT/use_syslog' => { value => $use_syslog }})
create_resources($name, {'DEFAULT/use_syslog_rfc_format' => { value => $use_syslog_rfc_format }})
create_resources($name, {'DEFAULT/syslog_log_facility' => { value => $syslog_log_facility }})
create_resources($name, {'DEFAULT/use_stderr' => { value => $use_stderr }})
create_resources($name, {'DEFAULT/logging_context_format_string' => { value => $logging_context_format_string }})
create_resources($name, {'DEFAULT/logging_default_format_string' => { value => $logging_default_format_string }})
create_resources($name, {'DEFAULT/logging_debug_format_suffix' => { value => $logging_debug_format_suffix }})
create_resources($name, {'DEFAULT/logging_exception_prefix' => { value => $logging_exception_prefix }})
create_resources($name, {'DEFAULT/logging_user_identity_format' => { value => $logging_user_identity_format }})
create_resources($name, {'DEFAULT/default_log_levels' => { value => $default_log_levels_real }})
create_resources($name, {'DEFAULT/publish_errors' => { value => $publish_errors }})
create_resources($name, {'DEFAULT/instance_format' => { value => $instance_format }})
create_resources($name, {'DEFAULT/instance_uuid_format' => { value => $instance_uuid_format }})
create_resources($name, {'DEFAULT/fatal_deprecations' => { value => $fatal_deprecations }})
create_resources($name, {'DEFAULT/log_format' => { value => $log_format }})
$log_options = {
'DEFAULT/debug' => { value => $debug },
'DEFAULT/verbose' => { value => $verbose },
'DEFAULT/log_config_append' => { value => $log_config_append },
'DEFAULT/log_date_format' => { value => $log_date_format },
'DEFAULT/log_file' => { value => $log_file },
'DEFAULT/log_dir' => { value => $log_dir },
'DEFAULT/watch_log_file' => { value => $watch_log_file },
'DEFAULT/use_syslog' => { value => $use_syslog },
'DEFAULT/syslog_log_facility' => { value => $syslog_log_facility },
'DEFAULT/use_stderr' => { value => $use_stderr },
'DEFAULT/logging_context_format_string' => { value => $logging_context_format_string },
'DEFAULT/logging_default_format_string' => { value => $logging_default_format_string },
'DEFAULT/logging_debug_format_suffix' => { value => $logging_debug_format_suffix },
'DEFAULT/logging_exception_prefix' => { value => $logging_exception_prefix },
'DEFAULT/logging_user_identity_format' => { value => $logging_user_identity_format },
'DEFAULT/default_log_levels' => { value => $default_log_levels_real },
'DEFAULT/publish_errors' => { value => $publish_errors },
'DEFAULT/instance_format' => { value => $instance_format },
'DEFAULT/instance_uuid_format' => { value => $instance_uuid_format },
'DEFAULT/fatal_deprecations' => { value => $fatal_deprecations },
}
create_resources($name, $log_options)
}

View File

@ -0,0 +1,107 @@
require 'spec_helper'
describe 'oslo::log' do
let (:title) { 'keystone_config' }
shared_examples 'shared examples' do
context 'with default parameters' do
it 'configure oslo_log default params' do
is_expected.to contain_keystone_config('DEFAULT/debug').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/verbose').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/log_config_append').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/log_date_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/log_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/log_dir').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/watch_log_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/use_syslog').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/syslog_log_facility').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/use_stderr').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/logging_context_format_string').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/logging_default_format_string').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/logging_debug_format_suffix').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/logging_exception_prefix').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/logging_user_identity_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/default_log_levels').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/publish_errors').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/instance_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/instance_uuid_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('DEFAULT/fatal_deprecations').with_value('<SERVICE DEFAULT>')
end
end
context 'with overridden parameters' do
let :params do
{ :debug => true,
:verbose => true,
:log_config_append => '/var/log/keystone/keystone.log',
:log_date_format => '%Y-%m-%d %H:%M:%S',
:log_file => '/var/log/keystone/keystone.log',
:log_dir => '/var/log/keystone',
:watch_log_file => true,
:use_syslog => true,
:syslog_log_facility => 'LOG_USER',
:use_stderr => true,
:logging_context_format_string =>
'%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s',
:logging_default_format_string => '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s',
:logging_debug_format_suffix => '%(funcName)s %(pathname)s:%(lineno)d',
:logging_exception_prefix => '%(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s',
:logging_user_identity_format => '%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s',
:default_log_levels => {
'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN','qpid' => 'WARN', 'sqlalchemy' => 'WARN',
'suds' => 'INFO', 'iso8601' => 'WARN', 'requests.packages.urllib3.connectionpool' => 'WARN' },
:publish_errors => true,
:instance_format => '[instance: %(uuid)s]',
:instance_uuid_format => '[instance: %(uuid)s]',
:fatal_deprecations => true,
}
end
it 'configures logging' do
is_expected.to contain_keystone_config('DEFAULT/debug').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/verbose').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/log_config_append').with_value('/var/log/keystone/keystone.log')
is_expected.to contain_keystone_config('DEFAULT/log_date_format').with_value('%Y-%m-%d %H:%M:%S')
is_expected.to contain_keystone_config('DEFAULT/log_file').with_value('/var/log/keystone/keystone.log')
is_expected.to contain_keystone_config('DEFAULT/log_dir').with_value('/var/log/keystone')
is_expected.to contain_keystone_config('DEFAULT/watch_log_file').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/use_syslog').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/syslog_log_facility').with_value('LOG_USER')
is_expected.to contain_keystone_config('DEFAULT/use_stderr').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/logging_context_format_string').with_value(
'%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s')
is_expected.to contain_keystone_config('DEFAULT/logging_default_format_string').with_value(
'%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s')
is_expected.to contain_keystone_config('DEFAULT/logging_debug_format_suffix').with_value('%(funcName)s %(pathname)s:%(lineno)d')
is_expected.to contain_keystone_config('DEFAULT/logging_exception_prefix').with_value(
'%(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s')
is_expected.to contain_keystone_config('DEFAULT/logging_user_identity_format').with_value(
'%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s')
is_expected.to contain_keystone_config('DEFAULT/default_log_levels').with_value(
'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,qpid=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO')
is_expected.to contain_keystone_config('DEFAULT/publish_errors').with_value(true)
is_expected.to contain_keystone_config('DEFAULT/instance_format').with_value('[instance: %(uuid)s]')
is_expected.to contain_keystone_config('DEFAULT/instance_uuid_format').with_value('[instance: %(uuid)s]')
is_expected.to contain_keystone_config('DEFAULT/fatal_deprecations').with_value(true)
end
end
end
context 'on a Debian osfamily' do
let :facts do
@default_facts.merge({ :osfamily => "Debian" })
end
include_examples 'shared examples'
end
context 'on a RedHat osfamily' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
include_examples 'shared examples'
end
end