db: Use postgresql lib class for psycopg package
This patch introduce the same design than mysql for postgresql by requiring dedicated lib::python class instead of declaring a new resource package within barbican module. This patch also add unit tests for barbican::db class. Change-Id: I336cf39e55f1c145cde9849ac4dc81b9cd95f8ed
This commit is contained in:
parent
a49f187941
commit
520a4941b6
|
@ -43,6 +43,8 @@ class barbican::db (
|
||||||
$database_max_overflow = 20,
|
$database_max_overflow = 20,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
include ::barbican::params
|
||||||
|
|
||||||
$database_connection_real = pick($::barbican::database_connection, $database_connection)
|
$database_connection_real = pick($::barbican::database_connection, $database_connection)
|
||||||
$database_idle_timeout_real = pick($::barbican::database_idle_timeout, $database_idle_timeout)
|
$database_idle_timeout_real = pick($::barbican::database_idle_timeout, $database_idle_timeout)
|
||||||
$database_min_pool_size_real = pick($::barbican::database_min_pool_size, $database_min_pool_size)
|
$database_min_pool_size_real = pick($::barbican::database_min_pool_size, $database_min_pool_size)
|
||||||
|
@ -62,7 +64,8 @@ class barbican::db (
|
||||||
require 'mysql::bindings::python'
|
require 'mysql::bindings::python'
|
||||||
}
|
}
|
||||||
/^postgresql:\/\//: {
|
/^postgresql:\/\//: {
|
||||||
$backend_package = $::barbican::params::psycopg_package_name
|
$backend_package = false
|
||||||
|
require 'postgresql::lib::python'
|
||||||
}
|
}
|
||||||
/^sqlite:\/\//: {
|
/^sqlite:\/\//: {
|
||||||
$backend_package = $::barbican::params::sqlite_package_name
|
$backend_package = $::barbican::params::sqlite_package_name
|
||||||
|
|
|
@ -4,11 +4,9 @@ class barbican::params {
|
||||||
|
|
||||||
case $::osfamily {
|
case $::osfamily {
|
||||||
'RedHat': {
|
'RedHat': {
|
||||||
$psycopg_package_name = 'python-psycopg2'
|
|
||||||
$sqlite_package_name = undef
|
$sqlite_package_name = undef
|
||||||
}
|
}
|
||||||
'Debian': {
|
'Debian': {
|
||||||
$psycopg_package_name = 'python-psycopg2'
|
|
||||||
$sqlite_package_name = 'python-pysqlite2'
|
$sqlite_package_name = 'python-pysqlite2'
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'barbican::db' do
|
||||||
|
|
||||||
|
shared_examples 'barbican::db' do
|
||||||
|
|
||||||
|
context 'with default parameters' do
|
||||||
|
|
||||||
|
it { is_expected.to contain_class('barbican::params') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/connection').with_value('sqlite:////var/lib/barbican/barbican.sqlite') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/idle_timeout').with_value('3600') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/min_pool_size').with_value('1') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/max_retries').with_value('10') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/retry_interval').with_value('10') }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with specific parameters' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'mysql://barbican:barbican@localhost/barbican',
|
||||||
|
:database_idle_timeout => '3601',
|
||||||
|
:database_min_pool_size => '2',
|
||||||
|
:database_max_retries => '11',
|
||||||
|
:database_retry_interval => '11',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to contain_class('barbican::params') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/connection').with_value('mysql://barbican:barbican@localhost/barbican').with_secret(true) }
|
||||||
|
it { is_expected.to contain_barbican_config('database/idle_timeout').with_value('3601') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/min_pool_size').with_value('2') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/max_retries').with_value('11') }
|
||||||
|
it { is_expected.to contain_barbican_config('database/retry_interval').with_value('11') }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with postgresql backend' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'postgresql://barbican:barbican@localhost/barbican', }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'install the proper backend package' do
|
||||||
|
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'with incorrect database_connection string' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'redis://barbican:barbican@localhost/barbican', }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_raises 'a Puppet::Error', /validate_re/
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Debian platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'Debian',
|
||||||
|
:operatingsystem => 'Debian',
|
||||||
|
:operatingsystemrelease => 'jessie',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'barbican::db'
|
||||||
|
|
||||||
|
context 'with sqlite backend' do
|
||||||
|
let :params do
|
||||||
|
{ :database_connection => 'sqlite:///var/lib/barbican/barbican.sqlite', }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'install the proper backend package' do
|
||||||
|
is_expected.to contain_package('barbican-backend-package').with(
|
||||||
|
:ensure => 'present',
|
||||||
|
:name => 'python-pysqlite2',
|
||||||
|
:tag => 'openstack'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Redhat platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'RedHat',
|
||||||
|
:operatingsystemrelease => '7.1',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'barbican::db'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue