Barbican $::os_service_default for db and logging

Switch to $::os_service_default all params in logging and db.
Changes: logging.pp, db.pp and tests.

Related-bug: #1515273

Change-Id: I291db92684e6f31aca2bffa55ed2f3832e905a43
This commit is contained in:
Iury Gregory Melo Ferreira 2015-11-24 20:14:18 +00:00
parent 6ca9a4310b
commit e2e560642a
9 changed files with 106 additions and 211 deletions

View File

@ -10,37 +10,37 @@
# #
# [*database_idle_timeout*] # [*database_idle_timeout*]
# Timeout when db connections should be reaped. # Timeout when db connections should be reaped.
# (Optional) Defaults to 3600. # (Optional) Defaults to $::os_service_default
# #
# [*database_max_retries*] # [*database_max_retries*]
# Maximum number of database connection retries during startup. # Maximum number of database connection retries during startup.
# Setting -1 implies an infinite retry count. # Setting -1 implies an infinite retry count.
# (Optional) Defaults to 10. # (Optional) Defaults to $::os_service_default
# #
# [*database_retry_interval*] # [*database_retry_interval*]
# Interval between retries of opening a database connection. # Interval between retries of opening a database connection.
# (Optional) Defaults to 10. # (Optional) Defaults to $::os_service_default
# #
# [*database_min_pool_size*] # [*database_min_pool_size*]
# Minimum number of SQL connections to keep open in a pool. # Minimum number of SQL connections to keep open in a pool.
# (Optional) Defaults to 1. # (Optional) Defaults to $::os_service_default
# #
# [*database_max_pool_size*] # [*database_max_pool_size*]
# Maximum number of SQL connections to keep open in a pool. # Maximum number of SQL connections to keep open in a pool.
# (Optional) Defaults to 10. # (Optional) Defaults to $::os_service_default
# #
# [*database_max_overflow*] # [*database_max_overflow*]
# If set, use this value for max_overflow with sqlalchemy. # If set, use this value for max_overflow with sqlalchemy.
# (Optional) Defaults to 20. # (Optional) Defaults to $::os_service_default
# #
class barbican::db ( class barbican::db (
$database_connection = 'sqlite:////var/lib/barbican/barbican.sqlite', $database_connection = 'sqlite:////var/lib/barbican/barbican.sqlite',
$database_idle_timeout = 3600, $database_idle_timeout = $::os_service_default,
$database_min_pool_size = 1, $database_min_pool_size = $::os_service_default,
$database_max_pool_size = 10, $database_max_pool_size = $::os_service_default,
$database_max_retries = 10, $database_max_retries = $::os_service_default,
$database_retry_interval = 10, $database_retry_interval = $::os_service_default,
$database_max_overflow = 20, $database_max_overflow = $::os_service_default,
) { ) {
include ::barbican::params include ::barbican::params
@ -56,42 +56,40 @@ class barbican::db (
validate_re($database_connection_real, validate_re($database_connection_real,
'(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') '(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
if $database_connection_real { case $database_connection_real {
case $database_connection_real { /^mysql:\/\//: {
/^mysql:\/\//: { $backend_package = false
$backend_package = false require 'mysql::bindings'
require 'mysql::bindings' require 'mysql::bindings::python'
require 'mysql::bindings::python'
}
/^postgresql:\/\//: {
$backend_package = false
require 'postgresql::lib::python'
}
/^sqlite:\/\//: {
$backend_package = $::barbican::params::sqlite_package_name
}
default: {
fail('Unsupported backend configured')
}
} }
/^postgresql:\/\//: {
if $backend_package and !defined(Package[$backend_package]) { $backend_package = false
package {'barbican-backend-package': require 'postgresql::lib::python'
ensure => present,
name => $backend_package,
tag => 'openstack',
}
} }
/^sqlite:\/\//: {
barbican_config { $backend_package = $::barbican::params::sqlite_package_name
'database/connection': value => $database_connection_real, secret => true; }
'database/idle_timeout': value => $database_idle_timeout_real; default: {
'database/min_pool_size': value => $database_min_pool_size_real; fail('Unsupported backend configured')
'database/max_retries': value => $database_max_retries_real;
'database/retry_interval': value => $database_retry_interval_real;
'database/max_pool_size': value => $database_max_pool_size_real;
'database/max_overflow': value => $database_max_overflow_real;
} }
} }
if $backend_package and !defined(Package[$backend_package]) {
package {'barbican-backend-package':
ensure => present,
name => $backend_package,
tag => 'openstack',
}
}
barbican_config {
'database/connection': value => $database_connection_real, secret => true;
'database/idle_timeout': value => $database_idle_timeout_real;
'database/min_pool_size': value => $database_min_pool_size_real;
'database/max_retries': value => $database_max_retries_real;
'database/retry_interval': value => $database_retry_interval_real;
'database/max_pool_size': value => $database_max_pool_size_real;
'database/max_overflow': value => $database_max_overflow_real;
}
} }

View File

@ -6,34 +6,34 @@
# #
# [*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',
@ -45,167 +45,61 @@
# #
# [*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 barbican::logging( class barbican::logging(
$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,
) { ) {
if $logging_context_format_string { if is_service_default($default_log_levels) {
barbican_config { $default_log_levels_real = $default_log_levels
'DEFAULT/logging_context_format_string' : } else {
value => $logging_context_format_string; $default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',')
} }
}
else {
barbican_config {
'DEFAULT/logging_context_format_string' : ensure => absent;
}
}
if $logging_default_format_string {
barbican_config {
'DEFAULT/logging_default_format_string' :
value => $logging_default_format_string;
}
}
else {
barbican_config {
'DEFAULT/logging_default_format_string' : ensure => absent;
}
}
if $logging_debug_format_suffix {
barbican_config {
'DEFAULT/logging_debug_format_suffix' :
value => $logging_debug_format_suffix;
}
}
else {
barbican_config {
'DEFAULT/logging_debug_format_suffix' : ensure => absent;
}
}
if $logging_exception_prefix {
barbican_config {
'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix;
}
}
else {
barbican_config {
'DEFAULT/logging_exception_prefix' : ensure => absent;
}
}
if $log_config_append {
barbican_config {
'DEFAULT/log_config_append' : value => $log_config_append;
}
}
else {
barbican_config {
'DEFAULT/log_config_append' : ensure => absent;
}
}
if $default_log_levels {
barbican_config {
'DEFAULT/default_log_levels' :
value => join(sort(join_keys_to_values($default_log_levels, '=')), ',');
}
}
else {
barbican_config {
'DEFAULT/default_log_levels' : ensure => absent;
}
}
if $publish_errors {
barbican_config {
'DEFAULT/publish_errors' : value => $publish_errors;
}
}
else {
barbican_config {
'DEFAULT/publish_errors' : ensure => absent;
}
}
if $fatal_deprecations {
barbican_config {
'DEFAULT/fatal_deprecations' : value => $fatal_deprecations;
}
}
else {
barbican_config {
'DEFAULT/fatal_deprecations' : ensure => absent;
}
}
if $instance_format {
barbican_config {
'DEFAULT/instance_format' : value => $instance_format;
}
}
else {
barbican_config {
'DEFAULT/instance_format' : ensure => absent;
}
}
if $instance_uuid_format {
barbican_config {
'DEFAULT/instance_uuid_format' : value => $instance_uuid_format;
}
}
else {
barbican_config {
'DEFAULT/instance_uuid_format' : ensure => absent;
}
}
if $log_date_format {
barbican_config {
'DEFAULT/log_date_format' : value => $log_date_format;
}
}
else {
barbican_config {
'DEFAULT/log_date_format' : ensure => absent;
}
}
barbican_config {
'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/log_config_append': value => $log_config_append;
'DEFAULT/default_log_levels': value => $default_log_levels_real;
'DEFAULT/publish_errors': value => $publish_errors;
'DEFAULT/fatal_deprecations': value => $fatal_deprecations;
'DEFAULT/instance_format': value => $instance_format;
'DEFAULT/instance_uuid_format': value => $instance_uuid_format;
'DEFAULT/log_date_format': value => $log_date_format;
}
} }

View File

@ -10,7 +10,7 @@ describe 'barbican::db::mysql' do
end end
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
let :params do let :params do

View File

@ -12,11 +12,11 @@ describe 'barbican::db::postgresql' do
context 'on a RedHat osfamily' do context 'on a RedHat osfamily' do
let :facts do let :facts do
{ @default_facts.merge({
:osfamily => 'RedHat', :osfamily => 'RedHat',
:operatingsystemrelease => '7.0', :operatingsystemrelease => '7.0',
:concat_basedir => '/var/lib/puppet/concat' :concat_basedir => '/var/lib/puppet/concat'
} })
end end
context 'with only required parameters' do context 'with only required parameters' do
@ -34,12 +34,12 @@ describe 'barbican::db::postgresql' do
context 'on a Debian osfamily' do context 'on a Debian osfamily' do
let :facts do let :facts do
{ @default_facts.merge({
:operatingsystemrelease => '7.8', :operatingsystemrelease => '7.8',
:operatingsystem => 'Debian', :operatingsystem => 'Debian',
:osfamily => 'Debian', :osfamily => 'Debian',
:concat_basedir => '/var/lib/puppet/concat' :concat_basedir => '/var/lib/puppet/concat'
} })
end end
context 'with only required parameters' do context 'with only required parameters' do

View File

@ -8,10 +8,10 @@ describe 'barbican::db' do
it { is_expected.to contain_class('barbican::params') } it { is_expected.to contain_class('barbican::params') }
it { is_expected.to contain_barbican_config('database/connection').with_value('sqlite:////var/lib/barbican/barbican.sqlite') } it { is_expected.to contain_barbican_config('database/connection').with_value('sqlite:////var/lib/barbican/barbican.sqlite') }
it { is_expected.to contain_barbican_config('database/idle_timeout').with_value('3600') } it { is_expected.to contain_barbican_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_barbican_config('database/min_pool_size').with_value('1') } it { is_expected.to contain_barbican_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_barbican_config('database/max_retries').with_value('10') } it { is_expected.to contain_barbican_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_barbican_config('database/retry_interval').with_value('10') } it { is_expected.to contain_barbican_config('database/retry_interval').with_value('<SERVICE DEFAULT>') }
end end
@ -58,10 +58,10 @@ describe 'barbican::db' 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 => 'jessie', :operatingsystemrelease => 'jessie',
} })
end end
it_configures 'barbican::db' it_configures 'barbican::db'
@ -84,9 +84,9 @@ describe 'barbican::db' do
context 'on Redhat platforms' do context 'on Redhat platforms' do
let :facts do let :facts do
{ :osfamily => 'RedHat', @default_facts.merge({ :osfamily => 'RedHat',
:operatingsystemrelease => '7.1', :operatingsystemrelease => '7.1',
} })
end end
it_configures 'barbican::db' it_configures 'barbican::db'

View File

@ -7,7 +7,7 @@ require 'spec_helper'
describe 'barbican::keystone::auth' do describe 'barbican::keystone::auth' do
let :facts do let :facts do
{ :osfamily => 'Debian' } @default_facts.merge({ :osfamily => 'Debian' })
end end
describe 'with default class parameters' do describe 'with default class parameters' do

View File

@ -84,13 +84,13 @@ describe 'barbican::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_barbican_config("DEFAULT/#{param}").with_ensure('absent') } it { is_expected.to contain_barbican_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 'barbican-logging' it_configures 'barbican-logging'
@ -98,7 +98,7 @@ describe 'barbican::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 'barbican-logging' it_configures 'barbican-logging'

View File

@ -25,7 +25,7 @@ describe 'barbican::policy' 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
it_configures 'barbican policies' it_configures 'barbican policies'
@ -33,7 +33,7 @@ describe 'barbican::policy' 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 'barbican policies' it_configures 'barbican policies'

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! }