Introduce keystone::db class
Current modules[1][2][3] implements a <component>::db class that is not implemented in keystone. This commit aims to apply here the same logic. [1] https://github.com/openstack/puppet-nova/blob/master/manifests/db.pp [2] https://github.com/openstack/puppet-designate/blob/master/manifests/db.pp [3] https://github.com/openstack/puppet-ceilometer/blob/master/manifests/db.pp Change-Id: Ifb868c101dd516eda7b9826e0faf33c3bc296e02
This commit is contained in:
parent
6d8239183b
commit
a909129600
|
@ -0,0 +1,96 @@
|
|||
# == Class: keystone::db
|
||||
#
|
||||
# Configure the Keystone database
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# [*database_connection*]
|
||||
# Url used to connect to database.
|
||||
# (Optional) Defaults to 'sqlite:////var/lib/keystone/keystone.sqlite'.
|
||||
#
|
||||
# [*database_idle_timeout*]
|
||||
# Timeout when db connections should be reaped.
|
||||
# (Optional) Defaults to 3600.
|
||||
#
|
||||
# [*database_max_retries*]
|
||||
# Maximum number of database connection retries during startup.
|
||||
# Setting -1 implies an infinite retry count.
|
||||
# (Optional) Defaults to 10.
|
||||
#
|
||||
# [*database_retry_interval*]
|
||||
# Interval between retries of opening a database connection.
|
||||
# (Optional) Defaults to 10.
|
||||
#
|
||||
# [*database_min_pool_size*]
|
||||
# Minimum number of SQL connections to keep open in a pool.
|
||||
# (Optional) Defaults to 1.
|
||||
#
|
||||
# [*database_max_pool_size*]
|
||||
# Maximum number of SQL connections to keep open in a pool.
|
||||
# (Optional) Defaults to 10.
|
||||
#
|
||||
# [*database_max_overflow*]
|
||||
# If set, use this value for max_overflow with sqlalchemy.
|
||||
# (Optional) Defaults to 20.
|
||||
#
|
||||
class keystone::db (
|
||||
$database_connection = 'sqlite:////var/lib/keystone/keystone.sqlite',
|
||||
$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,
|
||||
) {
|
||||
|
||||
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
|
||||
# to use keystone::<myparam> if keystone::db::<myparam> isn't specified.
|
||||
$database_connection_real = pick($::keystone::database_connection, $database_connection)
|
||||
$database_idle_timeout_real = pick($::keystone::database_idle_timeout, $database_idle_timeout)
|
||||
$database_min_pool_size_real = pick($::keystone::database_min_pool_size, $database_min_pool_size)
|
||||
$database_max_pool_size_real = pick($::keystone::database_max_pool_size, $database_max_pool_size)
|
||||
$database_max_retries_real = pick($::keystone::database_max_retries, $database_max_retries)
|
||||
$database_retry_interval_real = pick($::keystone::database_retry_interval, $database_retry_interval)
|
||||
$database_max_overflow_real = pick($::keystone::database_max_overflow, $database_max_overflow)
|
||||
|
||||
validate_re($database_connection_real,
|
||||
'(sqlite|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 = $::keystone::params::psycopg_package_name
|
||||
}
|
||||
/^sqlite:\/\//: {
|
||||
$backend_package = $::keystone::params::sqlite_package_name
|
||||
}
|
||||
default: {
|
||||
fail('Unsupported backend configured')
|
||||
}
|
||||
}
|
||||
|
||||
if $backend_package and !defined(Package[$backend_package]) {
|
||||
package {'keystone-backend-package':
|
||||
ensure => present,
|
||||
name => $backend_package,
|
||||
tag => 'openstack',
|
||||
}
|
||||
}
|
||||
|
||||
keystone_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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -119,11 +119,32 @@
|
|||
#
|
||||
# [*database_connection*]
|
||||
# (optional) Url used to connect to database.
|
||||
# Defaults to sqlite:////var/lib/keystone/keystone.db
|
||||
# Defaults to undef.
|
||||
#
|
||||
# [*database_idle_timeout*]
|
||||
# (optional) Timeout when db connections should be reaped.
|
||||
# Defaults to 200.
|
||||
# Defaults to undef.
|
||||
#
|
||||
# [*database_max_retries*]
|
||||
# (optional) Maximum number of database connection retries during startup.
|
||||
# Setting -1 implies an infinite retry count.
|
||||
# (Defaults to undef)
|
||||
#
|
||||
# [*database_retry_interval*]
|
||||
# (optional) Interval between retries of opening a database connection.
|
||||
# (Defaults to undef)
|
||||
#
|
||||
# [*database_min_pool_size*]
|
||||
# (optional) Minimum number of SQL connections to keep open in a pool.
|
||||
# Defaults to: undef
|
||||
#
|
||||
# [*database_max_pool_size*]
|
||||
# (optional) Maximum number of SQL connections to keep open in a pool.
|
||||
# Defaults to: undef
|
||||
#
|
||||
# [*database_max_overflow*]
|
||||
# (optional) If set, use this value for max_overflow with sqlalchemy.
|
||||
# Defaults to: undef
|
||||
#
|
||||
# [*enable_pki_setup*]
|
||||
# (optional) Enable call to pki_setup to generate the cert for signing pki tokens and
|
||||
|
@ -461,8 +482,13 @@ class keystone(
|
|||
$debug_cache_backend = false,
|
||||
$token_caching = true,
|
||||
$enabled = true,
|
||||
$database_connection = 'sqlite:////var/lib/keystone/keystone.db',
|
||||
$database_idle_timeout = '200',
|
||||
$database_connection = undef,
|
||||
$database_idle_timeout = undef,
|
||||
$database_max_retries = undef,
|
||||
$database_retry_interval = undef,
|
||||
$database_min_pool_size = undef,
|
||||
$database_max_pool_size = undef,
|
||||
$database_max_overflow = undef,
|
||||
$enable_pki_setup = true,
|
||||
$signing_certfile = '/etc/keystone/ssl/certs/signing_cert.pem',
|
||||
$signing_keyfile = '/etc/keystone/ssl/private/signing_key.pem',
|
||||
|
@ -540,6 +566,7 @@ class keystone(
|
|||
Keystone_config<||> ~> Exec<| title == 'keystone-manage pki_setup'|>
|
||||
Keystone_config<||> ~> Exec<| title == 'keystone-manage fernet_setup'|>
|
||||
|
||||
include ::keystone::db
|
||||
include ::keystone::params
|
||||
|
||||
package { 'keystone':
|
||||
|
@ -667,17 +694,6 @@ class keystone(
|
|||
}
|
||||
}
|
||||
|
||||
if($database_connection =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
|
||||
require 'mysql::bindings'
|
||||
require 'mysql::bindings::python'
|
||||
} elsif($database_connection =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
|
||||
|
||||
} elsif($database_connection =~ /sqlite:\/\//) {
|
||||
|
||||
} else {
|
||||
fail("Invalid db connection ${database_connection}")
|
||||
}
|
||||
|
||||
# memcache connection config
|
||||
if $memcache_servers {
|
||||
validate_array($memcache_servers)
|
||||
|
@ -710,12 +726,6 @@ class keystone(
|
|||
}
|
||||
}
|
||||
|
||||
# db connection config
|
||||
keystone_config {
|
||||
'database/connection': value => $database_connection, secret => true;
|
||||
'database/idle_timeout': value => $database_idle_timeout;
|
||||
}
|
||||
|
||||
# configure based on the catalog backend
|
||||
if $catalog_driver {
|
||||
$catalog_driver_real = $catalog_driver
|
||||
|
|
|
@ -11,6 +11,8 @@ class keystone::params {
|
|||
$keystone_wsgi_script_path = '/usr/lib/cgi-bin/keystone'
|
||||
$keystone_wsgi_script_source = '/usr/share/keystone/wsgi.py'
|
||||
$python_memcache_package_name = 'python-memcache'
|
||||
$psycopg_package_name = 'python-psycopg2'
|
||||
$sqlite_package_name = 'python-pysqlite2'
|
||||
$paste_config = undef
|
||||
case $::operatingsystem {
|
||||
'Debian': {
|
||||
|
@ -26,6 +28,8 @@ class keystone::params {
|
|||
$service_name = 'openstack-keystone'
|
||||
$keystone_wsgi_script_path = '/var/www/cgi-bin/keystone'
|
||||
$python_memcache_package_name = 'python-memcached'
|
||||
$psycopg_package_name = 'python-psycopg2'
|
||||
$sqlite_package_name = undef
|
||||
$service_provider = undef
|
||||
$keystone_wsgi_script_source = '/usr/share/keystone/keystone.wsgi'
|
||||
$paste_config = '/usr/share/keystone/keystone-dist-paste.ini'
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'keystone::db' do
|
||||
|
||||
shared_examples 'keystone::db' do
|
||||
|
||||
context 'with default parameters' do
|
||||
|
||||
it { is_expected.to contain_keystone_config('database/connection').with_value('sqlite:////var/lib/keystone/keystone.sqlite').with_secret(true) }
|
||||
it { is_expected.to contain_keystone_config('database/idle_timeout').with_value('3600') }
|
||||
it { is_expected.to contain_keystone_config('database/min_pool_size').with_value('1') }
|
||||
it { is_expected.to contain_keystone_config('database/max_pool_size').with_value('10') }
|
||||
it { is_expected.to contain_keystone_config('database/max_overflow').with_value('20') }
|
||||
it { is_expected.to contain_keystone_config('database/max_retries').with_value('10') }
|
||||
it { is_expected.to contain_keystone_config('database/retry_interval').with_value('10') }
|
||||
|
||||
end
|
||||
|
||||
context 'with specific parameters' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://keystone:keystone@localhost/keystone',
|
||||
:database_idle_timeout => '3601',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_pool_size => '21',
|
||||
:database_max_retries => '11',
|
||||
:database_max_overflow => '21',
|
||||
:database_retry_interval => '11', }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_keystone_config('database/connection').with_value('mysql://keystone:keystone@localhost/keystone').with_secret(true) }
|
||||
it { is_expected.to contain_keystone_config('database/idle_timeout').with_value('3601') }
|
||||
it { is_expected.to contain_keystone_config('database/min_pool_size').with_value('2') }
|
||||
it { is_expected.to contain_keystone_config('database/max_retries').with_value('11') }
|
||||
it { is_expected.to contain_keystone_config('database/max_pool_size').with_value('21') }
|
||||
it { is_expected.to contain_keystone_config('database/max_overflow').with_value('21') }
|
||||
it { is_expected.to contain_keystone_config('database/retry_interval').with_value('11') }
|
||||
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'redis://keystone:keystone@localhost/keystone', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
it_configures 'keystone::db'
|
||||
end
|
||||
|
||||
context 'on Redhat platforms' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
it_configures 'keystone::db'
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue