Add db related classes
Change-Id: Ifd913a7ed4f55e41a11da99bdfbc293a53f1614f
This commit is contained in:
parent
de16acd5bc
commit
ad894b5ec2
|
@ -43,24 +43,16 @@ class ec2api::db (
|
|||
$database_max_overflow = $::os_service_default,
|
||||
) {
|
||||
|
||||
$database_connection_real = pick($::ec2api::database_connection, $database_connection)
|
||||
$database_idle_timeout_real = pick($::ec2api::database_idle_timeout, $database_idle_timeout)
|
||||
$database_min_pool_size_real = pick($::ec2api::database_min_pool_size, $database_min_pool_size)
|
||||
$database_max_pool_size_real = pick($::ec2api::database_max_pool_size, $database_max_pool_size)
|
||||
$database_max_retries_real = pick($::ec2api::database_max_retries, $database_max_retries)
|
||||
$database_retry_interval_real = pick($::ec2api::database_retry_interval, $database_retry_interval)
|
||||
$database_max_overflow_real = pick($::ec2api::database_max_overflow, $database_max_overflow)
|
||||
|
||||
validate_re($database_connection_real,
|
||||
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
validate_re($database_connection, '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
|
||||
oslo::db { 'ec2api_config':
|
||||
connection => $database_connection_real,
|
||||
idle_timeout => $database_idle_timeout_real,
|
||||
min_pool_size => $database_min_pool_size_real,
|
||||
max_retries => $database_max_retries_real,
|
||||
retry_interval => $database_retry_interval_real,
|
||||
max_pool_size => $database_max_pool_size_real,
|
||||
max_overflow => $database_max_overflow_real,
|
||||
connection => $database_connection,
|
||||
idle_timeout => $database_idle_timeout,
|
||||
min_pool_size => $database_min_pool_size,
|
||||
max_retries => $database_max_retries,
|
||||
retry_interval => $database_retry_interval,
|
||||
max_pool_size => $database_max_pool_size,
|
||||
max_overflow => $database_max_overflow,
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,17 +42,21 @@
|
|||
#
|
||||
# == Copyright
|
||||
#
|
||||
class ec2api::db::mysql(
|
||||
class ec2api::db::mysql (
|
||||
$password,
|
||||
$dbname = 'ec2api',
|
||||
$user = 'ec2api',
|
||||
$dbname = 'ec2api',
|
||||
$host = '127.0.0.1',
|
||||
$charset = 'utf8',
|
||||
$collate = 'utf8_general_ci',
|
||||
$allowed_hosts = undef
|
||||
) {
|
||||
|
||||
validate_string($password)
|
||||
validate_string($dbname)
|
||||
validate_string($user)
|
||||
validate_string($host)
|
||||
validate_string($charset)
|
||||
validate_string($collate)
|
||||
|
||||
::openstacklib::db::mysql { 'ec2api':
|
||||
user => $user,
|
||||
|
@ -64,5 +68,7 @@ class ec2api::db::mysql(
|
|||
allowed_hosts => $allowed_hosts,
|
||||
}
|
||||
|
||||
::Openstacklib::Db::Mysql['ec2api'] ~> Exec<| title == 'ec2api-manage db_sync' |>
|
||||
::Openstacklib::Db::Mysql['ec2api'] ~>
|
||||
Exec<| title == 'ec2api_db_sync' |>
|
||||
|
||||
}
|
||||
|
|
|
@ -32,15 +32,16 @@
|
|||
#
|
||||
# == Copyright
|
||||
#
|
||||
class ec2api::db::postgresql(
|
||||
class ec2api::db::postgresql (
|
||||
$password,
|
||||
$dbname = 'ec2api',
|
||||
$user = 'ec2api',
|
||||
$dbname = 'ec2api',
|
||||
$encoding = undef,
|
||||
$privileges = 'ALL',
|
||||
) {
|
||||
|
||||
Class['ec2api::db::postgresql'] -> Service<| title == 'ec2api' |>
|
||||
Class['ec2api::db::postgresql'] ->
|
||||
Service<| tag == 'ec2api' |>
|
||||
|
||||
::openstacklib::db::postgresql { 'ec2api':
|
||||
password_hash => postgresql_password($user, $password),
|
||||
|
@ -50,6 +51,7 @@ class ec2api::db::postgresql(
|
|||
privileges => $privileges,
|
||||
}
|
||||
|
||||
::Openstacklib::Db::Postgresql['ec2api'] ~> Exec<| title == 'ec2api-manage db_sync' |>
|
||||
::Openstacklib::Db::Postgresql['ec2api'] ~>
|
||||
Exec<| title == 'ec2api_db_sync' |>
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +1,45 @@
|
|||
# == Class: ec2api::db::sync
|
||||
#
|
||||
# Class to execute ec2api-manage db_sync
|
||||
# Class to execute "ec2api-manage db_sync"
|
||||
#
|
||||
# == Parameters
|
||||
# === Parameters
|
||||
#
|
||||
# [*extra_params*]
|
||||
# (optional) String of extra command line parameters to append
|
||||
# to the ec2api-dbsync command.
|
||||
# Defaults to undef
|
||||
# [*system_user*]
|
||||
# Run db_sync from this system user account.
|
||||
# Default: ec2api
|
||||
#
|
||||
class ec2api::db::sync(
|
||||
$extra_params = undef,
|
||||
) {
|
||||
exec { 'ec2api-db-sync':
|
||||
command => "ec2api-manage db_sync ${extra_params}",
|
||||
# [*system_group*]
|
||||
# Run db_sync by this system group.
|
||||
# Default: ec2api
|
||||
#
|
||||
class ec2api::db::sync (
|
||||
$system_user = 'ec2api',
|
||||
$system_group = 'ec2api',
|
||||
) inherits ::ec2api::params {
|
||||
|
||||
exec { 'ec2api_db_sync' :
|
||||
command => 'ec2api-manage db_sync',
|
||||
path => '/usr/bin',
|
||||
user => 'ec2api',
|
||||
user => $system_user,
|
||||
group => $system_group,
|
||||
refreshonly => true,
|
||||
subscribe => [Package['ec2api'], Ec2api_config['database/connection']],
|
||||
}
|
||||
|
||||
Exec['ec2api-manage db_sync'] ~> Service<| title == 'ec2api' |>
|
||||
Package <| title == 'ec2api' |> ~>
|
||||
Exec['ec2api_db_sync']
|
||||
|
||||
Ec2api_config <| title == 'database/connection' |> ~>
|
||||
Exec['ec2api_db_sync']
|
||||
|
||||
User <| title == 'ec2api' |> ->
|
||||
Exec['ec2api_db_sync']
|
||||
|
||||
Exec['ec2api_db_sync'] ~>
|
||||
Service<| tag == 'ec2api-service' |>
|
||||
|
||||
Exec['ec2api_db_sync'] ~>
|
||||
Service<| tag == 'ec2api-service' |>
|
||||
|
||||
Exec['ec2api_db_sync'] ~>
|
||||
Service<| tag == 'ec2api-service' |>
|
||||
}
|
||||
|
|
|
@ -1,60 +1,64 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'ec2api::db::mysql' do
|
||||
on_supported_os(supported_os: OSDefaults.get_supported_os).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
|
||||
let :pre_condition do
|
||||
[
|
||||
'include mysql::server',
|
||||
'include ec2api::db::sync'
|
||||
]
|
||||
let(:facts) { facts.merge! @default_facts }
|
||||
|
||||
describe 'with default parameters' do
|
||||
let(:params) do
|
||||
{
|
||||
password: 'my_password',
|
||||
}
|
||||
end
|
||||
|
||||
db_parameters = {
|
||||
user: 'ec2api',
|
||||
password_hash: '*CCD3A959D6A004B9C3807B728BC2E55B67E10518',
|
||||
dbname: 'ec2api',
|
||||
host: '127.0.0.1',
|
||||
charset: 'utf8',
|
||||
collate: 'utf8_general_ci',
|
||||
}
|
||||
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db::mysql') }
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('ec2api').with(db_parameters) }
|
||||
end
|
||||
|
||||
describe 'with custom parameters' do
|
||||
let(:params) do
|
||||
{
|
||||
password: 'my_password',
|
||||
user: 'ec2user',
|
||||
dbname: 'ec2db',
|
||||
host: '192.168.0.1',
|
||||
charset: 'cp1251',
|
||||
collate: 'cp1251_general_ci',
|
||||
allowed_hosts: %w(192.168.0.2 192.168.0.3),
|
||||
}
|
||||
end
|
||||
|
||||
db_parameters = {
|
||||
user: 'ec2user',
|
||||
password_hash: '*CCD3A959D6A004B9C3807B728BC2E55B67E10518',
|
||||
dbname: 'ec2db',
|
||||
host: '192.168.0.1',
|
||||
charset: 'cp1251',
|
||||
collate: 'cp1251_general_ci',
|
||||
allowed_hosts: %w(192.168.0.2 192.168.0.3)
|
||||
}
|
||||
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db::mysql') }
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('ec2api').with(db_parameters) }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
'password' => 'fooboozoo_default_password',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with only required params' do
|
||||
it { is_expected.to contain_openstacklib__db__mysql('ec2api').with(
|
||||
:user => 'ec2api',
|
||||
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
|
||||
:dbname => 'ec2api',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8',
|
||||
:collate => 'utf8_general_ci',
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
before { params.merge!( :allowed_hosts => ['127.0.0.1','%'] ) }
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('ec2api').with(
|
||||
:user => 'ec2api',
|
||||
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
|
||||
:dbname => 'ec2api',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8',
|
||||
:collate => 'utf8_general_ci',
|
||||
:allowed_hosts => ['127.0.0.1','%']
|
||||
)}
|
||||
end
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
before { params.merge!( :allowed_hosts => '192.168.1.1' ) }
|
||||
|
||||
it { is_expected.to contain_openstacklib__db__mysql('ec2api').with(
|
||||
:user => 'ec2api',
|
||||
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
|
||||
:dbname => 'ec2api',
|
||||
:host => '127.0.0.1',
|
||||
:charset => 'utf8',
|
||||
:collate => 'utf8_general_ci',
|
||||
:allowed_hosts => '192.168.1.1'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,42 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'ec2api::db::postgresql' do
|
||||
|
||||
shared_examples_for 'ec2api::db::postgresql' do
|
||||
let :req_params do
|
||||
{ :password => 'pw' }
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
'include postgresql::server'
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
req_params
|
||||
end
|
||||
|
||||
it { is_expected.to contain_postgresql__server__db('ec2api').with(
|
||||
:user => 'ec2api',
|
||||
:password => 'md58f5ac3d04c0da5a38f9c80d62f00eb1e'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
on_supported_os(supported_os: OSDefaults.get_supported_os).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
|
||||
let (:facts) do
|
||||
facts.merge(OSDefaults.get_facts({
|
||||
facts.merge!(OSDefaults.get_facts({
|
||||
:processorcount => 8,
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
}))
|
||||
end
|
||||
|
||||
it_configures 'ec2api::db::postgresql'
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
{
|
||||
:password => 'pw',
|
||||
}
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
'include postgresql::server'
|
||||
end
|
||||
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db::postgresql') }
|
||||
|
||||
it { is_expected.to contain_postgresql__server__db('ec2api').with(
|
||||
:user => 'ec2api',
|
||||
:password => 'md58f5ac3d04c0da5a38f9c80d62f00eb1e'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,121 +1,59 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'ec2api::db' do
|
||||
on_supported_os(supported_os: OSDefaults.get_supported_os).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
|
||||
shared_examples 'ec2api::db' do
|
||||
context 'with default parameters' do
|
||||
it { is_expected.to contain_ec2api_config('database/connection').with_value('sqlite:////var/lib/ec2api/ec2api.sqlite') }
|
||||
it { is_expected.to contain_ec2api_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_ec2api_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_ec2api_config('database/retry_interval').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_pool_size').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_overflow').with_value('<SERVICE DEFAULT>') }
|
||||
end
|
||||
let(:facts) { facts.merge! @default_facts }
|
||||
|
||||
context 'with specific parameters' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://ec2api:ec2api@localhost/ec2api',
|
||||
:database_idle_timeout => '3601',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_retries => '11',
|
||||
:database_retry_interval => '11',
|
||||
:database_max_pool_size => '11',
|
||||
:database_max_overflow => '21',
|
||||
describe 'with default parameters' do
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db') }
|
||||
|
||||
parameters = {
|
||||
:connection => 'sqlite:////var/lib/ec2api/ec2api.sqlite',
|
||||
:idle_timeout => '<SERVICE DEFAULT>',
|
||||
:min_pool_size => '<SERVICE DEFAULT>',
|
||||
:max_retries => '<SERVICE DEFAULT>',
|
||||
:retry_interval => '<SERVICE DEFAULT>',
|
||||
:max_pool_size => '<SERVICE DEFAULT>',
|
||||
:max_overflow => '<SERVICE DEFAULT>',
|
||||
}
|
||||
|
||||
it { is_expected.to contain_oslo__db('ec2api_config').with(parameters) }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_ec2api_config('database/connection').with_value('mysql+pymysql://ec2api:ec2api@localhost/ec2api') }
|
||||
it { is_expected.to contain_ec2api_config('database/idle_timeout').with_value('3601') }
|
||||
it { is_expected.to contain_ec2api_config('database/min_pool_size').with_value('2') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_retries').with_value('11') }
|
||||
it { is_expected.to contain_ec2api_config('database/retry_interval').with_value('11') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_pool_size').with_value('11') }
|
||||
it { is_expected.to contain_ec2api_config('database/max_overflow').with_value('21') }
|
||||
end
|
||||
describe 'with custom parameters' do
|
||||
let(:params) do
|
||||
{
|
||||
:database_connection => 'sqlite:////path/to/my/db.sqlite',
|
||||
:database_idle_timeout => '1',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_retries => '3',
|
||||
:database_retry_interval => '4',
|
||||
:database_max_pool_size => '5',
|
||||
:database_max_overflow => '6',
|
||||
}
|
||||
end
|
||||
|
||||
context 'with postgresql backend' do
|
||||
let :params do
|
||||
{ :database_connection => 'postgresql://ec2api:ec2api@localhost/ec2api', }
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db') }
|
||||
|
||||
parameters = {
|
||||
:connection => 'sqlite:////path/to/my/db.sqlite',
|
||||
:idle_timeout => '1',
|
||||
:min_pool_size => '2',
|
||||
:max_retries => '3',
|
||||
:retry_interval => '4',
|
||||
:max_pool_size => '5',
|
||||
:max_overflow => '6',
|
||||
}
|
||||
|
||||
it { is_expected.to contain_oslo__db('ec2api_config').with(parameters) }
|
||||
end
|
||||
|
||||
it 'install the proper backend package' do
|
||||
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'with MySQL-python library as backend package' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://ec2api:ec2api@localhost/ec2api', }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') }
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'foodb://ec2api:ec2api@localhost/ec2api', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
context 'with incorrect pymysql database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'foo+pymysql://ec2api:ec2api@localhost/ec2api', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => 'jessie',
|
||||
})
|
||||
end
|
||||
|
||||
it_configures 'ec2api::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://ec2api:ec2api@localhost/ec2api', }
|
||||
end
|
||||
|
||||
it 'install the proper backend package' do
|
||||
is_expected.to contain_package('db_backend_package').with(
|
||||
:ensure => 'present',
|
||||
:name => 'python-pymysql',
|
||||
:tag => 'openstack'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Redhat platforms' do
|
||||
let :facts do
|
||||
@default_facts.merge({
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystemrelease => '7.1',
|
||||
})
|
||||
end
|
||||
|
||||
it_configures 'ec2api::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://ec2api:ec2api@localhost/ec2api', }
|
||||
end
|
||||
|
||||
it 'install the proper backend package' do
|
||||
is_expected.not_to contain_package('db_backend_package')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'ec2api::db::sync' do
|
||||
on_supported_os(supported_os: OSDefaults.get_supported_os).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
|
||||
let(:facts) { facts }
|
||||
|
||||
describe 'with default parameters' do
|
||||
exec_parameters = {
|
||||
command: 'ec2api-manage db_sync',
|
||||
path: '/usr/bin',
|
||||
user: 'ec2api',
|
||||
group: 'ec2api',
|
||||
refreshonly: true,
|
||||
}
|
||||
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::db::sync') }
|
||||
|
||||
it { is_expected.to contain_class('ec2api::params') }
|
||||
|
||||
it { is_expected.to contain_exec('ec2api_db_sync').with(exec_parameters) }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue