diff --git a/CHANGELOG.md b/CHANGELOG.md index a57ca32..4738d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ openstack-ops-database Cookbook CHANGELG =================================== This file is used to list changes made in each version of the openstack-ops-database cookbook. +## 9.2.0 +* Update database and mysql dependency + ## 9.1.0 * python_packages database client attributes have been migrated to the -common cookbook diff --git a/attributes/default.rb b/attributes/default.rb index 31b0ab0..52e1c65 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -17,3 +17,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +# Set to some text value if you want templated config files +# to contain a custom banner at the top of the written file +default['openstack']['db']['custom_template_banner'] = ' +# This file autogenerated by Chef +# Do not edit, changes will be overwritten +' diff --git a/metadata.rb b/metadata.rb index f669e2a..701e423 100644 --- a/metadata.rb +++ b/metadata.rb @@ -3,7 +3,7 @@ maintainer 'Opscode, Inc.' maintainer_email 'matt@opscode.com' license 'Apache 2.0' description 'Provides the shared database configuration for Chef for OpenStack.' -version '9.1.0' +version '9.2.0' recipe 'client', 'Installs client packages for the database used by the deployment.' recipe 'server', 'Installs and configures server packages for the database used by the deployment.' @@ -17,7 +17,8 @@ recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStac supports os end -depends 'mysql', '~> 4.1' +depends 'mysql', '~> 5.3' +depends 'mysql-chef_gem', '~> 0.0.2' depends 'postgresql', '~> 3.3' -depends 'database', '~> 2.0' +depends 'database', '~> 2.2' depends 'openstack-common', '~> 9.5' diff --git a/recipes/mysql-client.rb b/recipes/mysql-client.rb index 21b5938..ecda94d 100644 --- a/recipes/mysql-client.rb +++ b/recipes/mysql-client.rb @@ -20,8 +20,8 @@ # limitations under the License. # -include_recipe 'mysql::ruby' include_recipe 'mysql::client' +include_recipe 'mysql-chef_gem' node['openstack']['db']['python_packages']['mysql'].each do |pkg| package pkg diff --git a/recipes/mysql-server.rb b/recipes/mysql-server.rb index 840f8d0..54d28f9 100644 --- a/recipes/mysql-server.rb +++ b/recipes/mysql-server.rb @@ -22,38 +22,40 @@ class ::Chef::Recipe # rubocop:disable Documentation include ::Openstack + include ::Opscode::Mysql::Helpers end db_endpoint = endpoint 'db' +if node['openstack']['db']['root_user_use_databag'] + super_password = get_password 'user', node['openstack']['db']['root_user_key'] + node.set_unless['mysql']['server_root_password'] = super_password +else + super_password = node['mysql']['server_root_password'] +end + +node.set['mysql']['version'] = default_version_for( + node['platform'], + node['platform_family'], + node['platform_version'] + ) +node.override['mysql']['tunable']['default-storage-engine'] = 'InnoDB' node.override['mysql']['bind_address'] = db_endpoint.host node.override['mysql']['tunable']['innodb_thread_concurrency'] = '0' node.override['mysql']['tunable']['innodb_commit_concurrency'] = '0' node.override['mysql']['tunable']['innodb_read_io_threads'] = '4' node.override['mysql']['tunable']['innodb_flush_log_at_trx_commit'] = '2' node.override['mysql']['tunable']['skip-name-resolve'] = true +node.override['mysql']['tunable']['character-set-server'] = 'utf8' include_recipe 'openstack-ops-database::mysql-client' include_recipe 'mysql::server' -# NOTE:(mancdaz) This is a temporary workaround for this upstream bug in the -# mysql cookbook. It can be removed once the upstream issue is resolved: -# -# https://tickets.opscode.com/browse/COOK-4161 -case node['platform_family'] -when 'debian' - mycnf_template = '/etc/mysql/my.cnf' -when 'rhel' - mycnf_template = 'final-my.cnf' -end - -r = resources("template[#{mycnf_template}]") -r.notifies_immediately(:restart, 'service[mysql]') - -if node['openstack']['db']['root_user_use_databag'] - super_password = get_password 'user', node['openstack']['db']['root_user_key'] -else - super_password = node['mysql']['server_root_password'] +template '/etc/mysql/conf.d/openstack.cnf' do + owner 'mysql' + group 'mysql' + source 'openstack.cnf.erb' + notifies :restart, 'mysql_service[default]' end mysql_connection_info = { diff --git a/spec/mysql-client_spec.rb b/spec/mysql-client_spec.rb index 53795d0..9f57760 100644 --- a/spec/mysql-client_spec.rb +++ b/spec/mysql-client_spec.rb @@ -9,11 +9,14 @@ describe 'openstack-ops-database::mysql-client' do let(:node) { runner.node } let(:chef_run) { runner.converge(described_recipe) } - it 'includes mysql recipes' do - expect(chef_run).to include_recipe 'mysql::ruby' + it 'includes mysql client recipes' do expect(chef_run).to include_recipe 'mysql::client' end + it 'includes mysql-chef_gem recipes' do + expect(chef_run).to include_recipe 'mysql-chef_gem::default' + end + it 'installs mysql packages' do expect(chef_run).to install_package 'python-mysqldb' end diff --git a/spec/mysql-server-redhat_spec.rb b/spec/mysql-server-redhat_spec.rb index 51406cb..a305b26 100644 --- a/spec/mysql-server-redhat_spec.rb +++ b/spec/mysql-server-redhat_spec.rb @@ -15,10 +15,32 @@ describe 'openstack-ops-database::mysql-server' do } runner.converge(described_recipe) end + let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') } - it 'modifies my.cnf template to notify mysql restart' do - file = chef_run.template('final-my.cnf') - expect(file).to notify('service[mysql]').to(:restart) + it 'sets mysql version to 5.1' do + expect(chef_run.node['mysql']['version']).to eql '5.1' end + + it 'creates template /etc/mysql/conf.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('mysql_service[default]') + [/^# This file autogenerated by Chef$/, + /^# Do not edit, changes will be overwritten$/, + /^\[mysqld\]$/, + /^default-storage-engine = InnoDB$/, + /^bind-address = 127.0.0.1$/, + /^innodb_thread_concurrency= 0$/, + /^innodb_commit_concurrency = 0$/, + /^innodb_flush_log_at_trx_commit = 2$/, + /^skip-name-resolve$/, + /^character-set-server = utf8$/].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) + end + end + end end diff --git a/spec/mysql-server_spec.rb b/spec/mysql-server_spec.rb index e236f7f..8cd2f4a 100644 --- a/spec/mysql-server_spec.rb +++ b/spec/mysql-server_spec.rb @@ -15,14 +15,21 @@ describe 'openstack-ops-database::mysql-server' do } runner.converge(described_recipe) end + let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') } + + it 'sets mysql version to 5.5' do + expect(chef_run.node['mysql']['version']).to eql '5.5' + end it 'overrides default mysql attributes' do + expect(chef_run.node['mysql']['tunable']['default-storage-engine']).to eql 'InnoDB' expect(chef_run.node['mysql']['bind_address']).to eql '127.0.0.1' expect(chef_run.node['mysql']['tunable']['innodb_thread_concurrency']).to eql '0' expect(chef_run.node['mysql']['tunable']['innodb_commit_concurrency']).to eql '0' expect(chef_run.node['mysql']['tunable']['innodb_read_io_threads']).to eql '4' expect(chef_run.node['mysql']['tunable']['innodb_flush_log_at_trx_commit']).to eql '2' expect(chef_run.node['mysql']['tunable']['skip-name-resolve']).to eql true + expect(chef_run.node['mysql']['tunable']['character-set-server']).to eql 'utf8' end it 'includes mysql recipes' do @@ -30,55 +37,34 @@ describe 'openstack-ops-database::mysql-server' do expect(chef_run).to include_recipe 'mysql::server' end - it 'modifies my.cnf template to notify mysql restart' do - file = chef_run.template '/etc/mysql/my.cnf' - expect(file).to notify('service[mysql]').to(:restart) - end - - describe 'lwrps' do - connection = { - host: 'localhost', - username: 'root', - password: 'server-root-password' - } - - it 'removes insecure default localhost mysql users' do - resource = chef_run.find_resource( - 'mysql_database', - 'drop empty localhost user' - ).to_hash - - expect(resource).to include( - sql: "DELETE FROM mysql.user WHERE User = '' OR Password = ''", - connection: connection, - action: [:query] - ) - end - - it 'drops the test database' do - resource = chef_run.find_resource( - 'mysql_database', - 'test' - ).to_hash - - expect(resource).to include( - connection: connection, - action: [:drop] - ) - end - - it 'flushes privileges' do - resource = chef_run.find_resource( - 'mysql_database', - 'FLUSH PRIVILEGES' - ).to_hash - - expect(resource).to include( - connection: connection, - sql: 'FLUSH PRIVILEGES', - action: [:query] - ) + it 'creates template /etc/mysql/conf.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('mysql_service[default]') + [/^# This file autogenerated by Chef$/, + /^# Do not edit, changes will be overwritten$/, + /^\[mysqld\]$/, + /^default-storage-engine = InnoDB$/, + /^bind-address = 127.0.0.1$/, + /^innodb_thread_concurrency= 0$/, + /^innodb_commit_concurrency = 0$/, + /^innodb_read_io_threads = 4$/, + /^innodb_flush_log_at_trx_commit = 2$/, + /^skip-name-resolve$/, + /^character-set-server = utf8$/].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) end end + + it 'prepares the database server' do + expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES') + expect(chef_run).to query_mysql_database('drop empty localhost user') + expect(chef_run).to drop_mysql_database('test') + expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES') + end + end end diff --git a/templates/default/openstack.cnf.erb b/templates/default/openstack.cnf.erb new file mode 100644 index 0000000..2891bd7 --- /dev/null +++ b/templates/default/openstack.cnf.erb @@ -0,0 +1,14 @@ +<%= node['openstack']['db']['custom_template_banner'] %> +[mysqld] +default-storage-engine = <%= node['mysql']['tunable']['default-storage-engine'] %> +bind-address = <%= node['mysql']['bind_address'] %> +innodb_thread_concurrency= <%= node['mysql']['tunable']['innodb_thread_concurrency'] %> +innodb_commit_concurrency = <%= node['mysql']['tunable']['innodb_commit_concurrency'] %> +<% if node["mysql"]["version"].to_f >= 5.5 %> +innodb_read_io_threads = <%= node['mysql']['tunable']['innodb_read_io_threads'] %> +<% end %> +innodb_flush_log_at_trx_commit = <%= node['mysql']['tunable']['innodb_flush_log_at_trx_commit'] %> +<% if node['mysql']['tunable']['skip-name-resolve'] %> +skip-name-resolve +<% end %> +character-set-server = <%= node['mysql']['tunable']['character-set-server'] %>