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: I7b4390e0e4fe1f004e2c28df76fdbb9300114647
This commit is contained in:
Alex Schultz 2016-01-04 16:45:48 -07:00
parent 479098069f
commit a09b375f34
3 changed files with 49 additions and 5 deletions

View File

@ -52,13 +52,19 @@ class vitrage::db (
$database_max_overflow_real = pick($::vitrage::database_max_overflow, $database_max_overflow) $database_max_overflow_real = pick($::vitrage::database_max_overflow, $database_max_overflow)
validate_re($database_connection_real, validate_re($database_connection_real,
'(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
include ::vitrage::params
case $database_connection_real { case $database_connection_real {
/^mysql:\/\//: { /^mysql(\+pymysql)?:\/\//: {
$backend_package = false
require 'mysql::bindings' require 'mysql::bindings'
require 'mysql::bindings::python' require 'mysql::bindings::python'
if $database_connection_real =~ /^mysql\+pymysql/ {
$backend_package = $::vitrage::params::pymysql_package_name
} else {
$backend_package = false
}
} }
/^postgresql:\/\//: { /^postgresql:\/\//: {
$backend_package = false $backend_package = false

View File

@ -5,9 +5,11 @@ class vitrage::params {
case $::osfamily { case $::osfamily {
'RedHat': { 'RedHat': {
$sqlite_package_name = undef $sqlite_package_name = undef
$pymysql_package_name = undef
} }
'Debian': { 'Debian': {
$sqlite_package_name = 'python-pysqlite2' $sqlite_package_name = 'python-pysqlite2'
$pymysql_package_name = 'python-pymysql'
} }
default: { default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem") fail("Unsupported osfamily: ${::osfamily} operatingsystem")

View File

@ -15,7 +15,7 @@ describe 'vitrage::db' do
context 'with specific parameters' do context 'with specific parameters' do
let :params do let :params do
{ :database_connection => 'mysql://vitrage:vitrage@localhost/vitrage', { :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage',
:database_idle_timeout => '3601', :database_idle_timeout => '3601',
:database_min_pool_size => '2', :database_min_pool_size => '2',
:database_max_retries => '11', :database_max_retries => '11',
@ -25,7 +25,7 @@ describe 'vitrage::db' do
} }
end end
it { is_expected.to contain_vitrage_config('database/connection').with_value('mysql://vitrage:vitrage@localhost/vitrage') } it { is_expected.to contain_vitrage_config('database/connection').with_value('mysql+pymysql://vitrage:vitrage@localhost/vitrage') }
it { is_expected.to contain_vitrage_config('database/idle_timeout').with_value('3601') } it { is_expected.to contain_vitrage_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_vitrage_config('database/min_pool_size').with_value('2') } it { is_expected.to contain_vitrage_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_vitrage_config('database/max_retries').with_value('11') } it { is_expected.to contain_vitrage_config('database/max_retries').with_value('11') }
@ -45,12 +45,26 @@ describe 'vitrage::db' do
end end
context 'with MySQL-python library as backend package' do
let :params do
{ :database_connection => 'mysql://vitrage:vitrage@localhost/vitrage', }
end
it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') }
end
context 'with incorrect database_connection string' do context 'with incorrect database_connection string' do
let :params do let :params do
{ :database_connection => 'redis://vitrage:vitrage@localhost/vitrage', } { :database_connection => 'redis://vitrage:vitrage@localhost/vitrage', }
end end
it_raises 'a Puppet::Error', /validate_re/
end
context 'with incorrect pymysql database_connection string' do
let :params do
{ :database_connection => 'foo+pymysql://vitrage:vitrage@localhost/vitrage', }
end
it_raises 'a Puppet::Error', /validate_re/ it_raises 'a Puppet::Error', /validate_re/
end end
@ -66,6 +80,20 @@ describe 'vitrage::db' do
end end
it_configures 'vitrage::db' it_configures 'vitrage::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage', }
end
it 'install the proper backend package' do
is_expected.to contain_package('vitrage-backend-package').with(
:ensure => 'present',
:name => 'python-pymysql',
:tag => 'openstack'
)
end
end
end end
context 'on Redhat platforms' do context 'on Redhat platforms' do
@ -77,6 +105,14 @@ describe 'vitrage::db' do
end end
it_configures 'vitrage::db' it_configures 'vitrage::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage', }
end
it { is_expected.not_to contain_package('vitrage-backend-package') }
end
end end
end end