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
This commit is contained in:
Mark Vanderwiel 2015-02-12 15:20:23 -06:00
parent aa7e4fbdcd
commit baa3b76fcb
12 changed files with 109 additions and 221 deletions

View File

@ -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. 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 ## 10.0.0
* Upgrading to Juno * Upgrading to Juno
* Upgrading berkshelf from 2.0.18 to 3.1.5 * Upgrading berkshelf from 2.0.18 to 3.1.5

View File

@ -6,5 +6,5 @@ gem 'berkshelf', '~> 3.1.5'
gem 'hashie', '~> 2.0' gem 'hashie', '~> 2.0'
gem 'chefspec', '~> 4.0.0' gem 'chefspec', '~> 4.0.0'
gem 'rspec', '~> 3.0.0' gem 'rspec', '~> 3.0.0'
gem 'foodcritic', '~> 3.0.3' gem 'foodcritic', '~> 4.0'
gem 'rubocop', '~> 0.18.1' gem 'rubocop', '~> 0.18.1'

View File

@ -19,7 +19,7 @@ The following cookbooks are dependencies:
* database * database
* openstack-common * openstack-common
* mysql * mysql
* mysql-chef_gem * mysql2_chef_gem
* postgresql * postgresql
# Usage # # 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"]["port"]` - The port to bind the database service to
* `openstack["endpoints"]["db"]["path"]` - Unused at this time * `openstack["endpoints"]["db"]["path"]` - Unused at this time
* `openstack["endpoints"]["db"]["bind_interface"]` - The interface name to bind the database service to * `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 * `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 name of the key containing the password value within the data-bag item. This is defined in Common.
* `openstack["openstack"]["secret"]["user_passwords_data_bag"]` - The name of the data bag used to store the root user password
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. 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: See the attributes mysql.rb file for the mysql specific attributes that 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']`
For more information see: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html 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) 2012-2013, Opscode, Inc. |
| **Copyright** | Copyright (c) 2013, AT&T Services, Inc. | | **Copyright** | Copyright (c) 2013, AT&T Services, Inc. |
| **Copyright** | Copyright (c) 2013-2014, SUSE Linux GmbH | | **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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

45
attributes/mysql.rb Normal file
View File

@ -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'

12
metadata.rb Normal file → Executable file
View File

@ -3,7 +3,7 @@ maintainer 'openstack-chef'
maintainer_email 'opscode-chef-openstack@googlegroups.com' maintainer_email 'opscode-chef-openstack@googlegroups.com'
license 'Apache 2.0' license 'Apache 2.0'
description 'Provides the shared database configuration for Chef for OpenStack.' 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 '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.' 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 supports os
end end
depends 'mysql', '~> 5.4' depends 'mysql', '>= 6.0.13', '< 7.0.0'
depends 'mysql-chef_gem', '~> 0.0.2' depends 'mysql2_chef_gem', '>= 1.0.1', '< 2.0.0'
depends 'postgresql', '~> 3.3' depends 'postgresql', '>= 3.3.0', '< 4.0.0'
depends 'database', '~> 2.2' depends 'database', '>= 4.0.2', '< 5.0.0'
depends 'openstack-common', '>= 10.0.0' depends 'openstack-common', '>= 10.3.0'

View File

@ -20,8 +20,13 @@
# limitations under the License. # limitations under the License.
# #
include_recipe 'mysql::client' mysql_client 'default' do
include_recipe 'mysql-chef_gem' action :create
end
mysql2_chef_gem 'default' do
action :install
end
node['openstack']['db']['python_packages']['mysql'].each do |pkg| node['openstack']['db']['python_packages']['mysql'].each do |pkg|
package pkg package pkg

View File

@ -22,86 +22,25 @@
class ::Chef::Recipe # rubocop:disable Documentation class ::Chef::Recipe # rubocop:disable Documentation
include ::Openstack include ::Openstack
include ::Opscode::Mysql::Helpers
end end
db_endpoint = endpoint 'db' db_endpoint = endpoint 'db'
if node['openstack']['db']['root_user_use_databag'] super_password = get_password 'user', node['openstack']['db']['root_user_key']
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'
include_recipe 'openstack-ops-database::mysql-client' include_recipe 'openstack-ops-database::mysql-client'
mysql_service node['mysql']['service_name'] do mysql_service node['openstack']['mysql']['service_name'] do
version node['mysql']['version'] version node['openstack']['mysql']['version']
port node['mysql']['port'] data_dir node['openstack']['mysql']['data_dir'] if node['openstack']['mysql']['data_dir']
data_dir node['mysql']['data_dir'] initial_root_password super_password
server_root_password super_password bind_address db_endpoint.host
server_debian_password node['mysql']['server_debian_password'] port db_endpoint.port.to_s
server_repl_password node['mysql']['server_repl_password'] action [:create, :start]
allow_remote_root node['mysql']['allow_remote_root'] end
remove_anonymous_users node['mysql']['remove_anonymous_users']
remove_test_database node['mysql']['remove_test_database'] mysql_config 'openstack' do
root_network_acl node['mysql']['root_network_acl'] source 'openstack.cnf.erb'
notifies :restart, "mysql_service[#{node['openstack']['mysql']['service_name']}]"
action :create action :create
end 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

View File

@ -9,12 +9,12 @@ describe 'openstack-ops-database::mysql-client' do
let(:node) { runner.node } let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) } let(:chef_run) { runner.converge(described_recipe) }
it 'includes mysql client recipes' do it 'has default mysql client resource' do
expect(chef_run).to include_recipe 'mysql::client' expect(chef_run).to create_mysql_client 'default'
end end
it 'includes mysql-chef_gem recipes' do it 'has default mysql chef gem resource' do
expect(chef_run).to include_recipe 'mysql-chef_gem::default' expect(chef_run).to install_mysql2_chef_gem 'default'
end end
it 'installs mysql packages' do it 'installs mysql packages' do

View File

@ -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

View File

@ -8,63 +8,29 @@ describe 'openstack-ops-database::mysql-server' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node } let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) } 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 it 'includes mysql recipes' do
expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client' expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client'
end end
it 'creates template /etc/mysql/conf.d/openstack.cnf' do it 'creates mysql default service' 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
expect(chef_run).to create_mysql_service('default').with( 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 end
end end

View File

@ -7,14 +7,7 @@ describe 'openstack-ops-database::server' do
include_context 'database-stubs' include_context 'database-stubs'
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node } let(:node) { runner.node }
let(:chef_run) do let(:chef_run) { runner.converge(described_recipe) }
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
it 'uses mysql database server recipe by default' do it 'uses mysql database server recipe by default' do
expect(chef_run).to include_recipe('openstack-ops-database::mysql-server') expect(chef_run).to include_recipe('openstack-ops-database::mysql-server')

View File

@ -1,15 +1,12 @@
<%= node['openstack']['db']['custom_template_banner'] %> <%= node['openstack']['db']['custom_template_banner'] %>
[mysqld] [mysqld]
default-storage-engine = <%= node['mysql']['tunable']['default-storage-engine'] %> default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %>
bind-address = <%= node['mysql']['bind_address'] %> innodb_thread_concurrency= <%= node['openstack']['mysql']['innodb_thread_concurrency'] %>
innodb_thread_concurrency= <%= node['mysql']['tunable']['innodb_thread_concurrency'] %> innodb_commit_concurrency = <%= node['openstack']['mysql']['innodb_commit_concurrency'] %>
innodb_commit_concurrency = <%= node['mysql']['tunable']['innodb_commit_concurrency'] %> innodb_read_io_threads = <%= node['openstack']['mysql']['innodb_read_io_threads'] %>
<% if node["mysql"]["version"].to_f >= 5.5 %> innodb_flush_log_at_trx_commit = <%= node['openstack']['mysql']['innodb_flush_log_at_trx_commit'] %>
innodb_read_io_threads = <%= node['mysql']['tunable']['innodb_read_io_threads'] %> <% if node['openstack']['mysql']['skip-name-resolve'] %>
<% 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 skip-name-resolve
<% end %> <% end %>
character-set-server = <%= node['mysql']['tunable']['character-set-server'] %> character-set-server = <%= node['openstack']['mysql']['character-set-server'] %>
max_connections = <%= node['mysql']['tunable']['max_connections'] %> max_connections = <%= node['openstack']['mysql']['max_connections'] %>