Support of PyMySQL driver for MySQL backend

Add ability to use python-pymysql library
as backend for MySQL connections.
Update acceptance tests to use pyMySQL.
Docs: https://wiki.openstack.org/wiki/PyMySQL_evaluation
The same implementation as it's done for keystone:
https://review.openstack.org/#/c/242134/

Change-Id: Id279377b191363b665e22a86f117410a6f7b480c
This commit is contained in:
iberezovskiy 2015-11-03 17:13:09 +03:00
parent c1bb853fa7
commit e76e0b5d36
4 changed files with 50 additions and 7 deletions

View File

@ -56,13 +56,17 @@ class cinder::db (
$database_max_overflow_real = pick($::cinder::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 = $::cinder::params::pymysql_package_name
} else {
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false

View File

@ -21,6 +21,7 @@ class cinder::params {
$lio_package_name = 'targetcli'
$lock_path = '/var/lock/cinder'
$sqlite_package_name = 'python-pysqlite2'
$pymysql_package_name = 'python-pymysql'
} elsif($::osfamily == 'RedHat') {
@ -41,6 +42,7 @@ class cinder::params {
$lio_package_name = 'targetcli'
$lock_path = '/var/lib/cinder/tmp'
$sqlite_package_name = undef
$pymysql_package_name = undef
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux': {

View File

@ -29,7 +29,7 @@ describe 'basic cinder' do
# Cinder resources
class { '::cinder':
database_connection => 'mysql://cinder:a_big_secret@127.0.0.1/cinder?charset=utf8',
database_connection => 'mysql+pymysql://cinder:a_big_secret@127.0.0.1/cinder?charset=utf8',
rabbit_userid => 'cinder',
rabbit_password => 'an_even_bigger_secret',
rabbit_host => '127.0.0.1',

View File

@ -16,19 +16,18 @@ describe 'cinder::db' do
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://cinder:cinder@localhost/cinder',
{ :database_connection => 'mysql+pymysql://cinder:cinder@localhost/cinder',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_retries => '11',
:database_retry_interval => '11', }
end
it { is_expected.to contain_cinder_config('database/connection').with_value('mysql://cinder:cinder@localhost/cinder').with_secret(true) }
it { is_expected.to contain_cinder_config('database/connection').with_value('mysql+pymysql://cinder:cinder@localhost/cinder').with_secret(true) }
it { is_expected.to contain_cinder_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_cinder_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_cinder_config('database/max_retries').with_value('11') }
it { is_expected.to contain_cinder_config('database/retry_interval').with_value('11') }
end
context 'with postgresql backend' do
@ -42,6 +41,14 @@ describe 'cinder::db' do
end
context 'with MySQL-python library as backend package' do
let :params do
{ :database_connection => 'mysql://cinder:cinder@localhost/cinder', }
end
it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') }
end
context 'with incorrect database_connection string' do
let :params do
{ :database_connection => 'redis://cinder:cinder@localhost/cinder', }
@ -50,6 +57,14 @@ describe 'cinder::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://cinder:cinder@localhost/cinder', }
end
it_raises 'a Puppet::Error', /validate_re/
end
end
context 'on Debian platforms' do
@ -62,6 +77,20 @@ describe 'cinder::db' do
end
it_configures 'cinder::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://cinder:cinder@localhost/cinder', }
end
it 'install the proper backend package' do
is_expected.to contain_package('cinder-backend-package').with(
:ensure => 'present',
:name => 'python-pymysql',
:tag => 'openstack'
)
end
end
end
context 'on Redhat platforms' do
@ -73,6 +102,14 @@ describe 'cinder::db' do
end
it_configures 'cinder::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://cinder:cinder@localhost/cinder', }
end
it { is_expected.not_to contain_package('cinder-backend-package') }
end
end
end