diff --git a/manifests/db.pp b/manifests/db.pp index 4dfa59f..c19c02c 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -43,6 +43,8 @@ class murano::db ( $database_max_overflow = $::os_service_default, ) { + include ::murano::params + # NOTE(aderyugin): In order to keep backward compatibility we rely on the pick function # to use murano:: if murano::db:: isn't specified. $database_connection_real = pick($::murano::database_connection, $database_connection) @@ -53,13 +55,17 @@ class murano::db ( $database_retry_interval_real = pick($::murano::database_retry_interval, $database_retry_interval) $database_max_overflow_real = pick($::murano::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 = $::murano::params::pymysql_package_name + } else { + $backend_package = false + } } /^postgresql:\/\//: { $backend_package = false diff --git a/manifests/params.pp b/manifests/params.pp index 0095a42..454983d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -21,6 +21,7 @@ class murano::params { $engine_service_name = 'murano-engine' # dashboard config file $local_settings_path = '/etc/openstack-dashboard/local_settings' + $pymysql_package_name = undef } 'Debian': { # package names @@ -36,6 +37,7 @@ class murano::params { $engine_service_name = 'murano-engine' # dashboard config file $local_settings_path = '/etc/openstack-dashboard/local_settings.py' + $pymysql_package_name = 'python-pymysql' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}") diff --git a/spec/acceptance/basic_murano_spec.rb b/spec/acceptance/basic_murano_spec.rb index 517b73b..cad3ec5 100644 --- a/spec/acceptance/basic_murano_spec.rb +++ b/spec/acceptance/basic_murano_spec.rb @@ -51,7 +51,7 @@ describe 'basic murano' do rabbit_own_user => 'murano', rabbit_own_password => 'an_even_bigger_secret', rabbit_own_vhost => '/murano', - database_connection => 'mysql://murano:a_big_secret@127.0.0.1/murano?charset=utf8', + database_connection => 'mysql+pymysql://murano:a_big_secret@127.0.0.1/murano?charset=utf8', } class { '::murano::api': } class { '::murano::engine': } diff --git a/spec/classes/murano_db_spec.rb b/spec/classes/murano_db_spec.rb index 0580881..81f339a 100644 --- a/spec/classes/murano_db_spec.rb +++ b/spec/classes/murano_db_spec.rb @@ -15,7 +15,7 @@ describe 'murano::db' do context 'with specific parameters' do let :params do - { :database_connection => 'mysql://murano:murano@localhost/murano', + { :database_connection => 'mysql+pymysql://murano:murano@localhost/murano', :database_idle_timeout => '3601', :database_min_pool_size => '2', :database_max_retries => '11', @@ -25,7 +25,7 @@ describe 'murano::db' do } end - it { is_expected.to contain_murano_config('database/connection').with_value('mysql://murano:murano@localhost/murano') } + it { is_expected.to contain_murano_config('database/connection').with_value('mysql+pymysql://murano:murano@localhost/murano') } it { is_expected.to contain_murano_config('database/idle_timeout').with_value('3601') } it { is_expected.to contain_murano_config('database/min_pool_size').with_value('2') } it { is_expected.to contain_murano_config('database/max_retries').with_value('11') } @@ -45,6 +45,14 @@ describe 'murano::db' do end + context 'with MySQL-python library as backend package' do + let :params do + { :database_connection => 'mysql://murano:murano@localhost/murano', } + 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 => 'sqlite://murano:murano@localhost/murano', } @@ -52,6 +60,14 @@ describe 'murano::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://murano:murano@localhost/murano', } + end + + it_raises 'a Puppet::Error', /validate_re/ + end end context 'on Debian platforms' do @@ -63,6 +79,20 @@ describe 'murano::db' do end it_configures 'murano::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://murano:murano@localhost/murano', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('murano-backend-package').with( + :ensure => 'present', + :name => 'python-pymysql', + :tag => 'openstack' + ) + end + end end context 'on Redhat platforms' do @@ -73,6 +103,14 @@ describe 'murano::db' do end it_configures 'murano::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://murano:murano@localhost/murano', } + end + + it { is_expected.not_to contain_package('murano-backend-package') } + end end end