Switch aodh to use os_service_default fact

This change switches the aodh module to use the os_service_default
fact for configuration options that default to '<SERVICE DEFAULT>'.

Related-bug: #1515273
Change-Id: I05488c8bdcb5f54976a17aa25bf8a3b9d46627bb
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2015-10-29 13:44:43 +01:00
parent 6104ddc586
commit 86d3e7e214
9 changed files with 103 additions and 200 deletions

View File

@ -91,8 +91,9 @@
# #
# [*log_dir*] # [*log_dir*]
# (optional) Directory where logs should be stored. # (optional) Directory where logs should be stored.
# If set to boolean false, it will not log to any directory. # If set to boolean false or the $::os_service_default, it will not log to
# Defaults to undef # any directory.
# Defaults to undef.
# #
# [*state_path*] # [*state_path*]
# (optional) Directory for storing state. # (optional) Directory for storing state.
@ -222,6 +223,7 @@ class aodh (
$use_syslog = undef, $use_syslog = undef,
$use_stderr = undef, $use_stderr = undef,
$log_facility = undef, $log_facility = undef,
$log_dir = undef,
$notification_driver = undef, $notification_driver = undef,
$notification_topics = 'notifications', $notification_topics = 'notifications',
$database_connection = undef, $database_connection = undef,

View File

@ -6,59 +6,60 @@
# #
# [*verbose*] # [*verbose*]
# (Optional) Should the daemons log verbose messages # (Optional) Should the daemons log verbose messages
# Defaults to 'false' # Defaults to $::os_service_default
# #
# [*debug*] # [*debug*]
# (Optional) Should the daemons log debug messages # (Optional) Should the daemons log debug messages
# Defaults to 'false' # Defaults to $::os_service_default
# #
# [*use_syslog*] # [*use_syslog*]
# (Optional) Use syslog for logging. # (Optional) Use syslog for logging.
# Defaults to 'false' # Defaults to $::os_service_default
# #
# [*use_stderr*] # [*use_stderr*]
# (optional) Use stderr for logging # (optional) Use stderr for logging
# Defaults to 'true' # Defaults to $::os_service_default
# #
# [*log_facility*] # [*log_facility*]
# (Optional) Syslog facility to receive log lines. # (Optional) Syslog facility to receive log lines.
# Defaults to 'LOG_USER' # Defaults to $::os_service_default
# #
# [*log_dir*] # [*log_dir*]
# (optional) Directory where logs should be stored. # (optional) Directory where logs should be stored.
# If set to boolean false, it will not log to any directory. # If set to boolean false or the $::os_service_default, it will not log to
# Defaults to '/var/log/aodh' # any directory.
# Defaults to '/var/log/aodh'.
# #
# [*logging_context_format_string*] # [*logging_context_format_string*]
# (optional) Format string to use for log messages with context. # (optional) Format string to use for log messages with context.
# Defaults to undef. # Defaults to $::os_service_default
# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ # Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\
# [%(request_id)s %(user_identity)s] %(instance)s%(message)s' # [%(request_id)s %(user_identity)s] %(instance)s%(message)s'
# #
# [*logging_default_format_string*] # [*logging_default_format_string*]
# (optional) Format string to use for log messages without context. # (optional) Format string to use for log messages without context.
# Defaults to undef. # Defaults to $::os_service_default
# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ # Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\
# [-] %(instance)s%(message)s' # [-] %(instance)s%(message)s'
# #
# [*logging_debug_format_suffix*] # [*logging_debug_format_suffix*]
# (optional) Formatted data to append to log format when level is DEBUG. # (optional) Formatted data to append to log format when level is DEBUG.
# Defaults to undef. # Defaults to $::os_service_default
# Example: '%(funcName)s %(pathname)s:%(lineno)d' # Example: '%(funcName)s %(pathname)s:%(lineno)d'
# #
# [*logging_exception_prefix*] # [*logging_exception_prefix*]
# (optional) Prefix each line of exception output with this format. # (optional) Prefix each line of exception output with this format.
# Defaults to undef. # Defaults to $::os_service_default
# Example: '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s' # Example: '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s'
# #
# [*log_config_append*] # [*log_config_append*]
# The name of an additional logging configuration file. # The name of an additional logging configuration file.
# Defaults to undef. # Defaults to $::os_service_default
# See https://docs.python.org/2/howto/logging.html # See https://docs.python.org/2/howto/logging.html
# #
# [*default_log_levels*] # [*default_log_levels*]
# (optional) Hash of logger (keys) and level (values) pairs. # (optional) Hash of logger (keys) and level (values) pairs.
# Defaults to undef. # Defaults to $::os_service_default
# Example: # Example:
# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', # { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN',
# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', # 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO',
@ -67,191 +68,81 @@
# #
# [*publish_errors*] # [*publish_errors*]
# (optional) Publish error events (boolean value). # (optional) Publish error events (boolean value).
# Defaults to undef (false if unconfigured). # Defaults to $::os_service_default
# #
# [*fatal_deprecations*] # [*fatal_deprecations*]
# (optional) Make deprecations fatal (boolean value) # (optional) Make deprecations fatal (boolean value)
# Defaults to undef (false if unconfigured). # Defaults to $::os_service_default
# #
# [*instance_format*] # [*instance_format*]
# (optional) If an instance is passed with the log message, format it # (optional) If an instance is passed with the log message, format it
# like this (string value). # like this (string value).
# Defaults to undef. # Defaults to $::os_service_default
# Example: '[instance: %(uuid)s] ' # Example: '[instance: %(uuid)s] '
# #
# [*instance_uuid_format*] # [*instance_uuid_format*]
# (optional) If an instance UUID is passed with the log message, format # (optional) If an instance UUID is passed with the log message, format
# it like this (string value). # it like this (string value).
# Defaults to undef. # Defaults to $::os_service_default
# Example: instance_uuid_format='[instance: %(uuid)s] ' # Example: instance_uuid_format='[instance: %(uuid)s] '
# [*log_date_format*] # [*log_date_format*]
# (optional) Format string for %%(asctime)s in log records. # (optional) Format string for %%(asctime)s in log records.
# Defaults to undef. # Defaults to $::os_service_default
# Example: 'Y-%m-%d %H:%M:%S' # Example: 'Y-%m-%d %H:%M:%S'
class aodh::logging( class aodh::logging(
$use_syslog = false, $use_syslog = $::os_service_default,
$use_stderr = true, $use_stderr = $::os_service_default,
$log_facility = 'LOG_USER', $log_facility = $::os_service_default,
$log_dir = '/var/log/aodh', $log_dir = '/var/log/aodh',
$verbose = false, $verbose = $::os_service_default,
$debug = false, $debug = $::os_service_default,
$logging_context_format_string = undef, $logging_context_format_string = $::os_service_default,
$logging_default_format_string = undef, $logging_default_format_string = $::os_service_default,
$logging_debug_format_suffix = undef, $logging_debug_format_suffix = $::os_service_default,
$logging_exception_prefix = undef, $logging_exception_prefix = $::os_service_default,
$log_config_append = undef, $log_config_append = $::os_service_default,
$default_log_levels = undef, $default_log_levels = $::os_service_default,
$publish_errors = undef, $publish_errors = $::os_service_default,
$fatal_deprecations = undef, $fatal_deprecations = $::os_service_default,
$instance_format = undef, $instance_format = $::os_service_default,
$instance_uuid_format = undef, $instance_uuid_format = $::os_service_default,
$log_date_format = undef, $log_date_format = $::os_service_default,
) { ) {
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use aodh::<myparam> first then aodh::logging::<myparam>. # to use aodh::<myparam> first then aodh::logging::<myparam>.
$use_syslog_real = pick($::aodh::use_syslog,$use_syslog) $use_syslog_real = pick($::aodh::use_syslog,$use_syslog)
$use_stderr_real = pick($::aodh::use_stderr,$use_stderr) $use_stderr_real = pick($::aodh::use_stderr,$use_stderr)
$log_facility_real = pick($::aodh::log_facility,$log_facility) $log_facility_real = pick($::aodh::log_facility,$log_facility)
$log_dir_real = pick($::aodh::log_dir,$log_dir) $log_dir_real = pick($::aodh::log_dir,$log_dir)
$verbose_real = pick($::aodh::verbose,$verbose) $verbose_real = pick($::aodh::verbose,$verbose)
$debug_real = pick($::aodh::debug,$debug) $debug_real = pick($::aodh::debug,$debug)
aodh_config { if is_service_default($default_log_levels) {
'DEFAULT/debug' : value => $debug_real; $default_log_levels_real = $default_log_levels
'DEFAULT/verbose' : value => $verbose_real; } else {
'DEFAULT/use_stderr' : value => $use_stderr_real; $default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',')
'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 {
aodh_config { 'DEFAULT/debug' : value => $debug_real;
'DEFAULT/logging_context_format_string' : 'DEFAULT/verbose' : value => $verbose_real;
value => $logging_context_format_string; 'DEFAULT/use_stderr' : value => $use_stderr_real;
} 'DEFAULT/use_syslog' : value => $use_syslog_real;
} 'DEFAULT/log_dir' : value => $log_dir_real;
else { 'DEFAULT/syslog_log_facility' : value => $log_facility_real;
aodh_config { 'DEFAULT/logging_context_format_string' : value => $logging_context_format_string;
'DEFAULT/logging_context_format_string' : ensure => absent; '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/log_config_append' : value => $log_config_append;
if $logging_default_format_string { 'DEFAULT/default_log_levels' : value => $default_log_levels_real;
aodh_config { 'DEFAULT/publish_errors' : value => $publish_errors;
'DEFAULT/logging_default_format_string' : 'DEFAULT/fatal_deprecations' : value => $fatal_deprecations;
value => $logging_default_format_string; 'DEFAULT/instance_format' : value => $instance_format;
} 'DEFAULT/instance_uuid_format' : value => $instance_uuid_format;
} 'DEFAULT/log_date_format' : value => $log_date_format;
else { }
aodh_config {
'DEFAULT/logging_default_format_string' : ensure => absent;
}
}
if $logging_debug_format_suffix {
aodh_config {
'DEFAULT/logging_debug_format_suffix' :
value => $logging_debug_format_suffix;
}
}
else {
aodh_config {
'DEFAULT/logging_debug_format_suffix' : ensure => absent;
}
}
if $logging_exception_prefix {
aodh_config {
'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix;
}
}
else {
aodh_config {
'DEFAULT/logging_exception_prefix' : ensure => absent;
}
}
if $log_config_append {
aodh_config {
'DEFAULT/log_config_append' : value => $log_config_append;
}
}
else {
aodh_config {
'DEFAULT/log_config_append' : ensure => absent;
}
}
if $default_log_levels {
aodh_config {
'DEFAULT/default_log_levels' :
value => join(sort(join_keys_to_values($default_log_levels, '=')), ',');
}
}
else {
aodh_config {
'DEFAULT/default_log_levels' : ensure => absent;
}
}
if $publish_errors {
aodh_config {
'DEFAULT/publish_errors' : value => $publish_errors;
}
}
else {
aodh_config {
'DEFAULT/publish_errors' : ensure => absent;
}
}
if $fatal_deprecations {
aodh_config {
'DEFAULT/fatal_deprecations' : value => $fatal_deprecations;
}
}
else {
aodh_config {
'DEFAULT/fatal_deprecations' : ensure => absent;
}
}
if $instance_format {
aodh_config {
'DEFAULT/instance_format' : value => $instance_format;
}
}
else {
aodh_config {
'DEFAULT/instance_format' : ensure => absent;
}
}
if $instance_uuid_format {
aodh_config {
'DEFAULT/instance_uuid_format' : value => $instance_uuid_format;
}
}
else {
aodh_config {
'DEFAULT/instance_uuid_format' : ensure => absent;
}
}
if $log_date_format {
aodh_config {
'DEFAULT/log_date_format' : value => $log_date_format;
}
}
else {
aodh_config {
'DEFAULT/log_date_format' : ensure => absent;
}
}
} }

View File

@ -123,12 +123,14 @@ describe 'aodh::api' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian', @default_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian', :operatingsystem => 'Debian',
:operatingsystemrelease => '8.0', :operatingsystemrelease => '8.0',
:concat_basedir => '/var/lib/puppet/concat', :concat_basedir => '/var/lib/puppet/concat',
:fqdn => 'some.host.tld', :fqdn => 'some.host.tld',
:processorcount => 2 } :processorcount => 2,
})
end end
let :platform_params do let :platform_params do
@ -141,12 +143,14 @@ describe 'aodh::api' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat', @default_facts.merge({
:osfamily => 'RedHat',
:operatingsystem => 'RedHat', :operatingsystem => 'RedHat',
:operatingsystemrelease => '7.1', :operatingsystemrelease => '7.1',
:fqdn => 'some.host.tld', :fqdn => 'some.host.tld',
:concat_basedir => '/var/lib/puppet/concat', :concat_basedir => '/var/lib/puppet/concat',
:processorcount => 2 } :processorcount => 2,
})
end end
let :platform_params do let :platform_params do
@ -159,7 +163,7 @@ describe 'aodh::api' do
describe 'with custom auth_uri' do describe 'with custom auth_uri' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
before do before do
params.merge!({ params.merge!({
@ -173,10 +177,10 @@ describe 'aodh::api' do
describe "with custom keystone identity_uri" do describe "with custom keystone identity_uri" do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
before do before do
params.merge!({ params.merge!({
:keystone_identity_uri => 'https://foo.bar:1234/', :keystone_identity_uri => 'https://foo.bar:1234/',
}) })
end end
@ -187,10 +191,10 @@ describe 'aodh::api' do
describe "with custom keystone identity_uri and auth_uri" do describe "with custom keystone identity_uri and auth_uri" do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
before do before do
params.merge!({ params.merge!({
:keystone_identity_uri => 'https://foo.bar:35357/', :keystone_identity_uri => 'https://foo.bar:35357/',
:keystone_auth_uri => 'https://foo.bar:5000/v2.0/', :keystone_auth_uri => 'https://foo.bar:5000/v2.0/',
}) })

View File

@ -87,7 +87,7 @@ describe 'aodh::evaluator' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
let :platform_params do let :platform_params do
@ -100,7 +100,7 @@ describe 'aodh::evaluator' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
let :platform_params do let :platform_params do

View File

@ -214,8 +214,10 @@ describe 'aodh' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian', @default_facts.merge({
:operatingsystem => 'Debian' } :osfamily => 'Debian',
:operatingsystem => 'Debian',
})
end end
let :platform_params do let :platform_params do
@ -227,7 +229,7 @@ describe 'aodh' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
let :platform_params do let :platform_params do

View File

@ -73,7 +73,7 @@ describe 'aodh::listener' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
let :platform_params do let :platform_params do
@ -86,7 +86,7 @@ describe 'aodh::listener' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
let :platform_params do let :platform_params do

View File

@ -56,12 +56,13 @@ describe 'aodh::logging' do
end end
shared_examples 'basic default logging settings' do shared_examples 'basic default logging settings' do
it 'configures aodh logging settins with default values' do it 'configures aodh logging settings with default values' do
is_expected.to contain_aodh_config('DEFAULT/use_syslog').with(:value => 'false') is_expected.to contain_aodh_config('DEFAULT/use_syslog').with(:value => '<SERVICE DEFAULT>')
is_expected.to contain_aodh_config('DEFAULT/use_stderr').with(:value => 'true') is_expected.to contain_aodh_config('DEFAULT/use_stderr').with(:value => '<SERVICE DEFAULT>')
is_expected.to contain_aodh_config('DEFAULT/syslog_log_facility').with(:value => '<SERVICE DEFAULT>')
is_expected.to contain_aodh_config('DEFAULT/log_dir').with(:value => '/var/log/aodh') 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/verbose').with(:value => '<SERVICE DEFAULT>')
is_expected.to contain_aodh_config('DEFAULT/debug').with(:value => 'false') is_expected.to contain_aodh_config('DEFAULT/debug').with(:value => '<SERVICE DEFAULT>')
end end
end end
@ -120,13 +121,13 @@ describe 'aodh::logging' do
:default_log_levels, :fatal_deprecations, :default_log_levels, :fatal_deprecations,
:instance_format, :instance_uuid_format, :instance_format, :instance_uuid_format,
:log_date_format, ].each { |param| :log_date_format, ].each { |param|
it { is_expected.to contain_aodh_config("DEFAULT/#{param}").with_ensure('absent') } it { is_expected.to contain_aodh_config("DEFAULT/#{param}").with(:value => '<SERVICE DEFAULT>') }
} }
end end
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
it_configures 'aodh-logging' it_configures 'aodh-logging'
@ -134,7 +135,7 @@ describe 'aodh::logging' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
it_configures 'aodh-logging' it_configures 'aodh-logging'

View File

@ -73,7 +73,7 @@ describe 'aodh::notifier' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
let :platform_params do let :platform_params do
@ -86,7 +86,7 @@ describe 'aodh::notifier' do
context 'on RedHat platforms' do context 'on RedHat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat' } @default_facts.merge({ :osfamily => 'RedHat' })
end end
let :platform_params do let :platform_params do

View File

@ -5,6 +5,9 @@ require 'webmock/rspec'
RSpec.configure do |c| RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures' c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises' c.alias_it_should_behave_like_to :it_raises, 'raises'
c.before :each do
@default_facts = { :os_service_default => '<SERVICE DEFAULT>' }
end
end end
at_exit { RSpec::Puppet::Coverage.report! } at_exit { RSpec::Puppet::Coverage.report! }