diff --git a/attributes/database.rb b/attributes/database.rb index 9cf918d4..5e60baed 100644 --- a/attributes/database.rb +++ b/attributes/database.rb @@ -79,10 +79,10 @@ default['openstack']['endpoints']['db']['bind_interface'] = nil # Default database attributes default['openstack']['db']['server_role'] = 'os-ops-database' -default['openstack']['db']['service_type'] = 'mysql' # Database charset during create database default['openstack']['db']['charset'] = { mysql: 'utf8', + mariadb: 'utf8', postgresql: nil, pgsql: nil, sqlite: nil, @@ -93,12 +93,30 @@ default['openstack']['db']['charset'] = { # Database connection options. Should include starting '?' default['openstack']['db']['options'] = { mysql: "?charset=#{node['openstack']['db']['charset']['mysql']}", + mariadb: "?charset=#{node['openstack']['db']['charset']['mariadb']}", postgresql: '', sqlite: '', db2: "?charset=#{node['openstack']['db']['charset']['db2']}", nosql: '' } +case node['platform_family'] +when 'rhel' + default['openstack']['db']['service_type'] = 'mariadb' + default['openstack']['db']['python_packages']['mysql'] = ['MySQL-python'] + default['openstack']['db']['python_packages']['mariadb'] = ['MySQL-python'] + default['openstack']['db']['python_packages']['db2'] = ['python-ibm-db', 'python-ibm-db-sa'] +when 'suse' + default['openstack']['db']['service_type'] = 'mysql' + default['openstack']['db']['python_packages']['mysql'] = ['python-mysql'] + default['openstack']['db']['python_packages']['mariadb'] = ['python-mysql'] +when 'debian' + default['openstack']['db']['service_type'] = 'mysql' + default['openstack']['db']['python_packages']['mysql'] = ['python-mysqldb'] + default['openstack']['db']['python_packages']['mariadb'] = ['python-mysqldb'] + default['openstack']['db']['python_packages']['db2'] = ['ibm-db', 'ibm-db-sa'] +end + # Database used by the OpenStack Compute (Nova) service default['openstack']['db']['compute']['service_type'] = node['openstack']['db']['service_type'] default['openstack']['db']['compute']['host'] = node['openstack']['endpoints']['db']['host'] @@ -213,13 +231,3 @@ default['openstack']['db']['python_packages'] = { postgresql: ['python-psycopg2'], sqlite: [] } -case node['platform_family'] -when 'rhel' - default['openstack']['db']['python_packages']['mysql'] = ['MySQL-python'] - default['openstack']['db']['python_packages']['db2'] = ['python-ibm-db', 'python-ibm-db-sa'] -when 'suse' - default['openstack']['db']['python_packages']['mysql'] = ['python-mysql'] -when 'debian' - default['openstack']['db']['python_packages']['mysql'] = ['python-mysqldb'] - default['openstack']['db']['python_packages']['db2'] = ['ibm-db', 'ibm-db-sa'] -end diff --git a/libraries/database.rb b/libraries/database.rb index 8e36f696..dfdd8ce2 100644 --- a/libraries/database.rb +++ b/libraries/database.rb @@ -43,7 +43,7 @@ module ::Openstack # rubocop:disable Documentation super_user = 'postgres' user_key = node['openstack']['db']['root_user_key'] super_password = get_password 'user', user_key - when 'mysql' + when 'mysql', 'mariadb' db_prov = ::Chef::Provider::Database::Mysql user_prov = ::Chef::Provider::Database::MysqlUser super_user = 'root' diff --git a/libraries/endpoints.rb b/libraries/endpoints.rb index 5e4a6809..b6c98363 100644 --- a/libraries/endpoints.rb +++ b/libraries/endpoints.rb @@ -73,6 +73,8 @@ module ::Openstack # rubocop:disable Documentation end when 'pgsql' type = 'postgresql' + when 'mariadb' + type = 'mysql' end # Build uri diff --git a/metadata.rb b/metadata.rb index b702d743..d01b03fb 100644 --- a/metadata.rb +++ b/metadata.rb @@ -18,6 +18,7 @@ end depends 'apt', '~> 2.6.1' depends 'database', '~> 4.0.2' +depends 'mariadb', '~> 0.3.0' depends 'mysql', '~> 6.0.13' depends 'yum', '~> 3.5.2' depends 'yum-epel', '~> 0.6.0' diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 6caabc56..5d615689 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -20,7 +20,7 @@ describe 'openstack-common::default' do end it 'returns db info and creates database with user when service found' do - ['mysql', 'pgsql', 'postgresql'].each do |db_type| + %w(mysql, mariadb, pgsql, postgresql).each do |db_type| encoding = node['openstack']['db']['charset'][db_type] if encoding.nil? allow(subject).to receive(:database).and_return({}) diff --git a/spec/endpoints_spec.rb b/spec/endpoints_spec.rb index f41b22f3..8d503af4 100644 --- a/spec/endpoints_spec.rb +++ b/spec/endpoints_spec.rb @@ -383,6 +383,15 @@ describe 'openstack-common::set_endpoints_by_interface' do subject.db_uri('telemetry', 'user', 'pass') ).to eq(expected) end + + it 'returns compute db info hash when service found for mariadb' do + node.set['openstack']['db']['service_type'] = 'mariadb' + allow(subject).to receive(:node).and_return(chef_run.node) + expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8' + expect( + subject.db_uri('compute', 'user', 'pass') + ).to eq(expected) + end end describe '#address' do