Browse Source

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
Mark Vanderwiel 4 years ago
parent
commit
baa3b76fcb

+ 3
- 0
CHANGELOG.md View File

@@ -2,6 +2,9 @@ openstack-ops-database Cookbook CHANGELG
2 2
 ===================================
3 3
 This file is used to list changes made in each version of the openstack-ops-database cookbook.
4 4
 
5
+## 10.1.0
6
+* Updates for mysql cookbook ver 6.x
7
+
5 8
 ## 10.0.0
6 9
 * Upgrading to Juno
7 10
 * Upgrading berkshelf from 2.0.18 to 3.1.5

+ 1
- 1
Gemfile View File

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

+ 4
- 18
README.md View File

@@ -19,7 +19,7 @@ The following cookbooks are dependencies:
19 19
 * database
20 20
 * openstack-common
21 21
 * mysql
22
-* mysql-chef_gem
22
+* mysql2_chef_gem
23 23
 * postgresql
24 24
 
25 25
 # Usage #
@@ -77,26 +77,12 @@ The following attributes are defined in attributes/database.rb of the common coo
77 77
 * `openstack["endpoints"]["db"]["port"]` - The port to bind the database service to
78 78
 * `openstack["endpoints"]["db"]["path"]` - Unused at this time
79 79
 * `openstack["endpoints"]["db"]["bind_interface"]` - The interface name to bind the database service to
80
-* `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
81
-  to true, the mysql server_root_password attribute value will be ignored and will not reflect the password value, unless the attribute
82
-  value and the password retrieved from the data bag happen to be the same
83 80
 * `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
84
-  name of the key containing the password value within the data-bag item
85
-* `openstack["openstack"]["secret"]["user_passwords_data_bag"]` - The name of the data bag used to store the root user password
81
+  name of the key containing the password value within the data-bag item. This is defined in Common.
86 82
 
87 83
 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.
88 84
 
89
-The following mysql specific attributes are available:
90
-
91
-* `['mysql']['tunable']['default-storage-engine']`
92
-* `['mysql']['bind_address']`
93
-* `['mysql']['tunable']['innodb_thread_concurrency']`
94
-* `['mysql']['tunable']['innodb_commit_concurrency']`
95
-* `['mysql']['tunable']['innodb_read_io_threads']`
96
-* `['mysql']['tunable']['innodb_flush_log_at_trx_commit']`
97
-* `['mysql']['tunable']['skip-name-resolve']`
98
-* `['mysql']['tunable']['character-set-server']`
99
-* `['mysql']['tunable']['max_connections']`
85
+See the attributes mysql.rb file for the mysql specific attributes that are available.
100 86
 
101 87
 For more information see: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html
102 88
 
@@ -138,7 +124,7 @@ License and Author
138 124
 | **Copyright**        |  Copyright (c) 2012-2013, Opscode, Inc.            |
139 125
 | **Copyright**        |  Copyright (c) 2013, AT&T Services, Inc.           |
140 126
 | **Copyright**        |  Copyright (c) 2013-2014, SUSE Linux GmbH          |
141
-| **Copyright**        |  Copyright (c) 2014, IBM, Corp.                    |
127
+| **Copyright**        |  Copyright (c) 2014-2015, IBM, Corp.               |
142 128
 
143 129
 Licensed under the Apache License, Version 2.0 (the "License");
144 130
 you may not use this file except in compliance with the License.

+ 45
- 0
attributes/mysql.rb View File

@@ -0,0 +1,45 @@
1
+# encoding: UTF-8#
2
+#
3
+# Cookbook Name:: openstack-ops-database
4
+# Recipe:: default
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
+
19
+# MySql attributes that we use the mysql cookbook defaults:
20
+
21
+# Data directory
22
+default['openstack']['mysql']['data_dir'] = nil
23
+
24
+# MySql attributes that we select defaults for:
25
+
26
+# Version, support 5.5 and above
27
+default['openstack']['mysql']['version'] = '5.5'
28
+# Service name
29
+default['openstack']['mysql']['service_name'] = 'default'
30
+# Storage engine, base OpenStack requires the InnoDB flavor
31
+default['openstack']['mysql']['default-storage-engine'] = 'InnoDB'
32
+# InnoDB thread concurrency
33
+default['openstack']['mysql']['innodb_thread_concurrency'] = '0'
34
+# InnoDB commit concurrency
35
+default['openstack']['mysql']['innodb_commit_concurrency'] = '0'
36
+# InnoDB number of read io threads
37
+default['openstack']['mysql']['innodb_read_io_threads'] = '4'
38
+# InnoDB number of commit transactions to flush log
39
+default['openstack']['mysql']['innodb_flush_log_at_trx_commit'] = '2'
40
+# Skip name resolution
41
+default['openstack']['mysql']['skip-name-resolve'] = true
42
+# Character set
43
+default['openstack']['mysql']['character-set-server'] = 'utf8'
44
+# Maximum number of connections
45
+default['openstack']['mysql']['max_connections'] = '1024'

+ 6
- 6
metadata.rb View File

@@ -3,7 +3,7 @@ maintainer       'openstack-chef'
3 3
 maintainer_email 'opscode-chef-openstack@googlegroups.com'
4 4
 license           'Apache 2.0'
5 5
 description       'Provides the shared database configuration for Chef for OpenStack.'
6
-version           '10.0.0'
6
+version           '10.1.0'
7 7
 
8 8
 recipe 'client', 'Installs client packages for the database used by the deployment.'
9 9
 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
17 17
   supports os
18 18
 end
19 19
 
20
-depends 'mysql', '~> 5.4'
21
-depends 'mysql-chef_gem', '~> 0.0.2'
22
-depends 'postgresql', '~> 3.3'
23
-depends 'database', '~> 2.2'
24
-depends 'openstack-common', '>= 10.0.0'
20
+depends 'mysql', '>= 6.0.13', '< 7.0.0'
21
+depends 'mysql2_chef_gem', '>= 1.0.1', '< 2.0.0'
22
+depends 'postgresql', '>= 3.3.0', '< 4.0.0'
23
+depends 'database', '>= 4.0.2', '< 5.0.0'
24
+depends 'openstack-common', '>= 10.3.0'

+ 7
- 2
recipes/mysql-client.rb View File

@@ -20,8 +20,13 @@
20 20
 # limitations under the License.
21 21
 #
22 22
 
23
-include_recipe 'mysql::client'
24
-include_recipe 'mysql-chef_gem'
23
+mysql_client 'default' do
24
+  action :create
25
+end
26
+
27
+mysql2_chef_gem 'default' do
28
+  action :install
29
+end
25 30
 
26 31
 node['openstack']['db']['python_packages']['mysql'].each do |pkg|
27 32
   package pkg

+ 11
- 72
recipes/mysql-server.rb View File

@@ -22,86 +22,25 @@
22 22
 
23 23
 class ::Chef::Recipe # rubocop:disable Documentation
24 24
   include ::Openstack
25
-  include ::Opscode::Mysql::Helpers
26 25
 end
27 26
 
28 27
 db_endpoint = endpoint 'db'
29 28
 
30
-if node['openstack']['db']['root_user_use_databag']
31
-  super_password = get_password 'user', node['openstack']['db']['root_user_key']
32
-else
33
-  super_password = node['mysql']['server_root_password']
34
-end
35
-
36
-node.override['mysql']['tunable']['default-storage-engine'] = 'InnoDB'
37
-node.override['mysql']['bind_address'] = db_endpoint.host
38
-node.override['mysql']['tunable']['innodb_thread_concurrency'] = '0'
39
-node.override['mysql']['tunable']['innodb_commit_concurrency'] = '0'
40
-node.override['mysql']['tunable']['innodb_read_io_threads'] = '4'
41
-node.override['mysql']['tunable']['innodb_flush_log_at_trx_commit'] = '2'
42
-node.override['mysql']['tunable']['skip-name-resolve'] = true
43
-node.override['mysql']['tunable']['character-set-server'] = 'utf8'
44
-node.override['mysql']['tunable']['max_connections'] = '1024'
29
+super_password = get_password 'user', node['openstack']['db']['root_user_key']
45 30
 
46 31
 include_recipe 'openstack-ops-database::mysql-client'
47 32
 
48
-mysql_service node['mysql']['service_name'] do
49
-  version node['mysql']['version']
50
-  port node['mysql']['port']
51
-  data_dir node['mysql']['data_dir']
52
-  server_root_password super_password
53
-  server_debian_password node['mysql']['server_debian_password']
54
-  server_repl_password node['mysql']['server_repl_password']
55
-  allow_remote_root node['mysql']['allow_remote_root']
56
-  remove_anonymous_users node['mysql']['remove_anonymous_users']
57
-  remove_test_database node['mysql']['remove_test_database']
58
-  root_network_acl node['mysql']['root_network_acl']
59
-  action :create
33
+mysql_service node['openstack']['mysql']['service_name'] do
34
+  version node['openstack']['mysql']['version']
35
+  data_dir node['openstack']['mysql']['data_dir'] if node['openstack']['mysql']['data_dir']
36
+  initial_root_password super_password
37
+  bind_address db_endpoint.host
38
+  port db_endpoint.port.to_s
39
+  action [:create, :start]
60 40
 end
61 41
 
62
-# Set the version attribute based on what was actually
63
-# installed.
64
-server_resource = resources("mysql_service[#{node['mysql']['service_name']}]")
65
-server_version = server_resource.parsed_version
66
-node.set['mysql']['version'] = server_version
67
-
68
-template '/etc/mysql/conf.d/openstack.cnf' do
69
-  owner 'mysql'
70
-  group 'mysql'
42
+mysql_config 'openstack' do
71 43
   source 'openstack.cnf.erb'
72
-  notifies :restart, 'mysql_service[default]'
73
-end
74
-
75
-mysql_connection_info = {
76
-  host: 'localhost',
77
-  username: 'root',
78
-  password: super_password
79
-}
80
-
81
-mysql_database 'FLUSH PRIVILEGES pre query' do
82
-  connection mysql_connection_info
83
-  sql 'FLUSH PRIVILEGES'
84
-  action :query
85
-end
86
-
87
-# Unfortunately, this is needed to get around a MySQL bug
88
-# that repeatedly shows its face when running this in Vagabond
89
-# containers:
90
-#
91
-# http://bugs.mysql.com/bug.php?id=69644
92
-mysql_database 'drop empty localhost user' do
93
-  sql "DELETE FROM mysql.user WHERE User = '' OR Password = ''"
94
-  connection mysql_connection_info
95
-  action :query
96
-end
97
-
98
-mysql_database 'test' do
99
-  connection mysql_connection_info
100
-  action :drop
101
-end
102
-
103
-mysql_database 'FLUSH PRIVILEGES post query' do
104
-  connection mysql_connection_info
105
-  sql 'FLUSH PRIVILEGES'
106
-  action :query
44
+  notifies :restart, "mysql_service[#{node['openstack']['mysql']['service_name']}]"
45
+  action :create
107 46
 end

+ 4
- 4
spec/mysql-client_spec.rb View File

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

+ 0
- 46
spec/mysql-server-redhat_spec.rb View File

@@ -1,46 +0,0 @@
1
-# encoding: UTF-8
2
-
3
-require_relative 'spec_helper'
4
-
5
-describe 'openstack-ops-database::mysql-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) do
11
-      node.set_unless['mysql'] = {
12
-        'server_debian_password' => 'server-debian-password',
13
-        'server_root_password' => 'server-root-password',
14
-        'server_repl_password' => 'server-repl-password'
15
-      }
16
-      runner.converge(described_recipe)
17
-    end
18
-    let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') }
19
-
20
-    it 'sets mysql version to 5.5' do
21
-      expect(chef_run.node['mysql']['version']).to eql '5.5'
22
-    end
23
-
24
-    it 'creates template /etc/mysql/conf.d/openstack.cnf' do
25
-      expect(chef_run).to create_template(file.name).with(
26
-        user: 'mysql',
27
-        group: 'mysql',
28
-        source: 'openstack.cnf.erb'
29
-      )
30
-      expect(file).to notify('mysql_service[default]')
31
-      [/^# This file autogenerated by Chef$/,
32
-       /^# Do not edit, changes will be overwritten$/,
33
-       /^\[mysqld\]$/,
34
-       /^default-storage-engine = InnoDB$/,
35
-       /^bind-address = 127.0.0.1$/,
36
-       /^innodb_thread_concurrency= 0$/,
37
-       /^innodb_commit_concurrency = 0$/,
38
-       /^innodb_flush_log_at_trx_commit = 2$/,
39
-       /^skip-name-resolve$/,
40
-       /^character-set-server = utf8$/].each do |line|
41
-        expect(chef_run).to render_file(file.name).with_content(line)
42
-      end
43
-    end
44
-
45
-  end
46
-end

+ 15
- 49
spec/mysql-server_spec.rb View File

@@ -8,63 +8,29 @@ describe 'openstack-ops-database::mysql-server' do
8 8
     let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
9 9
     let(:node) { runner.node }
10 10
     let(:chef_run) { runner.converge(described_recipe) }
11
-    let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') }
12
-
13
-    it 'sets mysql version to 5.5' do
14
-      expect(chef_run.node['mysql']['version']).to eql '5.5'
15
-    end
16
-
17
-    it 'overrides default mysql attributes' do
18
-      expect(chef_run.node['mysql']['tunable']['default-storage-engine']).to eql 'InnoDB'
19
-      expect(chef_run.node['mysql']['bind_address']).to eql '127.0.0.1'
20
-      expect(chef_run.node['mysql']['tunable']['innodb_thread_concurrency']).to eql '0'
21
-      expect(chef_run.node['mysql']['tunable']['innodb_commit_concurrency']).to eql '0'
22
-      expect(chef_run.node['mysql']['tunable']['innodb_read_io_threads']).to eql '4'
23
-      expect(chef_run.node['mysql']['tunable']['innodb_flush_log_at_trx_commit']).to eql '2'
24
-      expect(chef_run.node['mysql']['tunable']['skip-name-resolve']).to eql true
25
-      expect(chef_run.node['mysql']['tunable']['character-set-server']).to eql 'utf8'
26
-      expect(chef_run.node['mysql']['tunable']['max_connections']).to eql '1024'
27
-    end
28 11
 
29 12
     it 'includes mysql recipes' do
30 13
       expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client'
31 14
     end
32 15
 
33
-    it 'creates template /etc/mysql/conf.d/openstack.cnf' do
34
-      expect(chef_run).to create_template(file.name).with(
35
-        user: 'mysql',
36
-        group: 'mysql',
37
-        source: 'openstack.cnf.erb'
16
+    it 'creates mysql default service' do
17
+      expect(chef_run).to create_mysql_service('default').with(
18
+        version: '5.5',
19
+        data_dir: nil,
20
+        initial_root_password: 'abc123',
21
+        bind_address: '127.0.0.1',
22
+        port: '3306',
23
+        action: [:create, :start]
38 24
       )
39
-      expect(file).to notify('mysql_service[default]')
40
-      [/^# This file autogenerated by Chef$/,
41
-       /^# Do not edit, changes will be overwritten$/,
42
-       /^\[mysqld\]$/,
43
-       /^default-storage-engine = InnoDB$/,
44
-       /^bind-address = 127.0.0.1$/,
45
-       /^innodb_thread_concurrency= 0$/,
46
-       /^innodb_commit_concurrency = 0$/,
47
-       /^innodb_read_io_threads = 4$/,
48
-       /^innodb_flush_log_at_trx_commit = 2$/,
49
-       /^skip-name-resolve$/,
50
-       /^character-set-server = utf8$/,
51
-       /^max_connections = 1024$/].each do |line|
52
-        expect(chef_run).to render_file(file.name).with_content(line)
53
-      end
54 25
     end
55 26
 
56
-    it 'prepares the database server' do
57
-      expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES pre query')
58
-      expect(chef_run).to query_mysql_database('drop empty localhost user')
59
-      expect(chef_run).to drop_mysql_database('test')
60
-      expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES post query')
61
-    end
62
-
63
-    it 'creates mysql service' do
64
-      node.set['openstack']['db']['root_user_use_databag'] = true
65
-      # Password is fixed as 'abc123' by spec_helper
66
-      expect(chef_run).to create_mysql_service('default').with(
67
-        server_root_password: 'abc123')
27
+    it 'creates mysql openstack config and notifies server to restart' do
28
+      expect(chef_run).to create_mysql_config('openstack').with(
29
+        source: 'openstack.cnf.erb',
30
+        action: [:create]
31
+      )
32
+      resource = chef_run.find_resource('mysql_config', 'openstack')
33
+      expect(resource).to notify('mysql_service[default]').to(:restart).delayed
68 34
     end
69 35
   end
70 36
 end

+ 1
- 8
spec/server_spec.rb View File

@@ -7,14 +7,7 @@ describe 'openstack-ops-database::server' do
7 7
     include_context 'database-stubs'
8 8
     let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
9 9
     let(:node) { runner.node }
10
-    let(:chef_run) do
11
-      node.set_unless['mysql'] = {
12
-        'server_debian_password' => 'server-debian-password',
13
-        'server_root_password' => 'server-root-password',
14
-        'server_repl_password' => 'server-repl-password'
15
-      }
16
-      runner.converge(described_recipe)
17
-    end
10
+    let(:chef_run) { runner.converge(described_recipe) }
18 11
 
19 12
     it 'uses mysql database server recipe by default' do
20 13
       expect(chef_run).to include_recipe('openstack-ops-database::mysql-server')

+ 8
- 11
templates/default/openstack.cnf.erb View File

@@ -1,15 +1,12 @@
1 1
 <%= node['openstack']['db']['custom_template_banner'] %>
2 2
 [mysqld]
3
-default-storage-engine = <%= node['mysql']['tunable']['default-storage-engine'] %>
4
-bind-address = <%= node['mysql']['bind_address'] %>
5
-innodb_thread_concurrency= <%= node['mysql']['tunable']['innodb_thread_concurrency'] %>
6
-innodb_commit_concurrency = <%= node['mysql']['tunable']['innodb_commit_concurrency'] %>
7
-<% if node["mysql"]["version"].to_f >= 5.5 %>
8
-innodb_read_io_threads = <%= node['mysql']['tunable']['innodb_read_io_threads'] %>
9
-<% end %>
10
-innodb_flush_log_at_trx_commit = <%= node['mysql']['tunable']['innodb_flush_log_at_trx_commit'] %>
11
-<% if node['mysql']['tunable']['skip-name-resolve'] %>
3
+default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %>
4
+innodb_thread_concurrency= <%= node['openstack']['mysql']['innodb_thread_concurrency'] %>
5
+innodb_commit_concurrency = <%= node['openstack']['mysql']['innodb_commit_concurrency'] %>
6
+innodb_read_io_threads = <%= node['openstack']['mysql']['innodb_read_io_threads'] %>
7
+innodb_flush_log_at_trx_commit = <%= node['openstack']['mysql']['innodb_flush_log_at_trx_commit'] %>
8
+<% if node['openstack']['mysql']['skip-name-resolve'] %>
12 9
 skip-name-resolve
13 10
 <% end %>
14
-character-set-server = <%= node['mysql']['tunable']['character-set-server'] %>
15
-max_connections = <%= node['mysql']['tunable']['max_connections'] %>
11
+character-set-server = <%= node['openstack']['mysql']['character-set-server'] %>
12
+max_connections = <%= node['openstack']['mysql']['max_connections'] %>

Loading…
Cancel
Save