From baa3b76fcbb1ba1e3da845aea375b73a848f3635 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Thu, 12 Feb 2015 15:20:23 -0600 Subject: [PATCH] MySql cookbook ver 6 changes mysql cookbook is now provider driven, and no longer has default attributes, like server_root_password. For the password, now always using the Common password methods. For the other mysql attributes we used, these were moved into the attributes mysql.rb file. The attribute name space was changed from [mysql][**attr**] and [mysql][tunable][**attr**] to [openstack][mysql][**attr**] This patch requires updates to the database and mysql-chef-gem cookbooks.mysql cookbook ver 6 changes Change-Id: I05d27de80de0371503c5fa71591b4600bbeb2ca9 Implements: blueprint trusty-juno --- CHANGELOG.md | 3 + Gemfile | 2 +- README.md | 22 ++------ attributes/mysql.rb | 45 +++++++++++++++ metadata.rb | 12 ++-- recipes/mysql-client.rb | 9 ++- recipes/mysql-server.rb | 87 +++++------------------------ spec/mysql-client_spec.rb | 8 +-- spec/mysql-server-redhat_spec.rb | 46 --------------- spec/mysql-server_spec.rb | 68 ++++++---------------- spec/server_spec.rb | 9 +-- templates/default/openstack.cnf.erb | 19 +++---- 12 files changed, 109 insertions(+), 221 deletions(-) create mode 100644 attributes/mysql.rb mode change 100644 => 100755 metadata.rb delete mode 100644 spec/mysql-server-redhat_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aee25c..bf51771 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. +## 10.1.0 +* Updates for mysql cookbook ver 6.x + ## 10.0.0 * Upgrading to Juno * Upgrading berkshelf from 2.0.18 to 3.1.5 diff --git a/Gemfile b/Gemfile index c92916d..a2f6a7e 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,5 @@ gem 'berkshelf', '~> 3.1.5' gem 'hashie', '~> 2.0' gem 'chefspec', '~> 4.0.0' gem 'rspec', '~> 3.0.0' -gem 'foodcritic', '~> 3.0.3' +gem 'foodcritic', '~> 4.0' gem 'rubocop', '~> 0.18.1' diff --git a/README.md b/README.md index 25f72ed..fea2f27 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The following cookbooks are dependencies: * database * openstack-common * mysql -* mysql-chef_gem +* mysql2_chef_gem * postgresql # Usage # @@ -77,26 +77,12 @@ The following attributes are defined in attributes/database.rb of the common coo * `openstack["endpoints"]["db"]["port"]` - The port to bind the database service to * `openstack["endpoints"]["db"]["path"]` - Unused at this time * `openstack["endpoints"]["db"]["bind_interface"]` - The interface name to bind the database service to -* `openstack["db"]["root_user_use_databag"]` - Whether or not to retrieve the root-user password from a data bag; note that if this is set - to true, the mysql server_root_password attribute value will be ignored and will not reflect the password value, unless the attribute - value and the password retrieved from the data bag happen to be the same * `openstack["db"]["root_user_key"]` - The key used to retrieve the root user password; the key is both the name of the data-bag item and - name of the key containing the password value within the data-bag item -* `openstack["openstack"]["secret"]["user_passwords_data_bag"]` - The name of the data bag used to store the root user password + name of the key containing the password value within the data-bag item. This is defined in Common. If the value of the "bind_interface" attribute is non-nil, then the database service will be bound to the first IP address on that interface. If the value of the "bind_interface" attribute is nil, then the database service will be bound to the IP address specified in the host attribute. -The following mysql specific attributes are available: - -* `['mysql']['tunable']['default-storage-engine']` -* `['mysql']['bind_address']` -* `['mysql']['tunable']['innodb_thread_concurrency']` -* `['mysql']['tunable']['innodb_commit_concurrency']` -* `['mysql']['tunable']['innodb_read_io_threads']` -* `['mysql']['tunable']['innodb_flush_log_at_trx_commit']` -* `['mysql']['tunable']['skip-name-resolve']` -* `['mysql']['tunable']['character-set-server']` -* `['mysql']['tunable']['max_connections']` +See the attributes mysql.rb file for the mysql specific attributes that are available. For more information see: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html @@ -138,7 +124,7 @@ License and Author | **Copyright** | Copyright (c) 2012-2013, Opscode, Inc. | | **Copyright** | Copyright (c) 2013, AT&T Services, Inc. | | **Copyright** | Copyright (c) 2013-2014, SUSE Linux GmbH | -| **Copyright** | Copyright (c) 2014, IBM, Corp. | +| **Copyright** | Copyright (c) 2014-2015, IBM, Corp. | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/attributes/mysql.rb b/attributes/mysql.rb new file mode 100644 index 0000000..9343800 --- /dev/null +++ b/attributes/mysql.rb @@ -0,0 +1,45 @@ +# encoding: UTF-8# +# +# Cookbook Name:: openstack-ops-database +# Recipe:: default +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# MySql attributes that we use the mysql cookbook defaults: + +# Data directory +default['openstack']['mysql']['data_dir'] = nil + +# MySql attributes that we select defaults for: + +# Version, support 5.5 and above +default['openstack']['mysql']['version'] = '5.5' +# Service name +default['openstack']['mysql']['service_name'] = 'default' +# Storage engine, base OpenStack requires the InnoDB flavor +default['openstack']['mysql']['default-storage-engine'] = 'InnoDB' +# InnoDB thread concurrency +default['openstack']['mysql']['innodb_thread_concurrency'] = '0' +# InnoDB commit concurrency +default['openstack']['mysql']['innodb_commit_concurrency'] = '0' +# InnoDB number of read io threads +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'] = '2' +# Skip name resolution +default['openstack']['mysql']['skip-name-resolve'] = true +# Character set +default['openstack']['mysql']['character-set-server'] = 'utf8' +# Maximum number of connections +default['openstack']['mysql']['max_connections'] = '1024' diff --git a/metadata.rb b/metadata.rb old mode 100644 new mode 100755 index 944884c..d1792c8 --- a/metadata.rb +++ b/metadata.rb @@ -3,7 +3,7 @@ maintainer 'openstack-chef' maintainer_email 'opscode-chef-openstack@googlegroups.com' license 'Apache 2.0' description 'Provides the shared database configuration for Chef for OpenStack.' -version '10.0.0' +version '10.1.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,8 +17,8 @@ recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStac supports os end -depends 'mysql', '~> 5.4' -depends 'mysql-chef_gem', '~> 0.0.2' -depends 'postgresql', '~> 3.3' -depends 'database', '~> 2.2' -depends 'openstack-common', '>= 10.0.0' +depends 'mysql', '>= 6.0.13', '< 7.0.0' +depends 'mysql2_chef_gem', '>= 1.0.1', '< 2.0.0' +depends 'postgresql', '>= 3.3.0', '< 4.0.0' +depends 'database', '>= 4.0.2', '< 5.0.0' +depends 'openstack-common', '>= 10.3.0' diff --git a/recipes/mysql-client.rb b/recipes/mysql-client.rb index ecda94d..59ea656 100644 --- a/recipes/mysql-client.rb +++ b/recipes/mysql-client.rb @@ -20,8 +20,13 @@ # limitations under the License. # -include_recipe 'mysql::client' -include_recipe 'mysql-chef_gem' +mysql_client 'default' do + action :create +end + +mysql2_chef_gem 'default' do + action :install +end node['openstack']['db']['python_packages']['mysql'].each do |pkg| package pkg diff --git a/recipes/mysql-server.rb b/recipes/mysql-server.rb index 4a28b80..d363f31 100644 --- a/recipes/mysql-server.rb +++ b/recipes/mysql-server.rb @@ -22,86 +22,25 @@ 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'] -else - super_password = node['mysql']['server_root_password'] -end - -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' -node.override['mysql']['tunable']['max_connections'] = '1024' +super_password = get_password 'user', node['openstack']['db']['root_user_key'] include_recipe 'openstack-ops-database::mysql-client' -mysql_service node['mysql']['service_name'] do - version node['mysql']['version'] - port node['mysql']['port'] - data_dir node['mysql']['data_dir'] - server_root_password super_password - server_debian_password node['mysql']['server_debian_password'] - server_repl_password node['mysql']['server_repl_password'] - allow_remote_root node['mysql']['allow_remote_root'] - remove_anonymous_users node['mysql']['remove_anonymous_users'] - remove_test_database node['mysql']['remove_test_database'] - root_network_acl node['mysql']['root_network_acl'] +mysql_service node['openstack']['mysql']['service_name'] do + version node['openstack']['mysql']['version'] + data_dir node['openstack']['mysql']['data_dir'] if node['openstack']['mysql']['data_dir'] + initial_root_password super_password + bind_address db_endpoint.host + port db_endpoint.port.to_s + action [:create, :start] +end + +mysql_config 'openstack' do + source 'openstack.cnf.erb' + notifies :restart, "mysql_service[#{node['openstack']['mysql']['service_name']}]" action :create end - -# Set the version attribute based on what was actually -# installed. -server_resource = resources("mysql_service[#{node['mysql']['service_name']}]") -server_version = server_resource.parsed_version -node.set['mysql']['version'] = server_version - -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 = { - host: 'localhost', - username: 'root', - password: super_password -} - -mysql_database 'FLUSH PRIVILEGES pre query' do - connection mysql_connection_info - sql 'FLUSH PRIVILEGES' - action :query -end - -# Unfortunately, this is needed to get around a MySQL bug -# that repeatedly shows its face when running this in Vagabond -# containers: -# -# http://bugs.mysql.com/bug.php?id=69644 -mysql_database 'drop empty localhost user' do - sql "DELETE FROM mysql.user WHERE User = '' OR Password = ''" - connection mysql_connection_info - action :query -end - -mysql_database 'test' do - connection mysql_connection_info - action :drop -end - -mysql_database 'FLUSH PRIVILEGES post query' do - connection mysql_connection_info - sql 'FLUSH PRIVILEGES' - action :query -end diff --git a/spec/mysql-client_spec.rb b/spec/mysql-client_spec.rb index 9f57760..85b8c90 100644 --- a/spec/mysql-client_spec.rb +++ b/spec/mysql-client_spec.rb @@ -9,12 +9,12 @@ describe 'openstack-ops-database::mysql-client' do let(:node) { runner.node } let(:chef_run) { runner.converge(described_recipe) } - it 'includes mysql client recipes' do - expect(chef_run).to include_recipe 'mysql::client' + it 'has default mysql client resource' do + expect(chef_run).to create_mysql_client 'default' end - it 'includes mysql-chef_gem recipes' do - expect(chef_run).to include_recipe 'mysql-chef_gem::default' + it 'has default mysql chef gem resource' do + expect(chef_run).to install_mysql2_chef_gem 'default' end it 'installs mysql packages' do diff --git a/spec/mysql-server-redhat_spec.rb b/spec/mysql-server-redhat_spec.rb deleted file mode 100644 index 04c4794..0000000 --- a/spec/mysql-server-redhat_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# encoding: UTF-8 - -require_relative 'spec_helper' - -describe 'openstack-ops-database::mysql-server' do - describe 'redhat' do - include_context 'database-stubs' - let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) } - let(:node) { runner.node } - let(:chef_run) do - node.set_unless['mysql'] = { - 'server_debian_password' => 'server-debian-password', - 'server_root_password' => 'server-root-password', - 'server_repl_password' => 'server-repl-password' - } - 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 '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 339ca5d..6eb11db 100644 --- a/spec/mysql-server_spec.rb +++ b/spec/mysql-server_spec.rb @@ -8,63 +8,29 @@ describe 'openstack-ops-database::mysql-server' do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:node) { runner.node } let(:chef_run) { runner.converge(described_recipe) } - 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' - expect(chef_run.node['mysql']['tunable']['max_connections']).to eql '1024' - end it 'includes mysql recipes' do expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client' 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_read_io_threads = 4$/, - /^innodb_flush_log_at_trx_commit = 2$/, - /^skip-name-resolve$/, - /^character-set-server = utf8$/, - /^max_connections = 1024$/].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 pre query') - 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 post query') - end - - it 'creates mysql service' do - node.set['openstack']['db']['root_user_use_databag'] = true - # Password is fixed as 'abc123' by spec_helper + it 'creates mysql default service' do expect(chef_run).to create_mysql_service('default').with( - server_root_password: 'abc123') + version: '5.5', + data_dir: nil, + initial_root_password: 'abc123', + bind_address: '127.0.0.1', + port: '3306', + action: [:create, :start] + ) + end + + it 'creates mysql openstack config and notifies server to restart' do + expect(chef_run).to create_mysql_config('openstack').with( + source: 'openstack.cnf.erb', + action: [:create] + ) + resource = chef_run.find_resource('mysql_config', 'openstack') + expect(resource).to notify('mysql_service[default]').to(:restart).delayed end end end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 33c84cb..a22f0d4 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -7,14 +7,7 @@ describe 'openstack-ops-database::server' do include_context 'database-stubs' let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) do - node.set_unless['mysql'] = { - 'server_debian_password' => 'server-debian-password', - 'server_root_password' => 'server-root-password', - 'server_repl_password' => 'server-repl-password' - } - runner.converge(described_recipe) - end + let(:chef_run) { runner.converge(described_recipe) } it 'uses mysql database server recipe by default' do expect(chef_run).to include_recipe('openstack-ops-database::mysql-server') diff --git a/templates/default/openstack.cnf.erb b/templates/default/openstack.cnf.erb index 19650fb..3251d68 100644 --- a/templates/default/openstack.cnf.erb +++ b/templates/default/openstack.cnf.erb @@ -1,15 +1,12 @@ <%= 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'] %> +default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %> +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'] %> +<% if node['openstack']['mysql']['skip-name-resolve'] %> skip-name-resolve <% end %> -character-set-server = <%= node['mysql']['tunable']['character-set-server'] %> -max_connections = <%= node['mysql']['tunable']['max_connections'] %> +character-set-server = <%= node['openstack']['mysql']['character-set-server'] %> +max_connections = <%= node['openstack']['mysql']['max_connections'] %>