Update to latest mariadb cookbook

This updates us to a new resource driven mariadb cookbook which
simplifies how we manage mysql. Other changes:

- Update to using MariaDB 10.3 instead of 10.1 as we need this for Stein
- Update attributes so they work better with the
  mariadb_server_configuration resource
- Remove use of the mysql2_chef_gem cookbook as it's no longer needed
  and causes issues with newer versions of MariaDB and MySQL.
- Remove use of the openstack.cnf template since we can add all
  configuration using the mariadb_server_configuration resource
- Remove RHEL mariadb-server ChefSpec as it's not needed
- Update openstack-db recipe to use the openstack_database resource
  instead of the openstack_common_database resource which was renamed

Depends-On: https://review.opendev.org/710351
Change-Id: Ia5b401cafcdf57aa84e090c745bd3e517c7251bf
This commit is contained in:
Lance Albertson 2020-02-27 16:06:37 -08:00
parent ceccaadf8a
commit 8747a1cf96
12 changed files with 130 additions and 144 deletions

View File

@ -23,24 +23,26 @@ default['openstack']['mysql']['data_dir'] = nil
# MySQL attributes that we select defaults for:
# Version, support 5.7 and above
# Mysql version, support 5.7 and above
default['openstack']['mysql']['version'] = '5.7'
# MariaDB version
default['openstack']['mariadb']['version'] = '10.3'
# Service name
default['openstack']['mysql']['service_name'] = 'default'
# Storage engine, base OpenStack requires the InnoDB flavor
default['openstack']['mysql']['default-storage-engine'] = 'InnoDB'
# InnoDB lock mode for generating auto-increment values
default['openstack']['mysql']['innodb_autoinc_lock_mode'] = '1'
default['openstack']['mysql']['innodb_autoinc_lock_mode'] = 1
# InnoDB give each table its own file
default['openstack']['mysql']['innodb_file_per_table'] = 'OFF'
default['openstack']['mysql']['innodb_file_per_table'] = 0
# InnoDB thread concurrency
default['openstack']['mysql']['innodb_thread_concurrency'] = '0'
default['openstack']['mysql']['innodb_thread_concurrency'] = 0
# InnoDB commit concurrency
default['openstack']['mysql']['innodb_commit_concurrency'] = '0'
default['openstack']['mysql']['innodb_commit_concurrency'] = 0
# InnoDB number of read io threads
default['openstack']['mysql']['innodb_read_io_threads'] = '4'
default['openstack']['mysql']['innodb_read_io_threads'] = 4
# InnoDB number of commit transactions to flush log
default['openstack']['mysql']['innodb_flush_log_at_trx_commit'] = '1'
default['openstack']['mysql']['innodb_flush_log_at_trx_commit'] = 1
# InnoDB memory buffer for caching table data and indexes
default['openstack']['mysql']['innodb_buffer_pool_size'] = '134217728'
# InnoDB size of each log file in a log group
@ -54,4 +56,4 @@ default['openstack']['mysql']['character-set-server'] = 'latin1'
# Memory allocated for caching query results
default['openstack']['mysql']['query_cache_size'] = '0'
# Maximum number of connections
default['openstack']['mysql']['max_connections'] = '307'
default['openstack']['mysql']['max_connections'] = 307

View File

@ -21,9 +21,8 @@ end
depends 'openstack-common', '>= 18.0.0'
depends 'mariadb', '~> 1.5'
depends 'mariadb', '~> 3.1'
depends 'mysql', '~> 8.6'
depends 'mysql2_chef_gem', '~> 2.0'
issues_url 'https://launchpad.net/openstack-chef'
source_url 'https://opendev.org/openstack/cookbook-openstack-ops-database'

View File

@ -15,13 +15,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
mariadb_repository 'default' do
version node['openstack']['mariadb']['version']
end
node.normal['mariadb']['use_default_repository'] = true
include_recipe 'mariadb::client'
mysql2_chef_gem_mariadb 'default' do
gem_version '0.4.9'
action :install
mariadb_client_install 'default' do
version node['openstack']['mariadb']['version']
end
node['openstack']['db']['python_packages']['mariadb'].each do |pkg|

View File

@ -22,37 +22,65 @@ end
bind_db = node['openstack']['bind_service']['db']
listen_address = if bind_db['interface']
address_for bind_db['interface']
else
bind_db['host']
end
listen_address =
if bind_db['interface']
address_for bind_db['interface']
else
bind_db['host']
end
super_password = get_password 'db', node['openstack']['db']['root_user_key']
node.normal['mariadb']['remove_test_database'] = true
node.normal['mariadb']['allow_root_pass_change'] = true
node.normal['mariadb']['server_root_password'] = super_password
node.normal['mariadb']['mysqld']['bind_address'] = listen_address
# increase the default from 5 seconds to allow extra time for services to warm up
node.normal['mariadb']['connect_timeout'] = 30
unless listen_address == '127.0.0.1' || listen_address == 'localhost'
node.normal['mariadb']['forbid_remote_root'] = false
end
include_recipe 'openstack-ops-database::mariadb-client'
# reuse mysql configuration for mariadb
node.normal['mariadb']['mysqld']['default_storage_engine'] = node['openstack']['mysql']['default-storage-engine']
node.normal['mariadb']['mysqld']['max_connections'] = node['openstack']['mysql']['max_connections']
include_recipe 'mariadb::server'
# reuse mysql configuration file for mariadb
template "#{node['mariadb']['configuration']['includedir']}/openstack.cnf" do
owner 'mysql'
group 'mysql'
source 'openstack.cnf.erb'
notifies :restart, 'service[mysql]'
mariadb_server_install 'default' do
version node['openstack']['mariadb']['version']
password super_password
action [:install, :create]
end
# Using this to generate a service resource to control
service 'mysql' do
supports restart: true, status: true, reload: true
action :nothing
end
mariadb_server_configuration 'default' do
innodb_buffer_pool_size node['openstack']['mysql']['innodb_buffer_pool_size']
innodb_file_per_table node['openstack']['mysql']['innodb_file_per_table']
innodb_log_buffer_size node['openstack']['mysql']['innodb_log_buffer_size']
innodb_log_file_size node['openstack']['mysql']['innodb_log_file_size']
innodb_options(
innodb_autoinc_lock_mode: node['openstack']['mysql']['innodb_autoinc_lock_mode'],
innodb_thread_concurrency: node['openstack']['mysql']['innodb_thread_concurrency'],
innodb_commit_concurrency: node['openstack']['mysql']['innodb_commit_concurrency'],
innodb_read_io_threads: node['openstack']['mysql']['innodb_read_io_threads'],
innodb_flush_log_at_trx_commit: node['openstack']['mysql']['innodb_flush_log_at_trx_commit']
)
mysqld_bind_address listen_address
# increase the default from 5 seconds to allow extra time for services to warm up
mysqld_connect_timeout 30
mysqld_default_storage_engine node['openstack']['mysql']['default-storage-engine']
mysqld_max_connections node['openstack']['mysql']['max_connections']
mysqld_query_cache_size node['openstack']['mysql']['query_cache_size']
mysqld_skip_name_resolve node['openstack']['mysql']['skip-name-resolve']
mysqld_options(
'character-set-server' => node['openstack']['mysql']['character-set-server']
)
version node['openstack']['mariadb']['version']
notifies :restart, 'service[mysql]', :immediately
end
# Remove anonymous localhost user
mariadb_user 'anonymous' do
username ''
host 'localhost'
ctrl_password super_password
action :drop
end
# Remove test database
mariadb_database 'test' do
password super_password
action :drop
end

View File

@ -33,11 +33,6 @@ when 'rhel'
package 'mariadb-devel'
end
mysql2_chef_gem 'default' do
gem_version '0.4.5'
action :install
end
node['openstack']['db']['python_packages']['mysql'].each do |pkg|
package pkg
end

View File

@ -29,7 +29,7 @@ node['openstack']['common']['services'].each do |service, project|
begin
username = node['openstack']['db'][service]['username']
password = get_password('db', project)
openstack_common_database service do
openstack_database service do
user username
pass password
end

View File

@ -14,12 +14,12 @@ describe 'openstack-ops-database::mariadb-client' do
runner.converge(described_recipe)
end
it 'includes mariadb client recipes' do
expect(chef_run).to include_recipe('mariadb::client')
it do
expect(chef_run).to add_mariadb_repository('default').with(version: '10.3')
end
it do
expect(chef_run).to install_mysql2_chef_gem_mariadb('default').with(gem_version: '0.4.9')
expect(chef_run).to install_mariadb_client_install('default').with(version: '10.3')
end
it 'installs mariadb python client packages' do

View File

@ -1,40 +0,0 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-ops-database::mariadb-server' do
describe 'redhat' do
include_context 'database-stubs'
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) { runner.node }
cached(:chef_run) do
node.override['mariadb']['install']['version'] = '5.7'
runner.converge(described_recipe)
end
let(:file) { chef_run.template('/etc/my.cnf.d/openstack.cnf') }
it 'creates template /etc/my.cnf.d/openstack.cnf' do
expect(chef_run).to create_template(file.name).with(
user: 'mysql',
group: 'mysql',
source: 'openstack.cnf.erb'
)
expect(file).to notify('service[mysql]')
[/^default-storage-engine = InnoDB$/,
/^innodb_autoinc_lock_mode = 1$/,
/^innodb_file_per_table = OFF$/,
/^innodb_thread_concurrency = 0$/,
/^innodb_commit_concurrency = 0$/,
/^innodb_read_io_threads = 4$/,
/^innodb_flush_log_at_trx_commit = 1$/,
/^innodb_buffer_pool_size = 134217728$/,
/^innodb_log_file_size = 5242880$/,
/^innodb_log_buffer_size = 8388608$/,
/^character-set-server = latin1$/,
/^query_cache_size = 0$/,
/^max_connections = 307$/].each do |line|
expect(chef_run).to render_config_file(file.name).with_section_content('mysqld', line)
end
end
end
end

View File

@ -8,52 +8,62 @@ describe 'openstack-ops-database::mariadb-server' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
cached(:chef_run) { runner.converge(described_recipe) }
let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') }
it 'overrides mariadb default attributes' do
expect(chef_run.node['mariadb']['mysqld']['bind_address']).to eq '127.0.0.1'
expect(chef_run.node['mariadb']['mysqld']['default_storage_engine']).to eq 'InnoDB'
expect(chef_run.node['mariadb']['mysqld']['max_connections']).to eq '307'
expect(chef_run.node['mariadb']['forbid_remote_root']).to be true
expect(chef_run.node['mariadb']['remove_anonymous_users']).to be true
expect(chef_run.node['mariadb']['remove_test_database']).to be true
end
it 'includes mariadb recipes' do
expect(chef_run).to include_recipe('openstack-ops-database::mariadb-client')
expect(chef_run).to include_recipe('mariadb::server')
end
it 'creates template /etc/mysql/conf.d/openstack.cnf' do
node.override['mariadb']['install']['version'] = '10.1'
expect(chef_run).to create_template(file.name).with(
user: 'mysql',
group: 'mysql',
source: 'openstack.cnf.erb'
it do
expect(chef_run).to install_mariadb_server_install('default').with(
version: '10.3',
password: 'abc123'
)
expect(file).to notify('service[mysql]')
[/^default-storage-engine = InnoDB$/,
/^innodb_autoinc_lock_mode = 1$/,
/^innodb_file_per_table = OFF$/,
/^innodb_thread_concurrency = 0$/,
/^innodb_commit_concurrency = 0$/,
/^innodb_read_io_threads = 4$/,
/^innodb_flush_log_at_trx_commit = 1$/,
/^innodb_buffer_pool_size = 134217728$/,
/^innodb_log_file_size = 5242880$/,
/^innodb_log_buffer_size = 8388608$/,
/^character-set-server = latin1$/,
/^query_cache_size = 0$/,
/^max_connections = 307$/].each do |line|
expect(chef_run).to render_config_file(file.name)\
.with_section_content('mysqld', line)
end
end
it 'creates mariadb with root password' do
# Password is fixed as 'abc123' by spec_helper
expect(chef_run.node['mariadb']['allow_root_pass_change']).to be true
expect(chef_run.node['mariadb']['server_root_password']).to eq 'abc123'
it do
expect(chef_run).to create_mariadb_server_install('default')
end
it do
expect(chef_run).to modify_mariadb_server_configuration('default').with(
innodb_buffer_pool_size: '134217728',
innodb_file_per_table: 0,
innodb_log_buffer_size: '8388608',
innodb_log_file_size: '5242880',
innodb_options: {
innodb_autoinc_lock_mode: 1,
innodb_thread_concurrency: 0,
innodb_commit_concurrency: 0,
innodb_read_io_threads: 4,
innodb_flush_log_at_trx_commit: 1,
},
mysqld_bind_address: '127.0.0.1',
mysqld_connect_timeout: 30,
mysqld_default_storage_engine: 'InnoDB',
mysqld_max_connections: 307,
mysqld_query_cache_size: '0',
mysqld_skip_name_resolve: false,
mysqld_options: {
'character-set-server' => 'latin1',
},
version: '10.3'
)
end
it do
expect(chef_run.mariadb_server_configuration('default')).to notify('service[mysql]').to(:restart).immediately
end
it do
expect(chef_run).to drop_mariadb_user('anonymous').with(
username: '',
host: 'localhost',
ctrl_password: 'abc123'
)
end
it do
expect(chef_run).to drop_mariadb_database('test').with(password: 'abc123')
end
context 'set db host to 192.168.1.1' do
@ -61,8 +71,10 @@ describe 'openstack-ops-database::mariadb-server' do
node.override['openstack']['bind_service']['db']['host'] = '192.168.1.1'
runner.converge(described_recipe)
end
it 'allow root remote access' do
expect(chef_run.node['mariadb']['forbid_remote_root']).to be false
it do
expect(chef_run).to modify_mariadb_server_configuration('default').with(
mysqld_bind_address: '192.168.1.1'
)
end
end
end

View File

@ -13,10 +13,6 @@ describe 'openstack-ops-database::mysql-client' do
expect(chef_run).to create_mysql_client 'default'
end
it 'has default mysql chef gem resource' do
expect(chef_run).to install_mysql2_chef_gem('default').with(gem_version: '0.4.5')
end
it 'installs mysql packages' do
expect(chef_run).to install_package 'MySQL-python'
expect(chef_run).to install_package 'mariadb-devel'

View File

@ -13,10 +13,6 @@ describe 'openstack-ops-database::mysql-client' do
expect(chef_run).to create_mysql_client 'default'
end
it 'has default mysql chef gem resource' do
expect(chef_run).to install_mysql2_chef_gem('default').with(gem_version: '0.4.5')
end
it 'installs mysql packages' do
expect(chef_run).to install_package 'python3-mysqldb'
expect(chef_run).to install_package 'libmysqlclient-dev'

View File

@ -20,9 +20,8 @@ describe 'openstack-ops-database::openstack-db' do
'orchestration' => 'heat',
'telemetry' => 'ceilometer',
}.each do |service, _project|
expect(chef_run).to create_openstack_common_database(service)
.with(user: node['openstack']['db'][service]['username'],
pass: 'test-pass')
expect(chef_run).to create_openstack_database(service)
.with(user: node['openstack']['db'][service]['username'], pass: 'test-pass')
end
## TODO: utilize _project and create test for rescue with specific log message
## when databag does not exist