diff --git a/manifests/db.pp b/manifests/db.pp index 328a668..5980758 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -52,13 +52,19 @@ class vitrage::db ( $database_max_overflow_real = pick($::vitrage::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+)?') + + include ::vitrage::params 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 = $::vitrage::params::pymysql_package_name + } else { + $backend_package = false + } } /^postgresql:\/\//: { $backend_package = false diff --git a/manifests/params.pp b/manifests/params.pp index c092897..b953068 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,9 +5,11 @@ class vitrage::params { case $::osfamily { 'RedHat': { $sqlite_package_name = undef + $pymysql_package_name = undef } 'Debian': { $sqlite_package_name = 'python-pysqlite2' + $pymysql_package_name = 'python-pymysql' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem") diff --git a/spec/classes/vitrage_db_spec.rb b/spec/classes/vitrage_db_spec.rb index f4c3cc4..edd9484 100644 --- a/spec/classes/vitrage_db_spec.rb +++ b/spec/classes/vitrage_db_spec.rb @@ -15,7 +15,7 @@ describe 'vitrage::db' do context 'with specific parameters' do let :params do - { :database_connection => 'mysql://vitrage:vitrage@localhost/vitrage', + { :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage', :database_idle_timeout => '3601', :database_min_pool_size => '2', :database_max_retries => '11', @@ -25,7 +25,7 @@ describe 'vitrage::db' do } end - it { is_expected.to contain_vitrage_config('database/connection').with_value('mysql://vitrage:vitrage@localhost/vitrage') } + it { is_expected.to contain_vitrage_config('database/connection').with_value('mysql+pymysql://vitrage:vitrage@localhost/vitrage') } it { is_expected.to contain_vitrage_config('database/idle_timeout').with_value('3601') } it { is_expected.to contain_vitrage_config('database/min_pool_size').with_value('2') } it { is_expected.to contain_vitrage_config('database/max_retries').with_value('11') } @@ -45,12 +45,26 @@ describe 'vitrage::db' do end + context 'with MySQL-python library as backend package' do + let :params do + { :database_connection => 'mysql://vitrage:vitrage@localhost/vitrage', } + 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 => 'redis://vitrage:vitrage@localhost/vitrage', } end + it_raises 'a Puppet::Error', /validate_re/ + end + context 'with incorrect pymysql database_connection string' do + let :params do + { :database_connection => 'foo+pymysql://vitrage:vitrage@localhost/vitrage', } + end it_raises 'a Puppet::Error', /validate_re/ end @@ -66,6 +80,20 @@ describe 'vitrage::db' do end it_configures 'vitrage::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('vitrage-backend-package').with( + :ensure => 'present', + :name => 'python-pymysql', + :tag => 'openstack' + ) + end + end end context 'on Redhat platforms' do @@ -77,6 +105,14 @@ describe 'vitrage::db' do end it_configures 'vitrage::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://vitrage:vitrage@localhost/vitrage', } + end + + it { is_expected.not_to contain_package('vitrage-backend-package') } + end end end