Use oslo module for logging and database configuration

Additonal changes:

  * switch database related parameters to $::os_service_default
    as they are used in oslo::db
  * update unit tests

Change-Id: I2c79261d8000d68521f783b5df9a535ff47ce53d
This commit is contained in:
Alexey Deryugin 2016-04-20 11:57:37 +03:00 committed by Emilien Macchi
parent 24839ec63f
commit b0804e5f8a
4 changed files with 42 additions and 86 deletions

View File

@ -35,16 +35,15 @@
# #
class trove::db ( class trove::db (
$database_connection = 'sqlite:////var/lib/trove/trove.sqlite', $database_connection = 'sqlite:////var/lib/trove/trove.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 ::trove::deps include ::trove::deps
include ::trove::params
# 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 trove::<myparam> if trove::db::<myparam> isn't specified. # to use trove::<myparam> if trove::db::<myparam> isn't specified.
@ -59,46 +58,13 @@ class trove::db (
validate_re($database_connection_real, validate_re($database_connection_real,
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
if $database_connection_real { oslo::db { 'trove_config':
case $database_connection_real { connection => $database_connection_real,
/^mysql(\+pymysql)?:\/\//: { idle_timeout => $database_idle_timeout_real,
require 'mysql::bindings' min_pool_size => $database_min_pool_size_real,
require 'mysql::bindings::python' max_pool_size => $database_max_pool_size_real,
if $database_connection_real =~ /^mysql\+pymysql/ { max_retries => $database_max_retries_real,
$backend_package = $::trove::params::pymysql_package_name retry_interval => $database_retry_interval_real,
} else { max_overflow => $database_max_overflow_real
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false
require 'postgresql::lib::python'
}
/^sqlite:\/\//: {
$backend_package = $::trove::params::sqlite_package_name
}
default: {
fail('Unsupported backend configured')
}
}
if $backend_package and !defined(Package[$backend_package]) {
package {'trove-backend-package':
ensure => present,
name => $backend_package,
tag => ['openstack', 'trove-package'],
}
}
trove_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

@ -127,30 +127,24 @@ class trove::logging(
$verbose_real = pick($::trove::api::verbose, $verbose) $verbose_real = pick($::trove::api::verbose, $verbose)
$debug_real = pick($::trove::api::debug, $debug) $debug_real = pick($::trove::api::debug, $debug)
if is_service_default($default_log_levels) { oslo::log { 'trove_config':
$default_log_levels_real = $default_log_levels debug => $debug_real,
} else { verbose => $verbose_real,
$default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',') use_stderr => $use_stderr_real,
} use_syslog => $use_syslog_real,
log_dir => $log_dir_real,
trove_config { log_file => $log_file_real,
'DEFAULT/debug' : value => $debug_real; syslog_log_facility => $log_facility_real,
'DEFAULT/verbose' : value => $verbose_real; logging_context_format_string => $logging_context_format_string,
'DEFAULT/use_stderr' : value => $use_stderr_real; logging_default_format_string => $logging_default_format_string,
'DEFAULT/use_syslog' : value => $use_syslog_real; logging_debug_format_suffix => $logging_debug_format_suffix,
'DEFAULT/log_dir' : value => $log_dir_real; logging_exception_prefix => $logging_exception_prefix,
'DEFAULT/log_file' : value => $log_file_real; log_config_append => $log_config_append,
'DEFAULT/syslog_log_facility' : value => $log_facility_real; default_log_levels => $default_log_levels,
'DEFAULT/logging_context_format_string' : value => $logging_context_format_string; publish_errors => $publish_errors,
'DEFAULT/logging_default_format_string' : value => $logging_default_format_string; fatal_deprecations => $fatal_deprecations,
'DEFAULT/logging_debug_format_suffix' : value => $logging_debug_format_suffix; instance_format => $instance_format,
'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix; instance_uuid_format => $instance_uuid_format,
'DEFAULT/log_config_append' : value => $log_config_append; log_date_format => $log_date_format
'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

@ -14,8 +14,6 @@ class trove::params {
$guestagent_service_name = 'openstack-trove-guestagent' $guestagent_service_name = 'openstack-trove-guestagent'
$taskmanager_package_name = 'openstack-trove-taskmanager' $taskmanager_package_name = 'openstack-trove-taskmanager'
$taskmanager_service_name = 'openstack-trove-taskmanager' $taskmanager_service_name = 'openstack-trove-taskmanager'
$sqlite_package_name = undef
$pymysql_package_name = undef
} }
'Debian': { 'Debian': {
$client_package_name = 'python-troveclient' $client_package_name = 'python-troveclient'
@ -28,8 +26,6 @@ class trove::params {
$guestagent_service_name = 'trove-guestagent' $guestagent_service_name = 'trove-guestagent'
$taskmanager_package_name = 'trove-taskmanager' $taskmanager_package_name = 'trove-taskmanager'
$taskmanager_service_name = 'trove-taskmanager' $taskmanager_service_name = 'trove-taskmanager'
$sqlite_package_name = 'python-pysqlite2'
$pymysql_package_name = 'python-pymysql'
} }
default: { default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem") fail("Unsupported osfamily: ${::osfamily} operatingsystem")

View File

@ -7,12 +7,12 @@ describe 'trove::db' do
context 'with default parameters' do context 'with default parameters' do
it { is_expected.to contain_trove_config('database/connection').with_value('sqlite:////var/lib/trove/trove.sqlite').with_secret(true) } it { is_expected.to contain_trove_config('database/connection').with_value('sqlite:////var/lib/trove/trove.sqlite').with_secret(true) }
it { is_expected.to contain_trove_config('database/idle_timeout').with_value('3600') } it { is_expected.to contain_trove_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_trove_config('database/min_pool_size').with_value('1') } it { is_expected.to contain_trove_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_trove_config('database/max_pool_size').with_value('10') } it { is_expected.to contain_trove_config('database/max_pool_size').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_trove_config('database/max_overflow').with_value('20') } it { is_expected.to contain_trove_config('database/max_overflow').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_trove_config('database/max_retries').with_value('10') } it { is_expected.to contain_trove_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_trove_config('database/retry_interval').with_value('10') } it { is_expected.to contain_trove_config('database/retry_interval').with_value('<SERVICE DEFAULT>') }
end end
@ -90,10 +90,10 @@ describe 'trove::db' do
end end
it 'install the proper backend package' do it 'install the proper backend package' do
is_expected.to contain_package('trove-backend-package').with( is_expected.to contain_package('db_backend_package').with(
:ensure => 'present', :ensure => 'present',
:name => 'python-pymysql', :name => 'python-pymysql',
:tag => ['openstack', 'trove-package'], :tag => 'openstack',
) )
end end
end end
@ -114,7 +114,7 @@ describe 'trove::db' do
{ :database_connection => 'mysql+pymysql://trove:trove@localhost/trove', } { :database_connection => 'mysql+pymysql://trove:trove@localhost/trove', }
end end
it { is_expected.not_to contain_package('trove-backend-package') } it { is_expected.not_to contain_package('db_backend_package') }
end end
end end