Support of PyMySQL driver for MySQL backend
Add ability to use python-pymysql library as backend for MySQL connections, and use it as default. Update acceptance tests to use pyMySQL. Change-Id: I625f1e6adb5ad581c293431d90d1a9e5578472d4 Docs: https://wiki.openstack.org/wiki/PyMySQL_evaluation
This commit is contained in:
parent
92d8d15b5c
commit
6ef55f4420
|
@ -22,7 +22,7 @@ class { '::sahara::db::mysql':
|
|||
|
||||
# Then the common class
|
||||
class { '::sahara':
|
||||
database_connection => 'mysql://sahara:a_big_secret@127.0.0.1:3306/sahara',
|
||||
database_connection => 'mysql+pymysql://sahara:a_big_secret@127.0.0.1:3306/sahara',
|
||||
verbose => true,
|
||||
debug => true,
|
||||
admin_user => 'admin',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
# [*database_connection*]
|
||||
# (Optional) The connection string to use to connect to the database.
|
||||
# Defaults to mysql://sahara:secrete@localhost:3306/sahara.
|
||||
# Defaults to 'mysql+pymysql://sahara:secrete@localhost:3306/sahara'
|
||||
#
|
||||
# [*database_max_retries*]
|
||||
# (Optional) Maximum number of database connection retries during startup.
|
||||
|
@ -34,7 +34,7 @@
|
|||
# Defaults to $::os_service_default.
|
||||
#
|
||||
class sahara::db (
|
||||
$database_connection = 'mysql://sahara:secrete@localhost:3306/sahara',
|
||||
$database_connection = 'mysql+pymysql://sahara:secrete@localhost:3306/sahara',
|
||||
$database_idle_timeout = $::os_service_default,
|
||||
$database_min_pool_size = $::os_service_default,
|
||||
$database_max_pool_size = $::os_service_default,
|
||||
|
@ -43,6 +43,8 @@ class sahara::db (
|
|||
$database_max_overflow = $::os_service_default,
|
||||
) {
|
||||
|
||||
include ::sahara::params
|
||||
|
||||
# NOTE(degorenko): In order to keep backward compatibility we rely on the pick function
|
||||
# to use sahara::<myparam> if sahara::db::<myparam> isn't specified.
|
||||
$database_connection_real = pick($::sahara::database_connection, $database_connection)
|
||||
|
@ -53,13 +55,18 @@ class sahara::db (
|
|||
$database_retry_interval_real = pick($::sahara::database_retry_interval, $database_retry_interval)
|
||||
$database_max_overflow_real = pick($::sahara::database_max_overflow, $database_max_overflow)
|
||||
|
||||
validate_re($database_connection_real, '(mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
|
||||
validate_re($database_connection_real,
|
||||
'^(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 = $::sahara::params::pymysql_package_name
|
||||
} else {
|
||||
$backend_package = false
|
||||
}
|
||||
}
|
||||
/^postgresql:\/\//: {
|
||||
$backend_package = false
|
||||
|
|
|
@ -15,6 +15,7 @@ class sahara::params {
|
|||
$all_service_name = 'openstack-sahara-all'
|
||||
$api_service_name = 'openstack-sahara-api'
|
||||
$engine_service_name = 'openstack-sahara-engine'
|
||||
$pymysql_package_name = undef
|
||||
}
|
||||
'Debian': {
|
||||
$common_package_name = 'sahara-common'
|
||||
|
@ -24,6 +25,7 @@ class sahara::params {
|
|||
$all_service_name = 'sahara'
|
||||
$api_service_name = 'sahara-api'
|
||||
$engine_service_name = 'sahara-engine'
|
||||
$pymysql_package_name = 'python-pymysql'
|
||||
}
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}")
|
||||
|
|
|
@ -36,7 +36,7 @@ describe 'basic sahara' do
|
|||
rabbit_password => 'an_even_bigger_secret',
|
||||
rabbit_host => '127.0.0.1',
|
||||
rpc_backend => 'rabbit',
|
||||
database_connection => 'mysql://sahara:a_big_secret@127.0.0.1/sahara?charset=utf8',
|
||||
database_connection => 'mysql+pymysql://sahara:a_big_secret@127.0.0.1/sahara?charset=utf8',
|
||||
admin_password => 'a_big_secret',
|
||||
}
|
||||
class { '::sahara::service::api': }
|
||||
|
|
|
@ -4,7 +4,7 @@ describe 'sahara::db' do
|
|||
|
||||
shared_examples 'sahara::db' do
|
||||
context 'with default parameters' do
|
||||
it { is_expected.to contain_sahara_config('database/connection').with_value('mysql://sahara:secrete@localhost:3306/sahara').with_secret(true) }
|
||||
it { is_expected.to contain_sahara_config('database/connection').with_value('mysql+pymysql://sahara:secrete@localhost:3306/sahara').with_secret(true) }
|
||||
it { is_expected.to contain_sahara_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_sahara_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_sahara_config('database/max_retries').with_value('<SERVICE DEFAULT>') }
|
||||
|
@ -15,7 +15,7 @@ describe 'sahara::db' do
|
|||
|
||||
context 'with specific parameters' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://sahara:sahara@localhost/sahara',
|
||||
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara',
|
||||
:database_idle_timeout => '3601',
|
||||
:database_min_pool_size => '2',
|
||||
:database_max_retries => '11',
|
||||
|
@ -25,7 +25,7 @@ describe 'sahara::db' do
|
|||
}
|
||||
end
|
||||
|
||||
it { is_expected.to contain_sahara_config('database/connection').with_value('mysql://sahara:sahara@localhost/sahara').with_secret(true) }
|
||||
it { is_expected.to contain_sahara_config('database/connection').with_value('mysql+pymysql://sahara:sahara@localhost/sahara').with_secret(true) }
|
||||
it { is_expected.to contain_sahara_config('database/idle_timeout').with_value('3601') }
|
||||
it { is_expected.to contain_sahara_config('database/min_pool_size').with_value('2') }
|
||||
it { is_expected.to contain_sahara_config('database/max_retries').with_value('11') }
|
||||
|
@ -34,6 +34,14 @@ describe 'sahara::db' do
|
|||
it { is_expected.to contain_sahara_config('database/max_overflow').with_value('21') }
|
||||
end
|
||||
|
||||
context 'with MySQL-python library as backend package' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql://sahara:sahara@localhost/sahara' }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_sahara_config('database/connection').with_value('mysql://sahara:sahara@localhost/sahara').with_secret(true) }
|
||||
end
|
||||
|
||||
context 'with postgresql backend' do
|
||||
let :params do
|
||||
{ :database_connection => 'postgresql://sahara:sahara@localhost/sahara', }
|
||||
|
@ -52,6 +60,14 @@ describe 'sahara::db' do
|
|||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
{ :database_connection => 'foo+pymysql://sahara:sahara@localhost/sahara', }
|
||||
end
|
||||
|
||||
it_raises 'a Puppet::Error', /validate_re/
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
|
@ -63,6 +79,15 @@ describe 'sahara::db' do
|
|||
end
|
||||
|
||||
it_configures 'sahara::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara' }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_package('sahara-backend-package').with({ :ensure => 'present', :name => 'python-pymysql' }) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on Redhat platforms' do
|
||||
|
@ -73,6 +98,14 @@ describe 'sahara::db' do
|
|||
end
|
||||
|
||||
it_configures 'sahara::db'
|
||||
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara' }
|
||||
end
|
||||
|
||||
it { is_expected.not_to contain_package('sahara-backend-package') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue