Use oslo::db to placement::db class

This patch changes so the placement::db class uses the
oslo::db and adds the parameters that placement supports
based on [1].

Patch utilizes the fix in [2] to puppet-oslo that allows
setting different config groups for database configuration
that we need because placement uses the placement_database
section [3].

[1] https://github.com/openstack/placement/blob/master/placement/conf/database.py#L58
[2] https://review.openstack.org/#/c/631772/
[3] https://github.com/openstack/placement/blob/master/placement/conf/database.py#L50

Depends-On: https://review.openstack.org/#/c/631772/
Change-Id: I6b408245c8f6139e3d01ab25dfe749724e2c53f5
This commit is contained in:
Tobias Urdin 2019-01-18 11:48:27 +01:00
parent 3f268c5cb3
commit 6e8f986362
3 changed files with 130 additions and 49 deletions

View File

@ -4,12 +4,63 @@
#
# === Parameters
#
# [*database_sqlite_synchronous*]
# (Optional) If True, SQLite uses synchronous mode.
# Defaults to $::os_service_default
#
# [*database_connection*]
# (Optional) Url used to connect to database.
# Defaults to 'sqlite:////var/lib/placement/placement.sqlite'.
# Defaults to 'sqlite:////var/lib/placement/placement.sqlite'
#
# [*database_slave_connection*]
# (Optional) Connection url to connect to placement slave database (read-only).
# Defaults to $::os_service_default
#
# [*database_mysql_sql_mode*]
# (Optional) The SQL mode to be used for MySQL sessions.
# Defaults to $::os_service_default
#
# [*database_max_pool_size*]
# (Optional) Maximum number of SQL connections to keep open in a pool.
# Defaults to $::os_service_default
#
# [*database_max_retries*]
# (Optional) Maximum db connection retries during startup.
# Setting -1 implies an infinite retry count.
# Defaults to $::os_service_default
#
# [*database_retry_interval*]
# (Optional) Interval between retries of opening a sql connection.
# Defaults to $::os_service_default
#
# [*database_max_overflow*]
# (Optional) If set, use this value for max_overflow with sqlalchemy.
# Defaults to $::os_service_default
#
# [*database_connection_debug*]
# (Optional) Verbosity of SQL debugging information: 0=None, 100=Everything.
# Defaults to $::os_service_default
#
# [*database_connection_trace*]
# (Optional) Boolean if we should add Python stack traces to SQL as comment strings.
# Defaults to $::os_service_default
#
# [*database_pool_timeout*]
# (Optional) If set, use this value for pool_timeout with SQLAlchemy.
# Defaults to $::os_service_default
#
class placement::db (
$database_connection = 'sqlite:////var/lib/placement/placement.sqlite',
$database_sqlite_synchronous = $::os_service_default,
$database_connection = 'sqlite:////var/lib/placement/placement.sqlite',
$database_slave_connection = $::os_service_default,
$database_mysql_sql_mode = $::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_debug = $::os_service_default,
$database_connection_trace = $::os_service_default,
$database_pool_timeout = $::os_service_default,
) {
include ::placement::deps
@ -18,8 +69,18 @@ class placement::db (
validate_re($database_connection,
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
placement_config {
'placement_database/connection': value => $database_connection;
oslo::db { 'placement_config':
config_group => 'placement_database',
sqlite_synchronous => $database_sqlite_synchronous,
connection => $database_connection,
slave_connection => $database_slave_connection,
mysql_sql_mode => $database_mysql_sql_mode,
max_pool_size => $database_max_pool_size,
max_retries => $database_max_retries,
retry_interval => $database_retry_interval,
max_overflow => $database_max_overflow,
connection_debug => $database_connection_debug,
connection_trace => $database_connection_trace,
pool_timeout => $database_pool_timeout,
}
}

View File

@ -0,0 +1,16 @@
---
features:
- |
Added the following parameters to placement::db, it now also uses the
oslo::db resource to create the databaes configuration:
- ``database_sqlite_synchronous``
- ``database_slave_connection``
- ``database_mysql_sql_mode``
- ``database_max_pool_size``
- ``database_max_retries``
- ``database_retry_interval``
- ``database_max_overflow``
- ``database_connection_debug``
- ``database_connection_trace``
- ``database_pool_timeout``

View File

@ -3,58 +3,63 @@ require 'spec_helper'
describe 'placement::db' do
shared_examples 'placement::db' do
context 'with default parameters' do
it { should contain_placement_config('placement_database/connection').with_value('sqlite:////var/lib/placement/placement.sqlite') }
it {
should contain_class('placement::deps')
should contain_class('placement::config')
}
it { should contain_oslo__db('placement_config').with(
:config_group => 'placement_database',
:sqlite_synchronous => '<SERVICE DEFAULT>',
:connection => 'sqlite:////var/lib/placement/placement.sqlite',
:slave_connection => '<SERVICE DEFAULT>',
:mysql_sql_mode => '<SERVICE DEFAULT>',
:max_pool_size => '<SERVICE DEFAULT>',
:max_retries => '<SERVICE DEFAULT>',
:retry_interval => '<SERVICE DEFAULT>',
:max_overflow => '<SERVICE DEFAULT>',
:connection_debug => '<SERVICE DEFAULT>',
:connection_trace => '<SERVICE DEFAULT>',
:pool_timeout => '<SERVICE DEFAULT>',
)}
end
context 'with specific parameters' do
let :params do
{
:database_connection => 'mysql+pymysql://placement:placement@localhost/placement',
:database_sqlite_synchronous => true,
:database_connection => 'mysql+pymysql://placement:placement@localhost/placement',
:database_slave_connection => 'mysql+pymysql://placement2:placement2@localhost/placement2',
:database_mysql_sql_mode => 'strict_mode',
:database_max_pool_size => '8',
:database_max_retries => '4',
:database_retry_interval => '-1',
:database_max_overflow => '2',
:database_connection_debug => '100',
:database_connection_trace => true,
:database_pool_timeout => '10',
}
end
it { should contain_placement_config('placement_database/connection').with_value('mysql+pymysql://placement:placement@localhost/placement') }
end
it {
should contain_class('placement::deps')
should contain_class('placement::config')
}
context 'with incorrect database_connection string' do
let :params do
{
:database_connection => 'foodb://placement:placement@localhost/placement',
}
end
it { should raise_error(Puppet::Error, /validate_re/) }
end
context 'with incorrect pymysql database_connection string' do
let :params do
{
:database_connection => 'foo+pymysql://placement:placement@localhost/placement',
}
end
it { should raise_error(Puppet::Error, /validate_re/) }
end
end
shared_examples 'placement::db on Debian' do
context 'using pymysql driver' do
let :params do
{
:database_connection => 'mysql+pymysql://placement:placement@localhost/placement',
}
end
end
end
shared_examples_for 'placement::db on RedHat' do
context 'using pymysql driver' do
let :params do
{
:database_connection => 'mysql+pymysql://placement:placement@localhost/placement',
}
end
it { should contain_oslo__db('placement_config').with(
:config_group => 'placement_database',
:sqlite_synchronous => true,
:connection => 'mysql+pymysql://placement:placement@localhost/placement',
:slave_connection => 'mysql+pymysql://placement2:placement2@localhost/placement2',
:mysql_sql_mode => 'strict_mode',
:max_pool_size => '8',
:max_retries => '4',
:retry_interval => '-1',
:max_overflow => '2',
:connection_debug => '100',
:connection_trace => true,
:pool_timeout => '10',
)}
end
end
@ -67,7 +72,6 @@ describe 'placement::db' do
end
it_behaves_like 'placement::db'
it_behaves_like "placement::db on #{facts[:osfamily]}"
end
end
end