1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
require 'spec_helper'
describe 'oslo::db' do
let (:title) { 'keystone_config' }
shared_examples 'oslo-db' do
context 'with default parameters' do
it 'configure oslo_db default params' do
is_expected.to contain_keystone_config('database/sqlite_synchronous').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/backend').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/connection').with_value('<SERVICE DEFAULT>').with_secret(true)
is_expected.to contain_keystone_config('database/slave_connection').with_value('<SERVICE DEFAULT>').with_secret(true)
is_expected.to contain_keystone_config('database/mysql_sql_mode').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/connection_recycle_time').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/max_pool_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/max_retries').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/retry_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/max_overflow').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/connection_debug').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/connection_trace').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/pool_timeout').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/use_db_reconnect').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/db_retry_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/db_inc_retry_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/db_max_retry_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/db_max_retries').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('database/mysql_enable_ndb').with_value('<SERVICE DEFAULT>')
end
end
context 'with overridden parameters' do
let :params do
{
:config_group => 'custom_group',
:backend => 'sqlalchemy',
:connection => 'mysql+pymysql://db:db@master/db',
:slave_connection => 'mysql+pymysql://db:db@slave/db',
:mysql_sql_mode => 'TRADITIONAL',
:connection_recycle_time => '3601',
:max_pool_size => '100',
:max_retries => '10',
:retry_interval => '10',
:max_overflow => '50',
:connection_debug => '0',
:connection_trace => true,
:pool_timeout => '10',
:use_db_reconnect => true,
:db_retry_interval => '1',
:db_inc_retry_interval => true,
:db_max_retry_interval => '10',
:db_max_retries => '20',
:mysql_enable_ndb => true,
}
end
it 'configures database parameters' do
is_expected.to contain_keystone_config('custom_group/sqlite_synchronous').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('custom_group/backend').with_value('sqlalchemy')
is_expected.to contain_keystone_config('custom_group/connection').with_value('mysql+pymysql://db:db@master/db').with_secret(true)
is_expected.to contain_keystone_config('custom_group/slave_connection').with_value('mysql+pymysql://db:db@slave/db').with_secret(true)
is_expected.to contain_keystone_config('custom_group/mysql_sql_mode').with_value('TRADITIONAL')
is_expected.to contain_keystone_config('custom_group/connection_recycle_time').with_value('3601')
is_expected.to contain_keystone_config('custom_group/max_pool_size').with_value('100')
is_expected.to contain_keystone_config('custom_group/max_retries').with_value('10')
is_expected.to contain_keystone_config('custom_group/retry_interval').with_value('10')
is_expected.to contain_keystone_config('custom_group/max_overflow').with_value('50')
is_expected.to contain_keystone_config('custom_group/connection_debug').with_value('0')
is_expected.to contain_keystone_config('custom_group/connection_trace').with_value(true)
is_expected.to contain_keystone_config('custom_group/pool_timeout').with_value('10')
is_expected.to contain_keystone_config('custom_group/use_db_reconnect').with_value(true)
is_expected.to contain_keystone_config('custom_group/db_retry_interval').with_value('1')
is_expected.to contain_keystone_config('custom_group/db_inc_retry_interval').with_value(true)
is_expected.to contain_keystone_config('custom_group/db_max_retry_interval').with_value('10')
is_expected.to contain_keystone_config('custom_group/db_max_retries').with_value('20')
is_expected.to contain_keystone_config('custom_group/mysql_enable_ndb').with_value(true)
end
end
context 'with config management disabled' do
let :params do
{ :manage_config => false }
end
it 'does not manage config options' do
is_expected.to_not contain_keystone_config('custom_group/backend')
is_expected.to_not contain_keystone_config('custom_group/conection')
end
end
context 'with pymysql connection' do
let :params do
{ :connection => 'mysql+pymysql://db:db@localhost/db' }
end
it { is_expected.to contain_class('oslo::params') }
it { is_expected.to contain_keystone_config('database/connection').with_value('mysql+pymysql://db:db@localhost/db').with_secret(true) }
end
context 'with postgresql backend' do
let :params do
{ :connection => 'postgresql://db:db@localhost/db', }
end
it { is_expected.to contain_keystone_config('database/connection').with_value('postgresql://db:db@localhost/db').with_secret(true) }
it { is_expected.to contain_class('postgresql::lib::python') }
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_class('postgresql::lib::python')
end
end
end
context 'with postgresql backend + drivername' do
let :params do
{ :connection => 'postgresql+psycopg2://db:db@localhost/db' }
end
it { is_expected.to contain_keystone_config('database/connection').with_value('postgresql+psycopg2://db:db@localhost/db').with_secret(true) }
it { is_expected.to contain_class('postgresql::lib::python') }
end
context 'with incorrect database_connection string' do
let :params do
{ :connection => 'foo://db:db@localhost/db', }
end
it { should raise_error(Puppet::Error) }
end
context 'with incorrect pymysql database_connection string' do
let :params do
{ :connection => 'foo+pymysql://db:db@localhost/db', }
end
it { should raise_error(Puppet::Error) }
end
end
shared_examples 'oslo-db on Debian' do
context 'using pymysql driver' do
let :params do
{ :connection => 'mysql+pymysql:///db:db@localhost/db', }
end
it 'install the proper backend package' do
is_expected.to contain_package(platform_params[:pymysql_package_name]).with(
:ensure => 'installed',
:name => platform_params[:pymysql_package_name],
:tag => 'openstack'
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-pymysql')
end
end
end
end
shared_examples 'oslo-db on RedHat' do
context 'using pymysql driver' do
let :params do
{ :connection => 'mysql+pymysql:///db:db@localhost/db', }
end
end
end
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({
# puppet-postgresql requires the service_provider fact provided by
# puppetlabs-postgresql.
:service_provider => 'systemd'
}))
end
let (:platform_params) do
case facts[:os]['family']
when 'Debian'
{
:pymongo_package_name => 'python3-pymongo',
:pymysql_package_name => 'python3-pymysql',
}
when 'RedHat'
{
:pymongo_package_name => 'python3-pymongo',
:pymysql_package_name => nil,
}
end
end
it_behaves_like 'oslo-db'
it_behaves_like "oslo-db on #{facts[:os]['family']}"
end
end
end
|