Merge "Put all the logging related parameters to the logging class"

This commit is contained in:
Jenkins
2015-10-12 10:12:45 +00:00
committed by Gerrit Code Review
4 changed files with 103 additions and 94 deletions

View File

@@ -157,7 +157,7 @@
# [*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, it will not log to any directory.
# Defaults to '/var/log/nova' # Defaults to undef
# #
# [*state_path*] # [*state_path*]
# (optional) Directory for storing state. # (optional) Directory for storing state.
@@ -170,11 +170,11 @@
# #
# [*verbose*] # [*verbose*]
# (optional) Set log output to verbose output. # (optional) Set log output to verbose output.
# Defaults to false # Defaults to undef
# #
# [*debug*] # [*debug*]
# (optional) Set log output to debug output. # (optional) Set log output to debug output.
# Defaults to false # Defaults to undef
# #
# [*periodic_interval*] # [*periodic_interval*]
# (optional) Seconds between running periodic tasks. # (optional) Seconds between running periodic tasks.
@@ -190,15 +190,15 @@
# #
# [*use_syslog*] # [*use_syslog*]
# (optional) Use syslog for logging # (optional) Use syslog for logging
# Defaults to false # Defaults to undef
# #
# [*use_stderr*] # [*use_stderr*]
# (optional) Use stderr for logging # (optional) Use stderr for logging
# Defaults to true # Defaults to undef
# #
# [*log_facility*] # [*log_facility*]
# (optional) Syslog facility to receive log lines. # (optional) Syslog facility to receive log lines.
# Defaults to 'LOG_USER' # Defaults to undef
# #
# [*install_utilities*] # [*install_utilities*]
# (optional) Install nova utilities (Extra packages used by nova tools) # (optional) Install nova utilities (Extra packages used by nova tools)
@@ -306,11 +306,11 @@ class nova(
$qpid_tcp_nodelay = true, $qpid_tcp_nodelay = true,
$auth_strategy = 'keystone', $auth_strategy = 'keystone',
$service_down_time = 60, $service_down_time = 60,
$log_dir = '/var/log/nova', $log_dir = undef,
$state_path = '/var/lib/nova', $state_path = '/var/lib/nova',
$lock_path = $::nova::params::lock_path, $lock_path = $::nova::params::lock_path,
$verbose = false, $verbose = undef,
$debug = false, $debug = undef,
$periodic_interval = '60', $periodic_interval = '60',
$report_interval = '10', $report_interval = '10',
$rootwrap_config = '/etc/nova/rootwrap.conf', $rootwrap_config = '/etc/nova/rootwrap.conf',
@@ -321,9 +321,9 @@ class nova(
$key_file = false, $key_file = false,
$nova_public_key = undef, $nova_public_key = undef,
$nova_private_key = undef, $nova_private_key = undef,
$use_syslog = false, $use_syslog = undef,
$use_stderr = true, $use_stderr = undef,
$log_facility = 'LOG_USER', $log_facility = undef,
$install_utilities = true, $install_utilities = true,
$notification_driver = undef, $notification_driver = undef,
$notification_topics = 'notifications', $notification_topics = 'notifications',
@@ -336,6 +336,7 @@ class nova(
# maintain backward compatibility # maintain backward compatibility
include ::nova::db include ::nova::db
include ::nova::logging
if $mysql_module { if $mysql_module {
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
@@ -599,19 +600,6 @@ class nova(
} }
} }
if $log_dir {
file { $log_dir:
ensure => directory,
mode => '0750',
owner => 'nova',
group => $::nova::params::nova_log_group,
require => Package['nova-common'],
}
nova_config { 'DEFAULT/log_dir': value => $log_dir;}
} else {
nova_config { 'DEFAULT/log_dir': ensure => absent;}
}
if $notification_driver { if $notification_driver {
nova_config { nova_config {
'DEFAULT/notification_driver': value => join(any2array($notification_driver), ','); 'DEFAULT/notification_driver': value => join(any2array($notification_driver), ',');
@@ -621,9 +609,6 @@ class nova(
} }
nova_config { nova_config {
'DEFAULT/verbose': value => $verbose;
'DEFAULT/debug': value => $debug;
'DEFAULT/use_stderr': value => $use_stderr;
'DEFAULT/rpc_backend': value => $rpc_backend; 'DEFAULT/rpc_backend': value => $rpc_backend;
'DEFAULT/notification_topics': value => $notification_topics; 'DEFAULT/notification_topics': value => $notification_topics;
'DEFAULT/notify_api_faults': value => $notify_api_faults; 'DEFAULT/notify_api_faults': value => $notify_api_faults;
@@ -643,18 +628,6 @@ class nova(
nova_config { 'DEFAULT/notify_on_state_change': ensure => absent; } nova_config { 'DEFAULT/notify_on_state_change': ensure => absent; }
} }
# Syslog configuration
if $use_syslog {
nova_config {
'DEFAULT/use_syslog': value => true;
'DEFAULT/syslog_log_facility': value => $log_facility;
}
} else {
nova_config {
'DEFAULT/use_syslog': value => false;
}
}
if $os_region_name { if $os_region_name {
nova_config { nova_config {
'cinder/os_region_name': value => $os_region_name; 'cinder/os_region_name': value => $os_region_name;

View File

@@ -1,9 +1,34 @@
# Class nova::logging # Class nova::logging
# #
# nova extended logging configuration # nova logging configuration
# #
# == parameters # == 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/nova'
#
# [*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 undef.
@@ -66,6 +91,12 @@
# Example: 'Y-%m-%d %H:%M:%S' # Example: 'Y-%m-%d %H:%M:%S'
class nova::logging( class nova::logging(
$use_syslog = false,
$use_stderr = true,
$log_facility = 'LOG_USER',
$log_dir = '/var/log/nova',
$verbose = false,
$debug = false,
$logging_context_format_string = undef, $logging_context_format_string = undef,
$logging_default_format_string = undef, $logging_default_format_string = undef,
$logging_debug_format_suffix = undef, $logging_debug_format_suffix = undef,
@@ -79,6 +110,24 @@ class nova::logging(
$log_date_format = undef, $log_date_format = undef,
) { ) {
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use nova::<myparam> first then nova::logging::<myparam>.
$use_syslog_real = pick($::nova::use_syslog,$use_syslog)
$use_stderr_real = pick($::nova::use_stderr,$use_stderr)
$log_facility_real = pick($::nova::log_facility,$log_facility)
$log_dir_real = pick($::nova::log_dir,$log_dir)
$verbose_real = pick($::nova::verbose,$verbose)
$debug_real = pick($::nova::debug,$debug)
nova_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 { if $logging_context_format_string {
nova_config { nova_config {
'DEFAULT/logging_context_format_string' : 'DEFAULT/logging_context_format_string' :

View File

@@ -6,6 +6,10 @@ describe 'nova' do
context 'with default parameters' do context 'with default parameters' do
it 'contains the logging class' do
is_expected.to contain_class('nova::logging')
end
it 'installs packages' do it 'installs packages' do
is_expected.to contain_package('python-greenlet').with( is_expected.to contain_package('python-greenlet').with(
:ensure => 'present', :ensure => 'present',
@@ -23,12 +27,6 @@ describe 'nova' do
end end
it 'creates various files and folders' do it 'creates various files and folders' do
is_expected.to contain_file('/var/log/nova').with(
:ensure => 'directory',
:mode => '0750',
:owner => 'nova',
:require => 'Package[nova-common]'
)
is_expected.to contain_file('/etc/nova/nova.conf').with( is_expected.to contain_file('/etc/nova/nova.conf').with(
:mode => '0640', :mode => '0640',
:owner => 'nova', :owner => 'nova',
@@ -68,10 +66,6 @@ describe 'nova' do
end end
it 'configures various things' do it 'configures various things' do
is_expected.to contain_nova_config('DEFAULT/verbose').with_value(false)
is_expected.to contain_nova_config('DEFAULT/debug').with_value(false)
is_expected.to contain_nova_config('DEFAULT/use_stderr').with_value(true)
is_expected.to contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova')
is_expected.to contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova') is_expected.to contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova')
is_expected.to contain_nova_config('DEFAULT/lock_path').with_value(platform_params[:lock_path]) is_expected.to contain_nova_config('DEFAULT/lock_path').with_value(platform_params[:lock_path])
is_expected.to contain_nova_config('DEFAULT/service_down_time').with_value('60') is_expected.to contain_nova_config('DEFAULT/service_down_time').with_value('60')
@@ -86,9 +80,6 @@ describe 'nova' do
is_expected.to contain_class('nova::utilities') is_expected.to contain_class('nova::utilities')
end end
it 'disables syslog' do
is_expected.to contain_nova_config('DEFAULT/use_syslog').with_value(false)
end
end end
context 'with overridden parameters' do context 'with overridden parameters' do
@@ -150,9 +141,6 @@ describe 'nova' do
end end
it 'configures various things' do it 'configures various things' do
is_expected.to contain_nova_config('DEFAULT/verbose').with_value(true)
is_expected.to contain_nova_config('DEFAULT/debug').with_value(true)
is_expected.to contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova2')
is_expected.to contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova2') is_expected.to contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova2')
is_expected.to contain_nova_config('DEFAULT/lock_path').with_value('/var/locky/path') is_expected.to contain_nova_config('DEFAULT/lock_path').with_value('/var/locky/path')
is_expected.to contain_nova_config('DEFAULT/service_down_time').with_value('120') is_expected.to contain_nova_config('DEFAULT/service_down_time').with_value('120')
@@ -176,11 +164,6 @@ describe 'nova' do
is_expected.to_not contain_class('nova::utilities') is_expected.to_not contain_class('nova::utilities')
end end
context 'with logging directory disabled' do
before { params.merge!( :log_dir => false) }
it { is_expected.to contain_nova_config('DEFAULT/log_dir').with_ensure('absent') }
end
end end
context 'with wrong notify_on_state_change parameter' do context 'with wrong notify_on_state_change parameter' do
@@ -203,29 +186,6 @@ describe 'nova' do
end end
end end
context 'with syslog enabled' do
let :params do
{ :use_syslog => 'true' }
end
it 'configures syslog' do
is_expected.to contain_nova_config('DEFAULT/use_syslog').with_value(true)
is_expected.to contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_USER')
end
end
context 'with syslog enabled and log_facility parameter' do
let :params do
{ :use_syslog => 'true',
:log_facility => 'LOG_LOCAL0' }
end
it 'configures syslog' do
is_expected.to contain_nova_config('DEFAULT/use_syslog').with_value(true)
is_expected.to contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0')
end
end
context 'with rabbit_hosts parameter' do context 'with rabbit_hosts parameter' do
let :params do let :params do
{ :rabbit_hosts => ['rabbit:5673', 'rabbit2:5674'] } { :rabbit_hosts => ['rabbit:5673', 'rabbit2:5674'] }
@@ -603,9 +563,6 @@ describe 'nova' do
end end
it_behaves_like 'nova' it_behaves_like 'nova'
it 'creates the log folder with the right group for Debian' do
is_expected.to contain_file('/var/log/nova').with(:group => 'nova')
end
end end
context 'on Ubuntu platforms' do context 'on Ubuntu platforms' do
@@ -620,9 +577,6 @@ describe 'nova' do
end end
it_behaves_like 'nova' it_behaves_like 'nova'
it 'creates the log folder with the right group for Ubuntu' do
is_expected.to contain_file('/var/log/nova').with(:group => 'adm')
end
end end
context 'on RedHat platforms' do context 'on RedHat platforms' do
@@ -637,8 +591,5 @@ describe 'nova' do
it_behaves_like 'nova' it_behaves_like 'nova'
it 'creates the log folder with the right group for RedHat' do
is_expected.to contain_file('/var/log/nova').with(:group => 'nova')
end
end end
end end

View File

@@ -24,11 +24,26 @@ describe 'nova::logging' do
:instance_format => '[instance: %(uuid)s] ', :instance_format => '[instance: %(uuid)s] ',
:instance_uuid_format => '[instance: %(uuid)s] ', :instance_uuid_format => '[instance: %(uuid)s] ',
:log_date_format => '%Y-%m-%d %H:%M:%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 end
shared_examples_for 'nova-logging' do shared_examples_for 'nova-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 context 'with extended logging options' do
before { params.merge!( log_params ) } before { params.merge!( log_params ) }
it_configures 'logging params set' it_configures 'logging params set'
@@ -40,6 +55,27 @@ describe 'nova::logging' do
end end
shared_examples 'basic default logging settings' do
it 'configures nova logging settins with default values' do
is_expected.to contain_nova_config('DEFAULT/use_syslog').with(:value => 'false')
is_expected.to contain_nova_config('DEFAULT/use_stderr').with(:value => 'true')
is_expected.to contain_nova_config('DEFAULT/log_dir').with(:value => '/var/log/nova')
is_expected.to contain_nova_config('DEFAULT/verbose').with(:value => 'false')
is_expected.to contain_nova_config('DEFAULT/debug').with(:value => 'false')
end
end
shared_examples 'basic non-default logging settings' do
it 'configures nova logging settins with non-default values' do
is_expected.to contain_nova_config('DEFAULT/use_syslog').with(:value => 'true')
is_expected.to contain_nova_config('DEFAULT/use_stderr').with(:value => 'false')
is_expected.to contain_nova_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO')
is_expected.to contain_nova_config('DEFAULT/log_dir').with(:value => '/var/log')
is_expected.to contain_nova_config('DEFAULT/verbose').with(:value => 'true')
is_expected.to contain_nova_config('DEFAULT/debug').with(:value => 'true')
end
end
shared_examples_for 'logging params set' do shared_examples_for 'logging params set' do
it 'enables logging params' do it 'enables logging params' do
is_expected.to contain_nova_config('DEFAULT/logging_context_format_string').with_value( is_expected.to contain_nova_config('DEFAULT/logging_context_format_string').with_value(