Add logging class
- Add logging class to manage olso.log related options - Add option 'manage_logging' for init class to make it possible to evaluate logging class separately from init class in one catalog - Deprecate 'verbose' option Change-Id: I641f78a631911d87623d90340848c3892ae706df
This commit is contained in:
parent
56d2a46738
commit
2471f3ad03
@ -13,13 +13,9 @@
|
||||
# (optional) The state of the package
|
||||
# Defaults to 'present'
|
||||
#
|
||||
# [*verbose*]
|
||||
# (optional) Verbose logging
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*debug*]
|
||||
# (optional) Print debug messages in the logs
|
||||
# Defaults to $::os_service_default
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*bind_host*]
|
||||
# (optional) The IP/interface to bind to
|
||||
@ -220,24 +216,29 @@
|
||||
#
|
||||
# [*use_syslog*]
|
||||
# (optional) Use syslog for logging
|
||||
# Defaults to $::os_service_default
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*use_stderr*]
|
||||
# (optional) Use stderr for logging
|
||||
# Defaults to $::os_service_default
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*log_facility*]
|
||||
# (optional) Syslog facility to receive log lines
|
||||
# Defaults to $::os_service_default
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*log_file*]
|
||||
# (optional) Where to log
|
||||
# Defaults to $::os_service_default
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*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/neutron
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*manage_logging*]
|
||||
# (optional) Whether to manage olso.logging options
|
||||
# If set to false, neutron::logging class should be evaluated
|
||||
# Defaults to true.
|
||||
#
|
||||
# [*state_path*]
|
||||
# (optional) Where to store state files. This directory must be writable
|
||||
@ -258,11 +259,14 @@
|
||||
#
|
||||
# [*network_device_mtu*]
|
||||
#
|
||||
# [*verbose*]
|
||||
# (optional) Deprecated. Verbose logging
|
||||
# Defaults to undef
|
||||
#
|
||||
class neutron (
|
||||
$enabled = true,
|
||||
$package_ensure = 'present',
|
||||
$verbose = $::os_service_default,
|
||||
$debug = $::os_service_default,
|
||||
$debug = undef,
|
||||
$bind_host = $::os_service_default,
|
||||
$bind_port = $::os_service_default,
|
||||
$core_plugin = 'openvswitch',
|
||||
@ -307,19 +311,24 @@ class neutron (
|
||||
$cert_file = $::os_service_default,
|
||||
$key_file = $::os_service_default,
|
||||
$ca_file = $::os_service_default,
|
||||
$use_syslog = $::os_service_default,
|
||||
$use_stderr = $::os_service_default,
|
||||
$log_facility = $::os_service_default,
|
||||
$log_file = $::os_service_default,
|
||||
$log_dir = '/var/log/neutron',
|
||||
$use_syslog = undef,
|
||||
$use_stderr = undef,
|
||||
$log_facility = undef,
|
||||
$log_file = undef,
|
||||
$log_dir = undef,
|
||||
$manage_logging = true,
|
||||
$state_path = $::os_service_default,
|
||||
$lock_path = '$state_path/lock',
|
||||
$purge_config = false,
|
||||
# DEPRECATED PARAMETERS
|
||||
$network_device_mtu = undef,
|
||||
$verbose = undef,
|
||||
) {
|
||||
|
||||
include ::neutron::params
|
||||
if $manage_logging {
|
||||
include ::neutron::logging
|
||||
}
|
||||
|
||||
if ! is_service_default($use_ssl) and ($use_ssl) {
|
||||
if is_service_default($cert_file) {
|
||||
@ -393,16 +402,6 @@ class neutron (
|
||||
'agent/report_interval': value => $report_interval;
|
||||
}
|
||||
|
||||
oslo::log { 'neutron_config':
|
||||
verbose => $verbose,
|
||||
debug => $debug,
|
||||
use_stderr => $use_stderr,
|
||||
use_syslog => $use_syslog,
|
||||
syslog_log_facility => $log_facility,
|
||||
log_file => $log_file,
|
||||
log_dir => $log_dir,
|
||||
}
|
||||
|
||||
oslo::concurrency { 'neutron_config': lock_path => $lock_path }
|
||||
|
||||
if ! is_service_default ($service_plugins) and ($service_plugins) {
|
||||
|
169
manifests/logging.pp
Normal file
169
manifests/logging.pp
Normal file
@ -0,0 +1,169 @@
|
||||
# == Class: neutron::logging
|
||||
#
|
||||
# Neutron logging configuration
|
||||
#
|
||||
# === Parameters:
|
||||
#
|
||||
# [*debug*]
|
||||
# (optional) Print debug messages in the logs
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*use_syslog*]
|
||||
# (optional) Use syslog for logging
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*use_stderr*]
|
||||
# (optional) Use stderr for logging
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*log_facility*]
|
||||
# (optional) Syslog facility to receive log lines
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*log_file*]
|
||||
# (optional) Where to log
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*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/neutron
|
||||
#
|
||||
# [*log_config_append*]
|
||||
# The name of an additional logging configuration file.
|
||||
# Defaults to $::os_service_default
|
||||
# See https://docs.python.org/2/howto/logging.html
|
||||
#
|
||||
# [*log_date_format*]
|
||||
# (Optional) Format string for %%(asctime)s in log records.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: 'Y-%m-%d %H:%M:%S'
|
||||
#
|
||||
# [*watch_log_file*]
|
||||
# (Optional) Uses logging handler designed to watch file system (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.
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*logging_context_format_string*]
|
||||
# (Optional) Format string to use for log messages with context.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s \
|
||||
# [%(request_id)s %(user_identity)s] %(instance)s%(message)s'
|
||||
#
|
||||
# [*logging_default_format_string*]
|
||||
# (Optional) Format string to use for log messages when context is undefined.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s \
|
||||
# %(name)s [-] %(instance)s%(message)s'
|
||||
#
|
||||
# [*logging_debug_format_suffix*]
|
||||
# (Optional) Additional data to append to log message when logging level for the message is DEBUG'
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '%(funcName)s %(pathname)s:%(lineno)d'
|
||||
#
|
||||
# [*logging_exception_prefix*]
|
||||
# (Optional) Prefix each line of exception output with this format.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '%(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s'
|
||||
#
|
||||
# [*logging_user_identity_format*]
|
||||
# (Optional) Defines the format string for %(user_identity)s that is used in logging_context_format_string.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s'
|
||||
#
|
||||
# [*default_log_levels*]
|
||||
# (Optional) Hash of logger (keys) and level (values) pairs.
|
||||
# Defaults to $::os_service_default
|
||||
# Example:
|
||||
# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN',
|
||||
# 'sqlalchemy' => 'WARN', 'suds' => 'INFO', 'iso8601' => 'WARN',
|
||||
# 'requests.packages.urllib3.connectionpool' => 'WARN' }
|
||||
#
|
||||
# [*publish_errors*]
|
||||
# (Optional) Enables or disables publication of error events (boolean value).
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*instance_format*]
|
||||
# (Optional) The format for an instance that is passed with the log message.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '[instance: %(uuid)s] '
|
||||
#
|
||||
# [*instance_uuid_format*]
|
||||
# (Optional) The format for an instance UUID that is passed with the log message.
|
||||
# Defaults to $::os_service_default
|
||||
# Example: '[instance: %(uuid)s] '
|
||||
#
|
||||
# [*fatal_deprecations*]
|
||||
# (Optional) Enables or disables fatal status of deprecations (boolean value).
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# DEPRECATED PARAMETERS
|
||||
#
|
||||
# [*verbose*]
|
||||
# (optional) Deprecated. Verbose logging
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
class neutron::logging (
|
||||
$verbose = $::os_service_default,
|
||||
$debug = $::os_service_default,
|
||||
$use_syslog = $::os_service_default,
|
||||
$use_stderr = $::os_service_default,
|
||||
$log_facility = $::os_service_default,
|
||||
$log_file = $::os_service_default,
|
||||
$log_dir = '/var/log/neutron',
|
||||
$log_config_append = $::os_service_default,
|
||||
$log_date_format = $::os_service_default,
|
||||
$watch_log_file = $::os_service_default,
|
||||
$syslog_log_facility = $::os_service_default,
|
||||
$logging_context_format_string = $::os_service_default,
|
||||
$logging_default_format_string = $::os_service_default,
|
||||
$logging_debug_format_suffix = $::os_service_default,
|
||||
$logging_exception_prefix = $::os_service_default,
|
||||
$logging_user_identity_format = $::os_service_default,
|
||||
$default_log_levels = $::os_service_default,
|
||||
$publish_errors = $::os_service_default,
|
||||
$instance_format = $::os_service_default,
|
||||
$instance_uuid_format = $::os_service_default,
|
||||
$fatal_deprecations = $::os_service_default,
|
||||
) {
|
||||
|
||||
$verbose_real = pick($::neutron::verbose,$verbose)
|
||||
$debug_real = pick($::neutron::debug,$debug)
|
||||
$use_syslog_real = pick($::neutron::use_syslog,$use_syslog)
|
||||
$use_stderr_real = pick($::neutron::use_stderr,$use_stderr)
|
||||
$log_facility_real = pick($::neutron::log_facility,$log_facility)
|
||||
$log_file_real = pick($::neutron::log_file,$log_file)
|
||||
$log_dir_real = pick($::neutron::log_dir,$log_dir)
|
||||
|
||||
if ! is_service_default($verbose_real) {
|
||||
warning('verbose parameter is deprecated and will be removed.')
|
||||
}
|
||||
|
||||
oslo::log { 'neutron_config':
|
||||
verbose => $verbose_real,
|
||||
debug => $debug_real,
|
||||
use_stderr => $use_stderr_real,
|
||||
use_syslog => $use_syslog_real,
|
||||
syslog_log_facility => $log_facility_real,
|
||||
log_file => $log_file_real,
|
||||
log_dir => $log_dir_real,
|
||||
log_config_append => $log_config_append,
|
||||
log_date_format => $log_date_format,
|
||||
watch_log_file => $watch_log_file,
|
||||
logging_context_format_string => $logging_context_format_string,
|
||||
logging_default_format_string => $logging_default_format_string,
|
||||
logging_debug_format_suffix => $logging_debug_format_suffix,
|
||||
logging_exception_prefix => $logging_exception_prefix,
|
||||
logging_user_identity_format => $logging_user_identity_format,
|
||||
default_log_levels => $default_log_levels,
|
||||
publish_errors => $publish_errors,
|
||||
instance_format => $instance_format,
|
||||
instance_uuid_format => $instance_uuid_format,
|
||||
fatal_deprecations => $fatal_deprecations,
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add logging class to manage olso.log related options
|
||||
init class can still be used for managing the limited number of options
|
||||
Add option _manage_logging_ for init class to make it possible to evaluate
|
||||
logging class separately from init class in one catalog
|
||||
deprecations:
|
||||
- _verbose_ option is deprecated and will be removed in future
|
133
spec/classes/neutron_logging_spec.rb
Normal file
133
spec/classes/neutron_logging_spec.rb
Normal file
@ -0,0 +1,133 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'neutron::logging' do
|
||||
|
||||
let :params do
|
||||
{
|
||||
}
|
||||
end
|
||||
|
||||
let :log_params do
|
||||
{
|
||||
: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 TRACE %(name)s %(instance)s',
|
||||
:logging_user_identity_format => '%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s',
|
||||
:log_config_append => '/etc/neutron/logging.conf',
|
||||
:publish_errors => true,
|
||||
:default_log_levels => {
|
||||
'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN',
|
||||
'sqlalchemy' => 'WARN', 'suds' => 'INFO', 'iso8601' => 'WARN',
|
||||
'requests.packages.urllib3.connectionpool' => 'WARN' },
|
||||
:fatal_deprecations => true,
|
||||
:instance_format => '[instance: %(uuid)s] ',
|
||||
:instance_uuid_format => '[instance: %(uuid)s] ',
|
||||
:log_date_format => '%Y-%m-%d %H:%M:%S',
|
||||
:use_syslog => false,
|
||||
:use_stderr => false,
|
||||
:log_facility => 'LOG_USER',
|
||||
:log_dir => '/var/log',
|
||||
:log_file => 'neutron.log',
|
||||
:watch_log_file => true,
|
||||
:verbose => true,
|
||||
:debug => true,
|
||||
}
|
||||
end
|
||||
|
||||
shared_examples_for 'neutron-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'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples 'basic default logging settings' do
|
||||
it 'configures neutron logging settins with default values' do
|
||||
is_expected.to contain_neutron_config('DEFAULT/use_syslog').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/use_stderr').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/syslog_log_facility').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_dir').with(:value => '/var/log/neutron')
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_file').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/watch_log_file').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/verbose').with(:value => '<SERVICE DEFAULT>')
|
||||
is_expected.to contain_neutron_config('DEFAULT/debug').with(:value => '<SERVICE DEFAULT>')
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'basic non-default logging settings' do
|
||||
it 'configures neutron logging settins with non-default values' do
|
||||
is_expected.to contain_neutron_config('DEFAULT/use_syslog').with(:value => 'false')
|
||||
is_expected.to contain_neutron_config('DEFAULT/use_stderr').with(:value => 'false')
|
||||
is_expected.to contain_neutron_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_USER')
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_dir').with(:value => '/var/log')
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_file').with(:value => 'neutron.log')
|
||||
is_expected.to contain_neutron_config('DEFAULT/watch_log_file').with(:value => 'true')
|
||||
is_expected.to contain_neutron_config('DEFAULT/verbose').with(:value => 'true')
|
||||
is_expected.to contain_neutron_config('DEFAULT/debug').with(:value => 'true')
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'logging params set' do
|
||||
it 'enables logging params' do
|
||||
is_expected.to contain_neutron_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_neutron_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_neutron_config('DEFAULT/logging_user_identity_format').with_value(
|
||||
'%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/logging_debug_format_suffix').with_value(
|
||||
'%(funcName)s %(pathname)s:%(lineno)d')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/logging_exception_prefix').with_value(
|
||||
'%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_config_append').with_value(
|
||||
'/etc/neutron/logging.conf')
|
||||
is_expected.to contain_neutron_config('DEFAULT/publish_errors').with_value(
|
||||
true)
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/default_log_levels').with_value(
|
||||
'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/fatal_deprecations').with_value(
|
||||
true)
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/instance_format').with_value(
|
||||
'[instance: %(uuid)s] ')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/instance_uuid_format').with_value(
|
||||
'[instance: %(uuid)s] ')
|
||||
|
||||
is_expected.to contain_neutron_config('DEFAULT/log_date_format').with_value(
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_configures 'neutron-logging'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user