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. Change-Id: I75045bc44aa05e46b4ce1f4cc65b3080bd98704a Docs: https://wiki.openstack.org/wiki/PyMySQL_evaluation
This commit is contained in:
parent
a883add571
commit
4f86d5d685
@ -43,6 +43,8 @@ class neutron::db (
|
||||
$database_max_overflow = 20,
|
||||
) {
|
||||
|
||||
include ::neutron::params
|
||||
|
||||
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
|
||||
# to use neutron::<myparam> if neutron::db::<myparam> isn't specified.
|
||||
$database_connection_real = pick($::neutron::server::database_connection, $database_connection)
|
||||
@ -54,14 +56,18 @@ class neutron::db (
|
||||
$database_max_overflow_real = pick($::neutron::server::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+)?')
|
||||
|
||||
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 = $::neutron::params::pymysql_package_name
|
||||
} else {
|
||||
$backend_package = false
|
||||
}
|
||||
}
|
||||
/^postgresql:\/\//: {
|
||||
$backend_package = false
|
||||
|
@ -78,6 +78,7 @@ class neutron::params {
|
||||
$kernel_headers = "linux-headers-${::kernelrelease}"
|
||||
|
||||
$sqlite_package_name = undef
|
||||
$pymysql_package_name = undef
|
||||
|
||||
} elsif($::osfamily == 'Debian') {
|
||||
|
||||
@ -159,6 +160,7 @@ class neutron::params {
|
||||
$kernel_headers = "linux-headers-${::kernelrelease}"
|
||||
|
||||
$sqlite_package_name = 'python-pysqlite2'
|
||||
$pymysql_package_name = 'python-pymysql'
|
||||
} else {
|
||||
|
||||
fail("Unsupported osfamily ${::osfamily}")
|
||||
|
@ -49,7 +49,7 @@ describe 'basic neutron' do
|
||||
password => 'a_big_secret',
|
||||
}
|
||||
class { '::neutron::server':
|
||||
database_connection => 'mysql://neutron:a_big_secret@127.0.0.1/neutron?charset=utf8',
|
||||
database_connection => 'mysql+pymysql://neutron:a_big_secret@127.0.0.1/neutron?charset=utf8',
|
||||
auth_password => 'a_big_secret',
|
||||
identity_uri => 'http://127.0.0.1:35357/',
|
||||
sync_db => true,
|
||||
|
@ -16,14 +16,14 @@ describe 'neutron::db' do
|
||||
|
||||
context 'with specific parameters' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://neutron:neutron@localhost/neutron',
|
||||
{ :database_connection => 'mysql+pymysql://neutron:neutron@localhost/neutron',
|
||||
:database_idle_timeout => '3601',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_retries => '11',
|
||||
:database_retry_interval => '11', }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_neutron_config('database/connection').with_value('mysql://neutron:neutron@localhost/neutron').with_secret(true) }
|
||||
it { is_expected.to contain_neutron_config('database/connection').with_value('mysql+pymysql://neutron:neutron@localhost/neutron').with_secret(true) }
|
||||
it { is_expected.to contain_neutron_config('database/idle_timeout').with_value('3601') }
|
||||
it { is_expected.to contain_neutron_config('database/min_pool_size').with_value('2') }
|
||||
it { is_expected.to contain_neutron_config('database/max_retries').with_value('11') }
|
||||
@ -31,6 +31,14 @@ describe 'neutron::db' do
|
||||
|
||||
end
|
||||
|
||||
context 'with MySQL-python library as backend package' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://neutron:neutron@localhost/neutron' }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_neutron_config('database/connection').with_value('mysql://neutron:neutron@localhost/neutron').with_secret(true) }
|
||||
end
|
||||
|
||||
context 'with postgresql backend' do
|
||||
let :params do
|
||||
{ :database_connection => 'postgresql://neutron:neutron@localhost/neutron', }
|
||||
@ -50,6 +58,14 @@ describe 'neutron::db' do
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'foo+pymysql://neutron:neutron@localhost/neutron', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
@ -61,6 +77,15 @@ describe 'neutron::db' do
|
||||
end
|
||||
|
||||
it_configures 'neutron::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://neutron:neutron@localhost/neutron' }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_package('neutron-backend-package').with({ :ensure => 'present', :name => 'python-pymysql' }) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on Redhat platforms' do
|
||||
@ -71,6 +96,15 @@ describe 'neutron::db' do
|
||||
end
|
||||
|
||||
it_configures 'neutron::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://neutron:neutron@localhost/neutron' }
|
||||
end
|
||||
|
||||
it { is_expected.not_to contain_package('neutron-backend-package') }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user