Add support for db_max_retries param

The db_max_retries parameter regulates the number of reconnection
attempts performed after an error raised rather than at startup.

Change-Id: I62a8ae71d3f041020596f844ea93e06136e31448
Closes-Bug: 1579718
This commit is contained in:
nanhai.liao 2016-05-12 08:12:00 +08:00
parent cca9f888bf
commit 29b678861f
3 changed files with 26 additions and 43 deletions

View File

@ -33,6 +33,11 @@
# If set, use this value for max_overflow with sqlalchemy.
# (Optional) Defaults to $::os_service_default
#
# [*database_db_max_retries*]
# (optional) Maximum retries in case of connection error or deadlock error
# before error is raised. Set to -1 to specify an infinite retry count.
# Defaults to $::os_service_default
#
class manila::db (
$database_connection = 'sqlite:////var/lib/manila/manila.sqlite',
$database_idle_timeout = $::os_service_default,
@ -41,10 +46,9 @@ class manila::db (
$database_max_retries = $::os_service_default,
$database_retry_interval = $::os_service_default,
$database_max_overflow = $::os_service_default,
$database_db_max_retries = $::os_service_default,
) {
include ::manila::params
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use manila::<myparam> if manila::db::<myparam> isn't specified.
$database_connection_real = pick($::manila::sql_connection, $database_connection)
@ -58,44 +62,14 @@ class manila::db (
validate_re($database_connection_real,
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
case $database_connection_real {
/^mysql(\+pymysql)?:\/\//: {
require 'mysql::bindings'
require 'mysql::bindings::python'
if $database_connection_real =~ /^mysql\+pymysql/ {
$backend_package = $::manila::params::pymysql_package_name
} else {
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false
require 'postgresql::lib::python'
}
/^sqlite:\/\//: {
$backend_package = $::manila::params::sqlite_package_name
}
default: {
fail('Unsupported backend configured')
}
oslo::db { 'manila_config':
connection => $database_connection_real,
idle_timeout => $database_idle_timeout_real,
min_pool_size => $database_min_pool_size_real,
max_pool_size => $database_max_pool_size_real,
max_retries => $database_max_retries_real,
retry_interval => $database_retry_interval_real,
max_overflow => $database_max_overflow_real,
db_max_retries => $database_db_max_retries,
}
if $backend_package and !defined(Package[$backend_package]) {
package {'manila-backend-package':
ensure => present,
name => $backend_package,
tag => 'openstack',
}
}
manila_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

@ -0,0 +1,6 @@
---
features:
- Add support for db_max_retries param
The db_max_retries parameter regulates
the number of reconnection attempts performed
after an error raised rather than at startup.

View File

@ -13,6 +13,7 @@ describe 'manila::db' do
it { is_expected.to contain_manila_config('database/max_overflow').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_manila_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_manila_config('database/retry_interval').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_manila_config('database/db_max_retries').with_value('<SERVICE DEFAULT>') }
end
@ -24,7 +25,8 @@ describe 'manila::db' do
:database_max_pool_size => '21',
:database_max_retries => '11',
:database_max_overflow => '21',
:database_retry_interval => '11', }
:database_retry_interval => '11',
:database_db_max_retries => '-1', }
end
it { is_expected.to contain_manila_config('database/connection').with_value('mysql+pymysql://manila:manila@localhost/manila').with_secret(true) }
@ -34,6 +36,7 @@ describe 'manila::db' do
it { is_expected.to contain_manila_config('database/max_pool_size').with_value('21') }
it { is_expected.to contain_manila_config('database/max_overflow').with_value('21') }
it { is_expected.to contain_manila_config('database/retry_interval').with_value('11') }
it { is_expected.to contain_manila_config('database/db_max_retries').with_value('-1') }
end
@ -89,7 +92,7 @@ describe 'manila::db' do
{ :database_connection => 'mysql+pymysql://manila:manila@localhost/manila' }
end
it { is_expected.to contain_package('manila-backend-package').with({ :ensure => 'present', :name => 'python-pymysql' }) }
it { is_expected.to contain_package('db_backend_package').with({ :ensure => 'present', :name => 'python-pymysql', :tag=> 'openstack' }) }
end
end