Support of PyMySQL driver for MySQL backend

This change adds the ability to use the python-pymysql library as the
backend for MySQL connections.

Change-Id: I7604cca9e2d7bf0b93c820adec5f937f72b64fa8
changes/81/263481/3
Alex Schultz 2016-01-04 16:57:29 -07:00
parent 9e3e5aa160
commit a18c7f87d9
3 changed files with 48 additions and 6 deletions

View File

@ -54,14 +54,18 @@ class aodh::db (
$database_max_overflow_real = pick($::aodh::database_max_overflow, $database_max_overflow)
validate_re($database_connection_real,
'(sqlite|mysql|postgresql|mongodb):\/\/(\S+:\S+@\S+\/\S+)?')
'^(sqlite|mysql(\+pymysql)?|postgresql|mongodb):\/\/(\S+:\S+@\S+\/\S+)?')
if $database_connection_real {
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 = $::aodh::params::pymysql_package_name
} else {
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false

View File

@ -20,6 +20,7 @@ class aodh::params {
$listener_package_name = 'openstack-aodh-listener'
$listener_service_name = 'openstack-aodh-listener'
$pymongo_package_name = 'python-pymongo'
$pymysql_package_name = undef
$aodh_wsgi_script_path = '/var/www/cgi-bin/aodh'
$aodh_wsgi_script_source = '/usr/lib/python2.7/site-packages/aodh/api/app.wsgi'
}
@ -38,6 +39,7 @@ class aodh::params {
$listener_package_name = 'aodh-listener'
$listener_service_name = 'aodh-listener'
$pymongo_package_name = 'python-pymongo'
$pymysql_package_name = 'python-pymysql'
$aodh_wsgi_script_path = '/usr/lib/cgi-bin/aodh'
$aodh_wsgi_script_source = '/usr/share/aodh-common/app.wsgi'
}

View File

@ -17,7 +17,7 @@ describe 'aodh::db' do
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://aodh:aodh@localhost/aodh',
{ :database_connection => 'mysql+pymysql://aodh:aodh@localhost/aodh',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_retries => '11',
@ -26,7 +26,7 @@ describe 'aodh::db' do
end
it { is_expected.to contain_class('aodh::params') }
it { is_expected.to contain_aodh_config('database/connection').with_value('mysql://aodh:aodh@localhost/aodh').with_secret(true) }
it { is_expected.to contain_aodh_config('database/connection').with_value('mysql+pymysql://aodh:aodh@localhost/aodh').with_secret(true) }
it { is_expected.to contain_aodh_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_aodh_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_aodh_config('database/max_retries').with_value('11') }
@ -45,6 +45,14 @@ describe 'aodh::db' do
end
context 'with MySQL-python library as backend package' do
let :params do
{ :database_connection => 'mysql://aodh:aodh@localhost/aodh', }
end
it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') }
end
context 'with mongodb backend' do
let :params do
{ :database_connection => 'mongodb://localhost:1234/aodh', }
@ -70,6 +78,13 @@ describe 'aodh::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://aodh:aodh@localhost/aodh', }
end
it_raises 'a Puppet::Error', /validate_re/
end
end
context 'on Debian platforms' do
@ -96,6 +111,20 @@ describe 'aodh::db' do
end
end
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://aodh:aodh@localhost/aodh', }
end
it 'install the proper backend package' do
is_expected.to contain_package('aodh-backend-package').with(
:ensure => 'present',
:name => 'python-pymysql',
:tag => 'openstack'
)
end
end
end
context 'on Redhat platforms' do
@ -106,7 +135,14 @@ describe 'aodh::db' do
end
it_configures 'aodh::db'
end
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://aodh:aodh@localhost/aodh', }
end
it { is_expected.not_to contain_package('aodh-backend-package') }
end
end
end