Support of PyMySQL driver for MySQL backend

Add the ability to use python-pymysql library as backend for MySQL
connections.

Update acceptance tests to use pyMySQL.

Change-Id: Id27afb52428a50ec889e8ae77f3509e1ca956538
Docs: https://wiki.openstack.org/wiki/PyMySQL_evaluation
This commit is contained in:
Javier Pena 2015-11-16 12:18:03 +01:00
parent e328ef849d
commit f70d5d5f31
6 changed files with 47 additions and 8 deletions

View File

@ -15,7 +15,7 @@ node default {
class { '::heat':
# The keystone_password parameter is mandatory
keystone_password => 'password',
sql_connection => 'mysql://heat:heat@localhost/heat'
sql_connection => 'mysql+pymysql://heat:heat@localhost/heat'
}
# Install heat-engine

View File

@ -49,6 +49,7 @@ class heat::db (
) {
include ::heat::deps
include ::heat::params
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use heat::<myparam> if heat::db::<myparam> isn't specified.
@ -62,13 +63,17 @@ class heat::db (
$sync_db_real = pick($::heat::sync_db, $sync_db)
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 = $::heat::params::pymysql_package_name
} else {
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false

View File

@ -17,6 +17,7 @@ class heat::params {
$client_package_name = 'python-heatclient'
$common_package_name = 'openstack-heat-common'
$sqlite_package_name = undef
$pymysql_package_name = undef
# service names
$api_service_name = 'openstack-heat-api'
$api_cloudwatch_service_name = 'openstack-heat-api-cloudwatch'
@ -32,6 +33,7 @@ class heat::params {
$client_package_name = 'python-heatclient'
$common_package_name = 'heat-common'
$sqlite_package_name = 'python-pysqlite2'
$pymysql_package_name = 'python-pymysql'
# service names
$api_service_name = 'heat-api'
$api_cloudwatch_service_name = 'heat-api-cloudwatch'

View File

@ -32,7 +32,7 @@ describe 'basic heat' do
rabbit_userid => 'heat',
rabbit_password => 'an_even_bigger_secret',
rabbit_host => '127.0.0.1',
database_connection => 'mysql://heat:a_big_secret@127.0.0.1/heat?charset=utf8',
database_connection => 'mysql+pymysql://heat:a_big_secret@127.0.0.1/heat?charset=utf8',
identity_uri => 'http://127.0.0.1:35357/',
keystone_password => 'a_big_secret',
debug => true,

View File

@ -18,7 +18,7 @@ describe 'heat::db' do
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://heat:heat@localhost/heat',
{ :database_connection => 'mysql+pymysql://heat:heat@localhost/heat',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_pool_size => '12',
@ -28,7 +28,7 @@ describe 'heat::db' do
end
it { is_expected.not_to contain_class('heat::db::sync') }
it { is_expected.to contain_heat_config('database/connection').with_value('mysql://heat:heat@localhost/heat').with_secret(true) }
it { is_expected.to contain_heat_config('database/connection').with_value('mysql+pymysql://heat:heat@localhost/heat').with_secret(true) }
it { is_expected.to contain_heat_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_heat_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_heat_config('database/max_pool_size').with_value('12') }
@ -37,6 +37,14 @@ describe 'heat::db' do
end
context 'with MySQL-python library as backend package' do
let :params do
{ :database_connection => 'mysql://heat:heat@localhost/heat' }
end
it { is_expected.to contain_heat_config('database/connection').with_value('mysql://heat:heat@localhost/heat').with_secret(true) }
end
context 'with postgresql backend' do
let :params do
{ :database_connection => 'postgresql://heat:heat@localhost/heat', }
@ -56,6 +64,14 @@ describe 'heat::db' do
it_raises 'a Puppet::Error', /validate_re/
end
context 'with incorrect database_connection string' do
let :params do
{ :database_connection => 'foo+pymysql://heat:heat@localhost/heat', }
end
it_raises 'a Puppet::Error', /validate_re/
end
end
context 'on Debian platforms' do
@ -68,6 +84,14 @@ describe 'heat::db' do
end
it_configures 'heat::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://heat:heat@localhost/heat' }
end
it { is_expected.to contain_package('heat-backend-package').with({ :ensure => 'present', :name => 'python-pymysql' }) }
end
end
context 'on Redhat platforms' do
@ -79,6 +103,14 @@ describe 'heat::db' do
end
it_configures 'heat::db'
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://heat:heat@localhost/heat' }
end
it { is_expected.not_to contain_package('heat-backend-package') }
end
end
end

View File

@ -14,7 +14,7 @@ describe 'heat' do
:rabbit_userid => '<SERVICE DEFAULT>',
:rabbit_password => '',
:rabbit_virtual_host => '<SERVICE DEFAULT>',
:database_connection => 'mysql://user@host/database',
:database_connection => 'mysql+pymysql://user@host/database',
:database_idle_timeout => 3600,
:auth_uri => 'http://127.0.0.1:5000/v2.0',
:keystone_ec2_uri => 'http://127.0.0.1:5000/v2.0/ec2tokens',