Skip to content

Commit 1eeba20

Browse files
sbadiastrider
authored andcommitted
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 aodh module. This patch also add unit tests for aodh::db class. Change-Id: I3f9ed49b44a9a7c89be06f40a5823cc24a66066e
1 parent 54f857d commit 1eeba20

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

manifests/db.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
$database_max_overflow = 20,
4444
) {
4545

46+
include ::aodh::params
47+
4648
$database_connection_real = pick($::aodh::database_connection, $database_connection)
4749
$database_idle_timeout_real = pick($::aodh::database_idle_timeout, $database_idle_timeout)
4850
$database_min_pool_size_real = pick($::aodh::database_min_pool_size, $database_min_pool_size)
@@ -62,7 +64,8 @@
6264
require 'mysql::bindings::python'
6365
}
6466
/^postgresql:\/\//: {
65-
$backend_package = $::aodh::params::psycopg_package_name
67+
$backend_package = false
68+
require 'postgresql::lib::python'
6669
}
6770
/^sqlite:\/\//: {
6871
$backend_package = $::aodh::params::sqlite_package_name

spec/classes/aodh_db_spec.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
require 'spec_helper'
2+
3+
describe 'aodh::db' do
4+
5+
shared_examples 'aodh::db' do
6+
7+
context 'with default parameters' do
8+
9+
it { is_expected.to contain_class('aodh::params') }
10+
it { is_expected.to contain_aodh_config('database/connection').with_value('sqlite:////var/lib/aodh/aodh.sqlite') }
11+
it { is_expected.to contain_aodh_config('database/idle_timeout').with_value('3600') }
12+
it { is_expected.to contain_aodh_config('database/min_pool_size').with_value('1') }
13+
it { is_expected.to contain_aodh_config('database/max_retries').with_value('10') }
14+
it { is_expected.to contain_aodh_config('database/retry_interval').with_value('10') }
15+
16+
end
17+
18+
context 'with specific parameters' do
19+
let :params do
20+
{ :database_connection => 'mysql://aodh:aodh@localhost/aodh',
21+
:database_idle_timeout => '3601',
22+
:database_min_pool_size => '2',
23+
:database_max_retries => '11',
24+
:database_retry_interval => '11',
25+
}
26+
end
27+
28+
it { is_expected.to contain_class('aodh::params') }
29+
it { is_expected.to contain_aodh_config('database/connection').with_value('mysql://aodh:aodh@localhost/aodh').with_secret(true) }
30+
it { is_expected.to contain_aodh_config('database/idle_timeout').with_value('3601') }
31+
it { is_expected.to contain_aodh_config('database/min_pool_size').with_value('2') }
32+
it { is_expected.to contain_aodh_config('database/max_retries').with_value('11') }
33+
it { is_expected.to contain_aodh_config('database/retry_interval').with_value('11') }
34+
35+
end
36+
37+
context 'with postgresql backend' do
38+
let :params do
39+
{ :database_connection => 'postgresql://localhost:1234/aodh', }
40+
end
41+
42+
it 'install the proper backend package' do
43+
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
44+
end
45+
46+
end
47+
48+
49+
context 'with incorrect database_connection string' do
50+
let :params do
51+
{ :database_connection => 'redis://aodh:aodh@localhost/aodh', }
52+
end
53+
54+
it_raises 'a Puppet::Error', /validate_re/
55+
end
56+
57+
end
58+
59+
context 'on Debian platforms' do
60+
let :facts do
61+
{ :osfamily => 'Debian',
62+
:operatingsystem => 'Debian',
63+
:operatingsystemrelease => 'jessie',
64+
}
65+
end
66+
67+
it_configures 'aodh::db'
68+
69+
context 'with sqlite backend' do
70+
let :params do
71+
{ :database_connection => 'sqlite:///var/lib/aodh/aodh.sqlite', }
72+
end
73+
74+
it 'install the proper backend package' do
75+
is_expected.to contain_package('aodh-backend-package').with(
76+
:ensure => 'present',
77+
:name => 'python-pysqlite2',
78+
:tag => 'openstack'
79+
)
80+
end
81+
82+
end
83+
end
84+
85+
context 'on Redhat platforms' do
86+
let :facts do
87+
{ :osfamily => 'RedHat',
88+
:operatingsystemrelease => '7.1',
89+
}
90+
end
91+
92+
it_configures 'aodh::db'
93+
end
94+
95+
end
96+

0 commit comments

Comments
 (0)