summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Ming Yin <yinym@cn.ibm.com>2015-02-12 16:19:13 +0800
committerYi Ming Yin <yinym@cn.ibm.com>2015-03-27 14:28:35 +0800
commit9a864936c479c53a2757002af34e84fb818cfc91 (patch)
tree1162e2804be9e4abb6954655817bb86e8157cade
parent24e581ff068c5151c931873ef24b77bb39e2e216 (diff)
Add mariadb database configuration support
1. Add 2 new recipes to configure mariadb client and server 2. Partially reuse existing code for mysql support 3. Add delete empty user and users with empty password workaround. Current mysql cookbook can do this, but mariadb cookbook doesn't. blueprint: mariadb-support Change-Id: I034cedb07f8bf11f271fc351f9a7ad534067b95a
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Mark Vanderwiel <vanderwl@us.ibm.com> Workflow+1: JJ Asghar <jj@getchef.com> Submitted-by: Jenkins Submitted-at: Thu, 02 Apr 2015 21:07:41 +0000 Reviewed-on: https://review.openstack.org/155222 Project: stackforge/cookbook-openstack-ops-database Branch: refs/heads/master
-rwxr-xr-x[-rw-r--r--]metadata.rb3
-rw-r--r--recipes/mariadb-client.rb29
-rw-r--r--recipes/mariadb-server.rb75
-rw-r--r--spec/mariadb-client-redhat_spec.rb18
-rw-r--r--spec/mariadb-client-suse_spec.rb18
-rw-r--r--spec/mariadb-client_spec.rb32
-rw-r--r--spec/mariadb-server-redhat_spec.rb32
-rw-r--r--spec/mariadb-server_spec.rb71
-rw-r--r--templates/default/openstack.cnf.erb2
9 files changed, 279 insertions, 1 deletions
diff --git a/metadata.rb b/metadata.rb
index 3e3efda..d7149db 100644..100755
--- a/metadata.rb
+++ b/metadata.rb
@@ -9,6 +9,8 @@ recipe 'client', 'Installs client packages for the database used by the deployme
9recipe 'server', 'Installs and configures server packages for the database used by the deployment.' 9recipe 'server', 'Installs and configures server packages for the database used by the deployment.'
10recipe 'mysql-client', 'Installs MySQL client packages.' 10recipe 'mysql-client', 'Installs MySQL client packages.'
11recipe 'mysql-server', 'Installs and configures MySQL server packages.' 11recipe 'mysql-server', 'Installs and configures MySQL server packages.'
12recipe 'mariadb-client', 'Installs MariaDB client packages.'
13recipe 'mariadb-server', 'Installs and configures MariaDB server packages.'
12recipe 'postgresql-client', 'Installs PostgreSQL client packages.' 14recipe 'postgresql-client', 'Installs PostgreSQL client packages.'
13recipe 'postgresql-server', 'Installs and configures PostgreSQL server packages.' 15recipe 'postgresql-server', 'Installs and configures PostgreSQL server packages.'
14recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStack.' 16recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStack.'
@@ -17,6 +19,7 @@ recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStac
17 supports os 19 supports os
18end 20end
19 21
22depends 'mariadb', '~> 0.3.0'
20depends 'mysql', '~> 6.0.13' 23depends 'mysql', '~> 6.0.13'
21depends 'mysql2_chef_gem', '~> 1.0.1' 24depends 'mysql2_chef_gem', '~> 1.0.1'
22depends 'postgresql', '~> 3.4.18' 25depends 'postgresql', '~> 3.4.18'
diff --git a/recipes/mariadb-client.rb b/recipes/mariadb-client.rb
new file mode 100644
index 0000000..bc3fda1
--- /dev/null
+++ b/recipes/mariadb-client.rb
@@ -0,0 +1,29 @@
1# encoding: UTF-8
2#
3# Cookbook Name:: openstack-ops-database
4# Recipe:: mariadb-client
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19node.override['mariadb']['install']['prefer_os_package'] = true
20include_recipe 'mariadb::client'
21
22mysql2_chef_gem 'default' do
23 provider Chef::Provider::Mysql2ChefGem::Mariadb
24 action :install
25end
26
27node['openstack']['db']['python_packages']['mariadb'].each do |pkg|
28 package pkg
29end
diff --git a/recipes/mariadb-server.rb b/recipes/mariadb-server.rb
new file mode 100644
index 0000000..7835ff0
--- /dev/null
+++ b/recipes/mariadb-server.rb
@@ -0,0 +1,75 @@
1# encoding: UTF-8
2#
3# Cookbook Name:: openstack-ops-database
4# Recipe:: mariadb-server
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19class ::Chef::Recipe # rubocop:disable Documentation
20 include ::Openstack
21end
22
23db_endpoint = endpoint 'db'
24super_password = get_password 'user', node['openstack']['db']['root_user_key']
25
26node.override['mariadb']['allow_root_pass_change'] = true
27node.override['mariadb']['server_root_password'] = super_password
28node.override['mariadb']['mysqld']['bind_address'] = db_endpoint.host
29node.override['mariadb']['install']['prefer_os_package'] = true
30
31unless db_endpoint.host == '127.0.0.1' || db_endpoint.host == 'localhost'
32 node.override['mariadb']['forbid_remote_root'] = false
33end
34
35include_recipe 'openstack-ops-database::mariadb-client'
36
37# reuse mysql configuration for mariadb
38node.override['mariadb']['mysqld']['default_storage_engine'] = node['openstack']['mysql']['default-storage-engine']
39node.override['mariadb']['mysqld']['max_connections'] = node['openstack']['mysql']['max_connections']
40include_recipe 'mariadb::server'
41
42# reuse mysql configuration file for mariadb
43template "#{node['mariadb']['configuration']['includedir']}/openstack.cnf" do
44 owner 'mysql'
45 group 'mysql'
46 source 'openstack.cnf.erb'
47 notifies :restart, 'service[mysql]'
48end
49
50# Current mariadb cookbook does not handle deleting anonymous users and default
51# users. We need to delete them here.
52mysql_connection_info = {
53 host: 'localhost',
54 username: 'root',
55 password: super_password
56}
57
58mysql_database 'drop empty and default users' do
59 database_name 'mysql'
60 sql "DELETE FROM mysql.user WHERE User = '' OR Password = ''"
61 connection mysql_connection_info
62 action :query
63end
64
65mysql_database 'test' do
66 connection mysql_connection_info
67 action :drop
68end
69
70mysql_database 'flush priviledges after cleanup' do
71 database_name 'mysql'
72 sql 'FLUSH PRIVILEGES'
73 connection mysql_connection_info
74 action :query
75end
diff --git a/spec/mariadb-client-redhat_spec.rb b/spec/mariadb-client-redhat_spec.rb
new file mode 100644
index 0000000..367a51d
--- /dev/null
+++ b/spec/mariadb-client-redhat_spec.rb
@@ -0,0 +1,18 @@
1# encoding: UTF-8
2
3require_relative 'spec_helper'
4
5describe 'openstack-ops-database::mariadb-client' do
6 describe 'suse' do
7 let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
8 let(:node) do
9 runner.node.set['openstack']['db']['service_type'] = 'mariadb'
10 runner.node
11 end
12 let(:chef_run) { runner.converge(described_recipe) }
13
14 it 'installs mariadb python client packages' do
15 expect(chef_run).to install_package('MySQL-python')
16 end
17 end
18end
diff --git a/spec/mariadb-client-suse_spec.rb b/spec/mariadb-client-suse_spec.rb
new file mode 100644
index 0000000..0a0ea4f
--- /dev/null
+++ b/spec/mariadb-client-suse_spec.rb
@@ -0,0 +1,18 @@
1# encoding: UTF-8
2
3require_relative 'spec_helper'
4
5describe 'openstack-ops-database::mariadb-client' do
6 describe 'suse' do
7 let(:runner) { ChefSpec::Runner.new(SUSE_OPTS) }
8 let(:node) do
9 runner.node.set['openstack']['db']['service_type'] = 'mariadb'
10 runner.node
11 end
12 let(:chef_run) { runner.converge(described_recipe) }
13
14 it 'installs mariadb python client packages' do
15 expect(chef_run).to install_package('python-mysql')
16 end
17 end
18end
diff --git a/spec/mariadb-client_spec.rb b/spec/mariadb-client_spec.rb
new file mode 100644
index 0000000..7976c94
--- /dev/null
+++ b/spec/mariadb-client_spec.rb
@@ -0,0 +1,32 @@
1# encoding: UTF-8
2
3require_relative 'spec_helper'
4
5describe 'openstack-ops-database::mariadb-client' do
6 include_context 'database-stubs'
7 describe 'ubuntu' do
8 let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
9 let(:node) do
10 runner.node.set['openstack']['db']['service_type'] = 'mariadb'
11 runner.node
12 end
13 let(:chef_run) { runner.converge(described_recipe) }
14
15 it 'includes mariadb client recipes' do
16 expect(chef_run).to include_recipe('mariadb::client')
17 end
18
19 it 'install mysql2 gem package' do
20 expect(chef_run).to install_mysql2_chef_gem('default')
21 .with(provider: Chef::Provider::Mysql2ChefGem::Mariadb)
22 end
23
24 it 'installs mariadb python client packages' do
25 expect(chef_run).to install_package('python-mysqldb')
26 end
27
28 it 'override prefer os package' do
29 expect(chef_run.node['mariadb']['install']['prefer_os_package']).to be true
30 end
31 end
32end
diff --git a/spec/mariadb-server-redhat_spec.rb b/spec/mariadb-server-redhat_spec.rb
new file mode 100644
index 0000000..6c3afd8
--- /dev/null
+++ b/spec/mariadb-server-redhat_spec.rb
@@ -0,0 +1,32 @@
1# encoding: UTF-8
2
3require_relative 'spec_helper'
4
5describe 'openstack-ops-database::mariadb-server' do
6 describe 'redhat' do
7 include_context 'database-stubs'
8 let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
9 let(:node) { runner.node }
10 let(:chef_run) { runner.converge(described_recipe) }
11 let(:file) { chef_run.template('/etc/my.cnf.d/openstack.cnf') }
12
13 it 'creates template /etc/my.cnf.d/openstack.cnf' do
14 node.set['mariadb']['install']['version'] = '5.5'
15 expect(chef_run).to create_template(file.name).with(
16 user: 'mysql',
17 group: 'mysql',
18 source: 'openstack.cnf.erb'
19 )
20 expect(file).to notify('service[mysql]')
21 [/^default-storage-engine = InnoDB$/,
22 /^innodb_thread_concurrency = 0$/,
23 /^innodb_commit_concurrency = 0$/,
24 /^innodb_flush_log_at_trx_commit = 2$/,
25 /^skip-name-resolve$/,
26 /^character-set-server = utf8$/].each do |line|
27 expect(chef_run).to render_config_file(file.name)\
28 .with_section_content('mysqld', line)
29 end
30 end
31 end
32end
diff --git a/spec/mariadb-server_spec.rb b/spec/mariadb-server_spec.rb
new file mode 100644
index 0000000..8cfc530
--- /dev/null
+++ b/spec/mariadb-server_spec.rb
@@ -0,0 +1,71 @@
1# encoding: UTF-8
2
3require_relative 'spec_helper'
4
5describe 'openstack-ops-database::mariadb-server' do
6 describe 'ubuntu' do
7 include_context 'database-stubs'
8 let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
9 let(:node) { runner.node }
10 let(:chef_run) { runner.converge(described_recipe) }
11 let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') }
12
13 it 'overrides mariadb default attributes' do
14 expect(chef_run.node['mariadb']['mysqld']['bind_address']).to eq '127.0.0.1'
15 expect(chef_run.node['mariadb']['mysqld']['default_storage_engine']).to eq 'InnoDB'
16 expect(chef_run.node['mariadb']['mysqld']['max_connections']).to eq '1024'
17 expect(chef_run.node['mariadb']['forbid_remote_root']).to be true
18 end
19
20 it 'includes mariadb recipes' do
21 expect(chef_run).to include_recipe('openstack-ops-database::mariadb-client')
22 expect(chef_run).to include_recipe('mariadb::server')
23 end
24
25 it 'creates template /etc/mysql/conf.d/openstack.cnf' do
26 node.set['mariadb']['install']['version'] = '5.5'
27 expect(chef_run).to create_template(file.name).with(
28 user: 'mysql',
29 group: 'mysql',
30 source: 'openstack.cnf.erb'
31 )
32 expect(file).to notify('service[mysql]')
33 [/^default-storage-engine = InnoDB$/,
34 /^innodb_thread_concurrency = 0$/,
35 /^innodb_commit_concurrency = 0$/,
36 /^innodb_read_io_threads = 4$/,
37 /^innodb_flush_log_at_trx_commit = 2$/,
38 /^skip-name-resolve$/,
39 /^character-set-server = utf8$/,
40 /^max_connections = 1024$/].each do |line|
41 expect(chef_run).to render_config_file(file.name)\
42 .with_section_content('mysqld', line)
43 end
44 end
45
46 it 'creates mariadb with root password' do
47 # Password is fixed as 'abc123' by spec_helper
48 expect(chef_run.node['mariadb']['allow_root_pass_change']).to be true
49 expect(chef_run.node['mariadb']['server_root_password']).to eq 'abc123'
50 end
51
52 it 'override prefer os package' do
53 expect(chef_run.node['mariadb']['install']['prefer_os_package']).to be true
54 end
55
56 it 'allow root remote access' do
57 node.set['openstack']['endpoints']['db']['host'] = '192.168.1.1'
58 expect(chef_run.node['mariadb']['forbid_remote_root']).to be false
59 end
60
61 it 'drop anonymous and empty users' do
62 expect(chef_run).to query_mysql_database('drop empty and default users')\
63 .with(database_name: 'mysql',
64 sql: "DELETE FROM mysql.user WHERE User = '' OR Password = ''")
65 expect(chef_run).to drop_mysql_database('test')
66 expect(chef_run).to query_mysql_database('flush priviledges after cleanup')\
67 .with(database_name: 'mysql',
68 sql: 'FLUSH PRIVILEGES')
69 end
70 end
71end
diff --git a/templates/default/openstack.cnf.erb b/templates/default/openstack.cnf.erb
index 3251d68..c43fbed 100644
--- a/templates/default/openstack.cnf.erb
+++ b/templates/default/openstack.cnf.erb
@@ -1,7 +1,7 @@
1<%= node['openstack']['db']['custom_template_banner'] %> 1<%= node['openstack']['db']['custom_template_banner'] %>
2[mysqld] 2[mysqld]
3default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %> 3default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %>
4innodb_thread_concurrency= <%= node['openstack']['mysql']['innodb_thread_concurrency'] %> 4innodb_thread_concurrency = <%= node['openstack']['mysql']['innodb_thread_concurrency'] %>
5innodb_commit_concurrency = <%= node['openstack']['mysql']['innodb_commit_concurrency'] %> 5innodb_commit_concurrency = <%= node['openstack']['mysql']['innodb_commit_concurrency'] %>
6innodb_read_io_threads = <%= node['openstack']['mysql']['innodb_read_io_threads'] %> 6innodb_read_io_threads = <%= node['openstack']['mysql']['innodb_read_io_threads'] %>
7innodb_flush_log_at_trx_commit = <%= node['openstack']['mysql']['innodb_flush_log_at_trx_commit'] %> 7innodb_flush_log_at_trx_commit = <%= node['openstack']['mysql']['innodb_flush_log_at_trx_commit'] %>