From 9b7ac7a647487bc0227c57d0cae61afa60bf3281 Mon Sep 17 00:00:00 2001 From: Iury Gregory Melo Ferreira Date: Wed, 2 Dec 2015 17:43:42 +0000 Subject: [PATCH] Switch magnum to $::os_service_default Switch to $::os_service_default all params in logging and db. Changes: logging.pp, db.pp and tests. Change-Id: Ic3ff963064fcb34f86056d88b6f2dce5e270fedc --- manifests/db.pp | 88 +++++---- manifests/logging.pp | 218 ++++++---------------- spec/classes/magnum_db_mysql_spec.rb | 2 +- spec/classes/magnum_db_postgresql_spec.rb | 8 +- spec/classes/magnum_db_spec.rb | 22 ++- spec/classes/magnum_keystone_auth_spec.rb | 2 +- spec/classes/magnum_logging_spec.rb | 16 +- spec/classes/magnum_policy_spec.rb | 4 +- spec/spec_helper.rb | 3 + 9 files changed, 129 insertions(+), 234 deletions(-) diff --git a/manifests/db.pp b/manifests/db.pp index b9be26f..5b76f93 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -10,37 +10,37 @@ # # [*database_idle_timeout*] # Timeout when db connections should be reaped. -# (Optional) Defaults to 3600. +# (Optional) Defaults to $::os_service_default # # [*database_max_retries*] # Maximum number of database connection retries during startup. # Setting -1 implies an infinite retry count. -# (Optional) Defaults to 10. +# (Optional) Defaults to $::os_service_default # # [*database_retry_interval*] # Interval between retries of opening a database connection. -# (Optional) Defaults to 10. +# (Optional) Defaults to $::os_service_default # # [*database_min_pool_size*] # 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*] # Maximum number of SQL connections to keep open in a pool. -# (Optional) Defaults to 10. +# (Optional) Defaults to $::os_service_default # # [*database_max_overflow*] # If set, use this value for max_overflow with sqlalchemy. -# (Optional) Defaults to 20. +# (Optional) Defaults to $::os_service_default # class magnum::db ( $database_connection = 'mysql://magnum:secrete@localhost:3306/magnum', - $database_idle_timeout = 3600, - $database_min_pool_size = 1, - $database_max_pool_size = 10, - $database_max_retries = 10, - $database_retry_interval = 10, - $database_max_overflow = 20, + $database_idle_timeout = $::os_service_default, + $database_min_pool_size = $::os_service_default, + $database_max_pool_size = $::os_service_default, + $database_max_retries = $::os_service_default, + $database_retry_interval = $::os_service_default, + $database_max_overflow = $::os_service_default, ) { $database_connection_real = pick($::magnum::database_connection, $database_connection) @@ -54,42 +54,40 @@ class magnum::db ( validate_re($database_connection_real, '(mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') - if $database_connection_real { - case $database_connection_real { - /^mysql:\/\//: { - $backend_package = false - require 'mysql::bindings' - require 'mysql::bindings::python' - } - /^postgresql:\/\//: { - $backend_package = false - require 'postgresql::lib::python' - } - /^sqlite:\/\//: { - $backend_package = $::magnum::params::sqlite_package_name - } - default: { - fail('Unsupported backend configured') - } + case $database_connection_real { + /^mysql:\/\//: { + $backend_package = false + require 'mysql::bindings' + require 'mysql::bindings::python' } - - if $backend_package and !defined(Package[$backend_package]) { - package {'magnum-backend-package': - ensure => present, - name => $backend_package, - tag => 'openstack', - } + /^postgresql:\/\//: { + $backend_package = false + require 'postgresql::lib::python' } - - magnum_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; + /^sqlite:\/\//: { + $backend_package = $::magnum::params::sqlite_package_name + } + default: { + fail('Unsupported backend configured') } } + if $backend_package and !defined(Package[$backend_package]) { + package {'magnum-backend-package': + ensure => present, + name => $backend_package, + tag => 'openstack', + } + } + + magnum_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; + } + } diff --git a/manifests/logging.pp b/manifests/logging.pp index 4418b35..fcaa6e2 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -6,23 +6,23 @@ # # [*verbose*] # (Optional) Should the daemons log verbose messages -# Defaults to false. +# Defaults to $::os_service_default # # [*debug*] # (Optional) Should the daemons log debug messages -# Defaults to false. +# Defaults to $::os_service_default # # [*use_syslog*] # (Optional) Use syslog for logging. -# Defaults to false. +# Defaults to $::os_service_default # # [*use_stderr*] # (optional) Use stderr for logging -# Defaults to true. +# Defaults to $::os_service_default # # [*log_facility*] # (Optional) Syslog facility to receive log lines. -# Defaults to 'LOG_USER'. +# Defaults to $::os_service_default # # [*log_dir*] # (optional) Directory where logs should be stored. @@ -31,34 +31,34 @@ # # [*logging_context_format_string*] # (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\ # [%(request_id)s %(user_identity)s] %(instance)s%(message)s' # # [*logging_default_format_string*] # (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\ # [-] %(instance)s%(message)s' # # [*logging_debug_format_suffix*] # (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' # # [*logging_exception_prefix*] # (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' # # [*log_config_append*] # 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 # # [*default_log_levels*] # (optional) Hash of logger (keys) and level (values) pairs. -# Defaults to undef. +# Defaults to $::os_service_default # Example: # { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', # 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', @@ -70,182 +70,74 @@ # # [*publish_errors*] # (optional) Publish error events (boolean value). -# Defaults to undef (false if unconfigured). +# Defaults to $::os_service_default # # [*fatal_deprecations*] # (optional) Make deprecations fatal (boolean value) -# Defaults to undef (false if unconfigured). +# Defaults to $::os_service_default # # [*instance_format*] # (optional) If an instance is passed with the log message, format it # like this (string value). -# Defaults to undef. +# Defaults to $::os_service_default # Example: '[instance: %(uuid)s] ' # # [*instance_uuid_format*] # (optional) If an instance UUID is passed with the log message, format # it like this (string value). -# Defaults to undef. +# Defaults to $::os_service_default # Example: instance_uuid_format='[instance: %(uuid)s] ' # # [*log_date_format*] # (optional) Format string for %%(asctime)s in log records. -# Defaults to undef. +# Defaults to $::os_service_default # Example: 'Y-%m-%d %H:%M:%S' class magnum::logging( - $use_syslog = false, - $use_stderr = true, - $log_facility = 'LOG_USER', + $use_syslog = $::os_service_default, + $use_stderr = $::os_service_default, + $log_facility = $::os_service_default, $log_dir = '/var/log/magnum', - $verbose = false, - $debug = false, - $logging_context_format_string = undef, - $logging_default_format_string = undef, - $logging_debug_format_suffix = undef, - $logging_exception_prefix = undef, - $log_config_append = undef, - $default_log_levels = undef, - $publish_errors = undef, - $fatal_deprecations = undef, - $instance_format = undef, - $instance_uuid_format = undef, - $log_date_format = undef, + $verbose = $::os_service_default, + $debug = $::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, + $log_config_append = $::os_service_default, + $default_log_levels = $::os_service_default, + $publish_errors = $::os_service_default, + $fatal_deprecations = $::os_service_default, + $instance_format = $::os_service_default, + $instance_uuid_format = $::os_service_default, + $log_date_format = $::os_service_default, ) { - magnum_config { - 'DEFAULT/use_syslog' : value => $use_syslog; - 'DEFAULT/use_stderr' : value => $use_stderr; - 'DEFAULT/log_dir' : value => $log_dir; - 'DEFAULT/verbose' : value => $verbose; - 'DEFAULT/debug' : value => $debug; - 'DEFAULT/syslog_log_facility' : value => $log_facility; + if is_service_default($default_log_levels) { + $default_log_levels_real = $default_log_levels + } else { + $default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',') } - if $logging_context_format_string { - magnum_config { - 'DEFAULT/logging_context_format_string' : - value => $logging_context_format_string; - } - } - else { - magnum_config { - 'DEFAULT/logging_context_format_string' : ensure => absent; - } - } - - if $logging_default_format_string { - magnum_config { - 'DEFAULT/logging_default_format_string' : - value => $logging_default_format_string; - } - } - else { - magnum_config { - 'DEFAULT/logging_default_format_string' : ensure => absent; - } - } - - if $logging_debug_format_suffix { - magnum_config { - 'DEFAULT/logging_debug_format_suffix' : - value => $logging_debug_format_suffix; - } - } - else { - magnum_config { - 'DEFAULT/logging_debug_format_suffix' : ensure => absent; - } - } - - if $logging_exception_prefix { - magnum_config { - 'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix; - } - } - else { - magnum_config { - 'DEFAULT/logging_exception_prefix' : ensure => absent; - } - } - - if $log_config_append { - magnum_config { - 'DEFAULT/log_config_append' : value => $log_config_append; - } - } - else { - magnum_config { - 'DEFAULT/log_config_append' : ensure => absent; - } - } - - if $default_log_levels { - magnum_config { - 'DEFAULT/default_log_levels' : - value => join(sort(join_keys_to_values($default_log_levels, '=')), ','); - } - } - else { - magnum_config { - 'DEFAULT/default_log_levels' : ensure => absent; - } - } - - if $publish_errors { - magnum_config { - 'DEFAULT/publish_errors' : value => $publish_errors; - } - } - else { - magnum_config { - 'DEFAULT/publish_errors' : ensure => absent; - } - } - - if $fatal_deprecations { - magnum_config { - 'DEFAULT/fatal_deprecations' : value => $fatal_deprecations; - } - } - else { - magnum_config { - 'DEFAULT/fatal_deprecations' : ensure => absent; - } - } - - if $instance_format { - magnum_config { - 'DEFAULT/instance_format' : value => $instance_format; - } - } - else { - magnum_config { - 'DEFAULT/instance_format' : ensure => absent; - } - } - - if $instance_uuid_format { - magnum_config { - 'DEFAULT/instance_uuid_format' : value => $instance_uuid_format; - } - } - else { - magnum_config { - 'DEFAULT/instance_uuid_format' : ensure => absent; - } - } - - if $log_date_format { - magnum_config { - 'DEFAULT/log_date_format' : value => $log_date_format; - } - } - else { - magnum_config { - 'DEFAULT/log_date_format' : ensure => absent; - } - } + magnum_config { + 'DEFAULT/use_syslog': value => $use_syslog; + 'DEFAULT/use_stderr': value => $use_stderr; + 'DEFAULT/log_dir': value => $log_dir; + 'DEFAULT/verbose': value => $verbose; + 'DEFAULT/debug': value => $debug; + 'DEFAULT/syslog_log_facility': value => $log_facility; + '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; + } } diff --git a/spec/classes/magnum_db_mysql_spec.rb b/spec/classes/magnum_db_mysql_spec.rb index d5be1c4..0fe53a4 100644 --- a/spec/classes/magnum_db_mysql_spec.rb +++ b/spec/classes/magnum_db_mysql_spec.rb @@ -10,7 +10,7 @@ describe 'magnum::db::mysql' do end let :facts do - { :osfamily => 'Debian' } + @default_facts.merge({ :osfamily => 'Debian' }) end let :params do diff --git a/spec/classes/magnum_db_postgresql_spec.rb b/spec/classes/magnum_db_postgresql_spec.rb index f892478..d645374 100644 --- a/spec/classes/magnum_db_postgresql_spec.rb +++ b/spec/classes/magnum_db_postgresql_spec.rb @@ -12,11 +12,11 @@ describe 'magnum::db::postgresql' do context 'on a RedHat osfamily' do let :facts do - { + @default_facts.merge({ :osfamily => 'RedHat', :operatingsystemrelease => '7.0', :concat_basedir => '/var/lib/puppet/concat' - } + }) end context 'with only required parameters' do @@ -34,12 +34,12 @@ describe 'magnum::db::postgresql' do context 'on a Debian osfamily' do let :facts do - { + @default_facts.merge({ :operatingsystemrelease => '7.8', :operatingsystem => 'Debian', :osfamily => 'Debian', :concat_basedir => '/var/lib/puppet/concat' - } + }) end context 'with only required parameters' do diff --git a/spec/classes/magnum_db_spec.rb b/spec/classes/magnum_db_spec.rb index d85bd9d..be94df4 100644 --- a/spec/classes/magnum_db_spec.rb +++ b/spec/classes/magnum_db_spec.rb @@ -5,12 +5,12 @@ describe 'magnum::db' do shared_examples 'magnum::db' do context 'with default parameters' do it { is_expected.to contain_magnum_config('database/connection').with_value('mysql://magnum:secrete@localhost:3306/magnum') } - it { is_expected.to contain_magnum_config('database/idle_timeout').with_value('3600') } - it { is_expected.to contain_magnum_config('database/min_pool_size').with_value('1') } - it { is_expected.to contain_magnum_config('database/max_retries').with_value('10') } - it { is_expected.to contain_magnum_config('database/retry_interval').with_value('10') } - it { is_expected.to contain_magnum_config('database/max_pool_size').with_value('10') } - it { is_expected.to contain_magnum_config('database/max_overflow').with_value('20') } + it { is_expected.to contain_magnum_config('database/idle_timeout').with_value('') } + it { is_expected.to contain_magnum_config('database/min_pool_size').with_value('') } + it { is_expected.to contain_magnum_config('database/max_retries').with_value('') } + it { is_expected.to contain_magnum_config('database/retry_interval').with_value('') } + it { is_expected.to contain_magnum_config('database/max_pool_size').with_value('') } + it { is_expected.to contain_magnum_config('database/max_overflow').with_value('') } end context 'with specific parameters' do @@ -56,10 +56,11 @@ describe 'magnum::db' do context 'on Debian platforms' do let :facts do - { :osfamily => 'Debian', + @default_facts.merge({ + :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => 'jessie', - } + }) end it_configures 'magnum::db' @@ -67,9 +68,10 @@ describe 'magnum::db' do context 'on Redhat platforms' do let :facts do - { :osfamily => 'RedHat', + @default_facts.merge({ + :osfamily => 'RedHat', :operatingsystemrelease => '7.1', - } + }) end it_configures 'magnum::db' diff --git a/spec/classes/magnum_keystone_auth_spec.rb b/spec/classes/magnum_keystone_auth_spec.rb index 79e29e1..4fa7308 100644 --- a/spec/classes/magnum_keystone_auth_spec.rb +++ b/spec/classes/magnum_keystone_auth_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' describe 'magnum::keystone::auth' do let :facts do - { :osfamily => 'Debian' } + @default_facts.merge({ :osfamily => 'Debian' }) end describe 'with default class parameters' do diff --git a/spec/classes/magnum_logging_spec.rb b/spec/classes/magnum_logging_spec.rb index d49d9f9..d4436b1 100644 --- a/spec/classes/magnum_logging_spec.rb +++ b/spec/classes/magnum_logging_spec.rb @@ -57,12 +57,12 @@ describe 'magnum::logging' do shared_examples 'basic default logging settings' do it 'configures magnum logging settins with default values' do - is_expected.to contain_magnum_config('DEFAULT/use_syslog').with(:value => 'false') - is_expected.to contain_magnum_config('DEFAULT/use_stderr').with(:value => 'true') - is_expected.to contain_magnum_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_USER') + is_expected.to contain_magnum_config('DEFAULT/use_syslog').with(:value => '') + is_expected.to contain_magnum_config('DEFAULT/use_stderr').with(:value => '') + is_expected.to contain_magnum_config('DEFAULT/syslog_log_facility').with(:value => '') is_expected.to contain_magnum_config('DEFAULT/log_dir').with(:value => '/var/log/magnum') - is_expected.to contain_magnum_config('DEFAULT/verbose').with(:value => 'false') - is_expected.to contain_magnum_config('DEFAULT/debug').with(:value => 'false') + is_expected.to contain_magnum_config('DEFAULT/verbose').with(:value => '') + is_expected.to contain_magnum_config('DEFAULT/debug').with(:value => '') end end @@ -121,13 +121,13 @@ describe 'magnum::logging' do :default_log_levels, :fatal_deprecations, :instance_format, :instance_uuid_format, :log_date_format, ].each { |param| - it { is_expected.to contain_magnum_config("DEFAULT/#{param}").with_ensure('absent') } + it { is_expected.to contain_magnum_config("DEFAULT/#{param}").with_value('') } } end context 'on Debian platforms' do let :facts do - { :osfamily => 'Debian' } + @default_facts.merge({ :osfamily => 'Debian' }) end it_configures 'magnum-logging' @@ -135,7 +135,7 @@ describe 'magnum::logging' do context 'on RedHat platforms' do let :facts do - { :osfamily => 'RedHat' } + @default_facts.merge({ :osfamily => 'RedHat' }) end it_configures 'magnum-logging' diff --git a/spec/classes/magnum_policy_spec.rb b/spec/classes/magnum_policy_spec.rb index 5dd48d4..c854b7a 100644 --- a/spec/classes/magnum_policy_spec.rb +++ b/spec/classes/magnum_policy_spec.rb @@ -25,7 +25,7 @@ describe 'magnum::policy' do context 'on Debian platforms' do let :facts do - { :osfamily => 'Debian' } + @default_facts.merge({ :osfamily => 'Debian' }) end it_configures 'magnum policies' @@ -33,7 +33,7 @@ describe 'magnum::policy' do context 'on RedHat platforms' do let :facts do - { :osfamily => 'RedHat' } + @default_facts.merge({ :osfamily => 'RedHat' }) end it_configures 'magnum policies' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3df4ced..9bc7bcf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,9 @@ require 'webmock/rspec' RSpec.configure do |c| c.alias_it_should_behave_like_to :it_configures, 'configures' c.alias_it_should_behave_like_to :it_raises, 'raises' + c.before :each do + @default_facts = { :os_service_default => '' } + end end at_exit { RSpec::Puppet::Coverage.report! }