From f70d5d5f31685bccc7e1f8bca9a63ea43ccb3251 Mon Sep 17 00:00:00 2001 From: Javier Pena Date: Mon, 16 Nov 2015 12:18:03 +0100 Subject: [PATCH] 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 --- examples/site.pp | 2 +- manifests/db.pp | 11 ++++++--- manifests/params.pp | 2 ++ spec/acceptance/basic_heat_spec.rb | 2 +- spec/classes/heat_db_spec.rb | 36 ++++++++++++++++++++++++++++-- spec/classes/heat_init_spec.rb | 2 +- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/examples/site.pp b/examples/site.pp index 0e2b79c4..2a0f902c 100644 --- a/examples/site.pp +++ b/examples/site.pp @@ -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 diff --git a/manifests/db.pp b/manifests/db.pp index 87837ae6..2a4ea7a4 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -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:: if heat::db:: 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 diff --git a/manifests/params.pp b/manifests/params.pp index d8b4830e..1133d68b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' diff --git a/spec/acceptance/basic_heat_spec.rb b/spec/acceptance/basic_heat_spec.rb index 81ca93dd..9021f294 100644 --- a/spec/acceptance/basic_heat_spec.rb +++ b/spec/acceptance/basic_heat_spec.rb @@ -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, diff --git a/spec/classes/heat_db_spec.rb b/spec/classes/heat_db_spec.rb index de977df2..20d9e1da 100644 --- a/spec/classes/heat_db_spec.rb +++ b/spec/classes/heat_db_spec.rb @@ -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 diff --git a/spec/classes/heat_init_spec.rb b/spec/classes/heat_init_spec.rb index 9d39c731..d171bff4 100644 --- a/spec/classes/heat_init_spec.rb +++ b/spec/classes/heat_init_spec.rb @@ -14,7 +14,7 @@ describe 'heat' do :rabbit_userid => '', :rabbit_password => '', :rabbit_virtual_host => '', - :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',