Merge "Support of PyMySQL driver for MySQL backend"
This commit is contained in:
commit
3fd114478b
|
@ -54,13 +54,17 @@ class barbican::db (
|
|||
$database_max_overflow_real = pick($::barbican::database_max_overflow, $database_max_overflow)
|
||||
|
||||
validate_re($database_connection_real,
|
||||
'(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
'^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
|
||||
case $database_connection_real {
|
||||
/^mysql:\/\//: {
|
||||
$backend_package = false
|
||||
/^mysql(\+pymysql)?:\/\//: {
|
||||
require 'mysql::bindings'
|
||||
require 'mysql::bindings::python'
|
||||
if $database_connection_real =~ /^mysql\+pymysql/ {
|
||||
$backend_package = $::barbican::params::pymysql_package_name
|
||||
} else {
|
||||
$backend_package = false
|
||||
}
|
||||
}
|
||||
/^postgresql:\/\//: {
|
||||
$backend_package = false
|
||||
|
|
|
@ -5,9 +5,11 @@ class barbican::params {
|
|||
case $::osfamily {
|
||||
'RedHat': {
|
||||
$sqlite_package_name = undef
|
||||
$pymysql_package_name = undef
|
||||
}
|
||||
'Debian': {
|
||||
$sqlite_package_name = 'python-pysqlite2'
|
||||
$pymysql_package_name = 'python-pymysql'
|
||||
}
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem")
|
||||
|
|
|
@ -17,7 +17,7 @@ describe 'barbican::db' do
|
|||
|
||||
context 'with specific parameters' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://barbican:barbican@localhost/barbican',
|
||||
{ :database_connection => 'mysql+pymysql://barbican:barbican@localhost/barbican',
|
||||
:database_idle_timeout => '3601',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_retries => '11',
|
||||
|
@ -26,7 +26,7 @@ describe 'barbican::db' do
|
|||
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/connection').with_value('mysql+pymysql://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') }
|
||||
|
@ -42,9 +42,15 @@ describe 'barbican::db' do
|
|||
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://barbican:barbican@localhost/barbican', }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') }
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
|
@ -54,6 +60,13 @@ describe 'barbican::db' do
|
|||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
context 'with incorrect pymysql database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'foo+pymysql://barbican:barbican@localhost/barbican', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
|
@ -80,6 +93,20 @@ describe 'barbican::db' do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://barbican:barbican@localhost/barbican', }
|
||||
end
|
||||
|
||||
it 'install the proper backend package' do
|
||||
is_expected.to contain_package('barbican-backend-package').with(
|
||||
:ensure => 'present',
|
||||
:name => 'python-pymysql',
|
||||
:tag => 'openstack'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Redhat platforms' do
|
||||
|
@ -90,6 +117,14 @@ describe 'barbican::db' do
|
|||
end
|
||||
|
||||
it_configures 'barbican::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://barbican:barbican@localhost/barbican', }
|
||||
end
|
||||
|
||||
it { is_expected.not_to contain_package('barbican-backend-package') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue