Introduce heat::db class
Current modules[1][2][3] implements a <component>::db class that is not implemented in heat. 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: I922260265d110d5823c546813ee125400ecc183d
This commit is contained in:
parent
06953c3d44
commit
fb4486166a
107
manifests/db.pp
Normal file
107
manifests/db.pp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
# == Class: heat::db
|
||||||
|
#
|
||||||
|
# Configure the Heat database
|
||||||
|
#
|
||||||
|
# === Parameters
|
||||||
|
#
|
||||||
|
# [*database_connection*]
|
||||||
|
# Url used to connect to database.
|
||||||
|
# (Optional) Defaults to 'sqlite:////var/lib/heat/heat.sqlite'.
|
||||||
|
#
|
||||||
|
# [*database_idle_timeout*]
|
||||||
|
# Timeout when db connections should be reaped.
|
||||||
|
# (Optional) Defaults to 3600.
|
||||||
|
#
|
||||||
|
# [*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_retries*]
|
||||||
|
# Maximum db connection retries during startup.
|
||||||
|
# Setting -1 implies an infinite retry count.
|
||||||
|
# (Optional) Defaults to 10.
|
||||||
|
#
|
||||||
|
# [*database_retry_interval*]
|
||||||
|
# Interval between retries of opening a sql connection.
|
||||||
|
# (Optional) Defaults to 10.
|
||||||
|
#
|
||||||
|
# [*database_max_overflow*]
|
||||||
|
# If set, use this value for max_overflow with sqlalchemy.
|
||||||
|
# (Optional) Defaults to 20.
|
||||||
|
#
|
||||||
|
# [*sync_db*]
|
||||||
|
# (Optional) Run db sync on nodes after connection setting has been set.
|
||||||
|
# Defaults to true
|
||||||
|
#
|
||||||
|
class heat::db (
|
||||||
|
$database_connection = 'sqlite:////var/lib/heat/heat.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,
|
||||||
|
$sync_db = true,
|
||||||
|
) {
|
||||||
|
|
||||||
|
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
|
||||||
|
# to use heat::<myparam> if heat::db::<myparam> isn't specified.
|
||||||
|
$database_connection_real = pick($::heat::database_connection, $database_connection)
|
||||||
|
$database_idle_timeout_real = pick($::heat::database_idle_timeout, $database_idle_timeout)
|
||||||
|
$database_min_pool_size_real = pick($::heat::database_min_pool_size, $database_min_pool_size)
|
||||||
|
$database_max_pool_size_real = pick($::heat::database_max_pool_size, $database_max_pool_size)
|
||||||
|
$database_max_retries_real = pick($::heat::database_max_retries, $database_max_retries)
|
||||||
|
$database_retry_interval_real = pick($::heat::database_retry_interval, $database_retry_interval)
|
||||||
|
$database_max_overflow_real = pick($::heat::database_max_overflow, $database_max_overflow)
|
||||||
|
$sync_db_real = pick($::heat::sync_db, $sync_db)
|
||||||
|
|
||||||
|
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 = $::heat::params::psycopg_package_name
|
||||||
|
}
|
||||||
|
/^sqlite:\/\//: {
|
||||||
|
$backend_package = $::heat::params::sqlite_package_name
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
fail('Unsupported backend configured')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if $backend_package and !defined(Package[$backend_package]) {
|
||||||
|
package {'heat-backend-package':
|
||||||
|
ensure => present,
|
||||||
|
name => $backend_package,
|
||||||
|
tag => 'openstack',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
heat_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if $sync_db_real {
|
||||||
|
include ::heat::db::sync
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -144,13 +144,33 @@
|
|||||||
# [*qpid_reconnect_interval_max*]
|
# [*qpid_reconnect_interval_max*]
|
||||||
#
|
#
|
||||||
# [*database_connection*]
|
# [*database_connection*]
|
||||||
# (Optional) Url used to connect to database.
|
# (optional) Connection url for the heat database.
|
||||||
# Defaults to 'sqlite:////var/lib/heat/heat.sqlite'.
|
# Defaults to undef.
|
||||||
|
#
|
||||||
|
# [*database_max_retries*]
|
||||||
|
# (optional) Maximum database connection retries during startup.
|
||||||
|
# Defaults to undef.
|
||||||
#
|
#
|
||||||
# [*database_idle_timeout*]
|
# [*database_idle_timeout*]
|
||||||
# (Optional) Timeout before idle db connections are reaped.
|
# (optional) Timeout before idle database connections are reaped.
|
||||||
# Defaults to 3600.
|
# 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.
|
||||||
|
|
||||||
# [*use_syslog*]
|
# [*use_syslog*]
|
||||||
# (Optional) Use syslog for logging.
|
# (Optional) Use syslog for logging.
|
||||||
# Defaults to undef.
|
# Defaults to undef.
|
||||||
@ -253,16 +273,21 @@ class heat(
|
|||||||
$qpid_reconnect_interval_min = 0,
|
$qpid_reconnect_interval_min = 0,
|
||||||
$qpid_reconnect_interval_max = 0,
|
$qpid_reconnect_interval_max = 0,
|
||||||
$qpid_reconnect_interval = 0,
|
$qpid_reconnect_interval = 0,
|
||||||
$database_connection = 'sqlite:////var/lib/heat/heat.sqlite',
|
|
||||||
$database_idle_timeout = 3600,
|
|
||||||
$use_syslog = undef,
|
$use_syslog = undef,
|
||||||
$use_stderr = undef,
|
$use_stderr = undef,
|
||||||
$log_facility = undef,
|
$log_facility = undef,
|
||||||
|
$database_connection = undef,
|
||||||
|
$database_max_retries = undef,
|
||||||
|
$database_idle_timeout = undef,
|
||||||
|
$database_retry_interval = undef,
|
||||||
|
$database_min_pool_size = undef,
|
||||||
|
$database_max_pool_size = undef,
|
||||||
|
$database_max_overflow = undef,
|
||||||
$flavor = undef,
|
$flavor = undef,
|
||||||
$region_name = undef,
|
$region_name = undef,
|
||||||
$enable_stack_adopt = undef,
|
$enable_stack_adopt = undef,
|
||||||
$enable_stack_abandon = undef,
|
$enable_stack_abandon = undef,
|
||||||
$sync_db = true,
|
$sync_db = undef,
|
||||||
# Deprecated parameters
|
# Deprecated parameters
|
||||||
$mysql_module = undef,
|
$mysql_module = undef,
|
||||||
$sql_connection = undef,
|
$sql_connection = undef,
|
||||||
@ -273,6 +298,7 @@ class heat(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
include ::heat::logging
|
include ::heat::logging
|
||||||
|
include ::heat::db
|
||||||
include ::heat::params
|
include ::heat::params
|
||||||
|
|
||||||
if $kombu_ssl_ca_certs and !$rabbit_use_ssl {
|
if $kombu_ssl_ca_certs and !$rabbit_use_ssl {
|
||||||
@ -484,55 +510,6 @@ class heat(
|
|||||||
'keystone_authtoken/admin_password' : value => $keystone_password, secret => true;
|
'keystone_authtoken/admin_password' : value => $keystone_password, secret => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if $sql_connection {
|
|
||||||
warning('The sql_connection parameter is deprecated, use database_connection instead.')
|
|
||||||
$database_connection_real = $sql_connection
|
|
||||||
} else {
|
|
||||||
$database_connection_real = $database_connection
|
|
||||||
}
|
|
||||||
|
|
||||||
if $database_connection_real {
|
|
||||||
validate_re($database_connection_real,
|
|
||||||
'(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
|
||||||
|
|
||||||
case $database_connection_real {
|
|
||||||
/^mysql:\/\//: {
|
|
||||||
$backend_package = false
|
|
||||||
require mysql::bindings
|
|
||||||
require mysql::bindings::python
|
|
||||||
}
|
|
||||||
/^postgresql:\/\//: {
|
|
||||||
$backend_package = 'python-psycopg2'
|
|
||||||
}
|
|
||||||
/^sqlite:\/\//: {
|
|
||||||
$backend_package = 'python-pysqlite2'
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
fail('Unsupported backend configured')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if $backend_package and !defined(Package[$backend_package]) {
|
|
||||||
package {'heat-backend-package':
|
|
||||||
ensure => present,
|
|
||||||
name => $backend_package,
|
|
||||||
tag => 'openstack',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
heat_config {
|
|
||||||
'database/connection':
|
|
||||||
value => $database_connection_real,
|
|
||||||
secret => true;
|
|
||||||
'database/idle_timeout':
|
|
||||||
value => $database_idle_timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
if $sync_db {
|
|
||||||
include ::heat::db::sync
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if $flavor {
|
if $flavor {
|
||||||
heat_config { 'paste_deploy/flavor': value => $flavor; }
|
heat_config { 'paste_deploy/flavor': value => $flavor; }
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,6 +16,8 @@ class heat::params {
|
|||||||
$engine_package_name = 'openstack-heat-engine'
|
$engine_package_name = 'openstack-heat-engine'
|
||||||
$client_package_name = 'python-heatclient'
|
$client_package_name = 'python-heatclient'
|
||||||
$common_package_name = 'openstack-heat-common'
|
$common_package_name = 'openstack-heat-common'
|
||||||
|
$psycopg_package_name = 'python-psycopg2'
|
||||||
|
$sqlite_package_name = undef
|
||||||
# service names
|
# service names
|
||||||
$api_service_name = 'openstack-heat-api'
|
$api_service_name = 'openstack-heat-api'
|
||||||
$api_cloudwatch_service_name = 'openstack-heat-api-cloudwatch'
|
$api_cloudwatch_service_name = 'openstack-heat-api-cloudwatch'
|
||||||
@ -30,6 +32,8 @@ class heat::params {
|
|||||||
$engine_package_name = 'heat-engine'
|
$engine_package_name = 'heat-engine'
|
||||||
$client_package_name = 'python-heatclient'
|
$client_package_name = 'python-heatclient'
|
||||||
$common_package_name = 'heat-common'
|
$common_package_name = 'heat-common'
|
||||||
|
$psycopg_package_name = 'python-psycopg2'
|
||||||
|
$sqlite_package_name = 'python-pysqlite2'
|
||||||
# service names
|
# service names
|
||||||
$api_service_name = 'heat-api'
|
$api_service_name = 'heat-api'
|
||||||
$api_cloudwatch_service_name = 'heat-api-cloudwatch'
|
$api_cloudwatch_service_name = 'heat-api-cloudwatch'
|
||||||
|
63
spec/classes/heat_db_spec.rb
Normal file
63
spec/classes/heat_db_spec.rb
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'heat::db' do
|
||||||
|
|
||||||
|
shared_examples 'heat::db' do
|
||||||
|
|
||||||
|
context 'with default parameters' do
|
||||||
|
|
||||||
|
it { is_expected.to contain_class('heat::db::sync') }
|
||||||
|
it { is_expected.to contain_heat_config('database/connection').with_value('sqlite:////var/lib/heat/heat.sqlite').with_secret(true) }
|
||||||
|
it { is_expected.to contain_heat_config('database/idle_timeout').with_value('3600') }
|
||||||
|
it { is_expected.to contain_heat_config('database/min_pool_size').with_value('1') }
|
||||||
|
it { is_expected.to contain_heat_config('database/max_retries').with_value('10') }
|
||||||
|
it { is_expected.to contain_heat_config('database/retry_interval').with_value('10') }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with specific parameters' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'mysql://heat:heat@localhost/heat',
|
||||||
|
:database_idle_timeout => '3601',
|
||||||
|
:database_min_pool_size => '2',
|
||||||
|
:database_max_retries => '11',
|
||||||
|
:database_retry_interval => '11',
|
||||||
|
:sync_db => false }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.not_to contain_class('heat::db::sync') }
|
||||||
|
it { is_expected.to contain_heat_config('database/connection').with_value('mysql://heat:heat@localhost/heat').with_secret(true) }
|
||||||
|
it { is_expected.to contain_heat_config('database/idle_timeout').with_value('3601') }
|
||||||
|
it { is_expected.to contain_heat_config('database/min_pool_size').with_value('2') }
|
||||||
|
it { is_expected.to contain_heat_config('database/max_retries').with_value('11') }
|
||||||
|
it { is_expected.to contain_heat_config('database/retry_interval').with_value('11') }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with incorrect database_connection string' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'redis://heat:heat@localhost/heat', }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_raises 'a Puppet::Error', /validate_re/
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Debian platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'Debian' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'heat::db'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Redhat platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'RedHat' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'heat::db'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -137,24 +137,6 @@ describe 'heat' do
|
|||||||
is_expected.to contain_heat_config('keystone_authtoken/auth_uri').with_value( params[:auth_uri] )
|
is_expected.to contain_heat_config('keystone_authtoken/auth_uri').with_value( params[:auth_uri] )
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configures database_connection' do
|
|
||||||
is_expected.to contain_heat_config('database/connection').with_value( params[:database_connection] )
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'configures database_idle_timeout' do
|
|
||||||
is_expected.to contain_heat_config('database/idle_timeout').with_value( params[:database_idle_timeout] )
|
|
||||||
end
|
|
||||||
|
|
||||||
context("failing if database_connection is invalid") do
|
|
||||||
before { params[:database_connection] = 'foo://foo:bar@baz/moo' }
|
|
||||||
it { expect { is_expected.to raise_error(Puppet::Error) } }
|
|
||||||
end
|
|
||||||
|
|
||||||
context("with deprecated sql_connection parameter") do
|
|
||||||
before { params[:sql_connection] = 'mysql://a:b@c/d' }
|
|
||||||
it { is_expected.to contain_heat_config('database/connection').with_value( params[:sql_connection] )}
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'configures keystone_ec2_uri' do
|
it 'configures keystone_ec2_uri' do
|
||||||
is_expected.to contain_heat_config('ec2authtoken/auth_uri').with_value( params[:keystone_ec2_uri] )
|
is_expected.to contain_heat_config('ec2authtoken/auth_uri').with_value( params[:keystone_ec2_uri] )
|
||||||
end
|
end
|
||||||
@ -358,18 +340,6 @@ describe 'heat' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'with database_idle_timeout modified' do
|
|
||||||
before do
|
|
||||||
params.merge!(
|
|
||||||
:database_idle_timeout => 69
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it do
|
|
||||||
is_expected.to contain_heat_config('database/idle_timeout').with_value(69)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples_for 'with ec2authtoken auth uri set' do
|
shared_examples_for 'with ec2authtoken auth uri set' do
|
||||||
before do
|
before do
|
||||||
params.merge!(
|
params.merge!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user