Skip to content

Commit 1536eef

Browse files
author
Sean OMeara
committed
[COOK-3928] - Refactoring mysql cookbook for readability and maintainability
1 parent 4bba0d8 commit 1536eef

35 files changed

+807
-471
lines changed

.kitchen.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,15 @@ platforms:
1919
suites:
2020
- name: client
2121
run_list:
22-
- recipe[minitest-handler]
2322
- recipe[mysql_test::client]
2423
- name: ruby
2524
run_list:
2625
- recipe[mysql::ruby]
2726
- name: server
2827
run_list:
29-
- recipe[minitest-handler]
3028
- recipe[mysql_test::server]
3129
- name: server-nondefault-data
32-
excludes:
33-
- ubuntu-10.04 # https://tickets.opscode.com/browse/COOK-3780
34-
- ubuntu-12.04 # https://tickets.opscode.com/browse/COOK-3780
3530
run_list:
36-
- recipe[minitest-handler]
3731
- recipe[mysql_test::server]
3832
attributes:
3933
mysql:

Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
source 'https://rubygems.org'
22

3+
gem 'strainer'
34
gem 'berkshelf', '~> 2.0'
4-
gem 'chefspec', '~> 2.0'
5+
gem 'chefspec', '~> 3.0'
56
gem 'foodcritic', '~> 3.0'
6-
gem 'rubocop', '~> 0.12'
7+
gem 'rubocop', '~> 0.14'
78

89
group :integration do
9-
gem 'test-kitchen', '~> 1.0.0.beta'
10+
gem 'test-kitchen', '~> 1.0.0.beta.4'
1011
gem 'kitchen-vagrant', '~> 0.11'
1112
end

README.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ mysql Cookbook
44

55
Installs and configures MySQL client or server.
66

7-
87
Requirements
98
------------
109
Chef 0.10.10+.
1110

12-
1311
Platform
1412
--------
1513
- Debian, Ubuntu
@@ -18,10 +16,8 @@ Platform
1816

1917
Tested on:
2018

21-
- Debian 5.0, 6.0
22-
- Ubuntu 10.04-12.04
23-
- CentOS 5.5-5.8, 6.2-6.3
24-
- Mac OS X 10.7.2
19+
- Ubuntu 10.04, 12.04
20+
- CentOS 5.9, 6.5
2521

2622
See TESTING.md for information about running tests in Opscode's Test Kitchen.
2723

@@ -45,39 +41,31 @@ Attributes
4541
----------
4642
See the `attributes/server.rb` or `attributes/client.rb` for default values. Several attributes have values that vary based on the node's platform and version.
4743

44+
* `node['mysql']['port']` - Listen port for MySQLd
45+
* `node['mysql']['data_dir']` - Location for mysql data directory. `WARNING` This will only on initial converge. It will not move data around if you change it.
46+
4847
* `node['mysql']['client']['packages']` - An array of package names
4948
that should be installed on "client" systems. This can be modified,
5049
e.g., to specify packages for Percona.
5150
* `node['mysql']['server']['packages']` - An array of package names
5251
that should be installed on "server" systems. This can be modified,
5352
e.g., to specify packages for Percona.
54-
5553
* `node['mysql']['auto-increment-increment']` -
5654
auto-increment-increment value in my.cnf
57-
* `node['mysql']['auto-increment-offset]` - auto-increment-offset
58-
value in my.cnf
59-
* `node['mysql']['basedir']` - Base directory where MySQL is installed
55+
* `node['mysql']['auto-increment-offset]` - auto-increment-offset value in my.cnf
56+
* `node['mysql']['server']['basedir']` - Base directory where MySQL is installed
6057
* `node['mysql']['bind_address']` - Listen address for MySQLd
61-
* `node['mysql']['conf_dir']` - Location for mysql conf directory
62-
* `node['mysql']['confd_dir']` - Location for mysql conf.d style
63-
include directory
64-
* `node['mysql']['data_dir']` - Location for mysql data directory. `WARNING` see https://tickets.opscode.com/browse/COOK-3780 if using Ubuntu and changing this.
65-
* `node['mysql']['ec2_path']` - location of mysql data_dir on EC2
66-
nodes
67-
* `node['mysql']['grants_path']` - Path where the grants.sql should be
68-
written
58+
* `node['mysql']['ec2_path']` - location of mysql data_dir on EC2 nodes
59+
* `node['mysql']['grants_path']` - Path where the grants.sql should be written
6960
* `node['mysql']['mysqladmin_bin']` - Path to the mysqladmin binary
70-
* `node['mysql']['old_passwords']` - Sets the `old_passwords` value in
71-
my.cnf.
72-
* `node['mysql']['pid_file']` - Path to the mysqld.pid file
73-
* `node['mysql']['port']` - Listen port for MySQLd
74-
* `node['mysql']['reload_action']` - Action to take when mysql conf
61+
* `node['mysql']['server']['old_passwords']` - Sets the `old_passwords` value in my.cnf.
62+
* `node['mysql']['server']['pid_file']` - Path to the mysqld.pid file
63+
64+
* `node['mysql']['server']['reload_action']` - Action to take when mysql conf
7565
files are modified. Also allows "reload" and "none".
76-
* `node['mysql']['root_group']` - The default group of the "root" user
77-
* `node['mysql']['service_name']` - The name of the mysqld service
78-
* `node['mysql']['socket']` - Path to the mysqld.sock file
79-
* `node['mysql']['use_upstart']` - Whether to use upstart for the
80-
service provider
66+
* `node['mysql']['server']['root_group']` - The default group of the "root" user
67+
* `node['mysql']['server']['service_name']` - The name of the mysqld service
68+
* `node['mysql']['server']['socket']` - Path to the mysqld.sock file
8169
* `mysql['root_network_acl']` - Set define the network the root user will be able to login from, default is nil
8270

8371
Performance and other "tunable" attributes are under the `node['mysql']['tunable']` attribute, corresponding to the same-named parameter in my.cnf, and the default values are used. See `attributes/server.rb`.
@@ -216,6 +204,7 @@ License & Authors
216204
- Author:: Jesse Howarth (<[email protected]>)
217205
- Author:: Andrew Crump (<[email protected]>)
218206
- Author:: Christoph Hartmann (<[email protected]>)
207+
- Author:: Sean OMeara (<[email protected]>)
219208

220209
```text
221210
Copyright:: 2009-2013 Opscode, Inc

Strainerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rubocop: bundle exec rubocop
2+
chefspec: bundle exec rspec --color
3+
foodcritic: bundle exec foodcritic -f any . --tags ~FC007 --tags ~FC024

attributes/server.rb

Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -17,128 +17,20 @@
1717
# limitations under the License.
1818
#
1919

20+
# Probably driven from wrapper cookbooks, environments, or roles.
21+
# Keep in this namespace for backwards compat
2022
default['mysql']['bind_address'] = node.attribute?('cloud') && node['cloud']['local_ipv4'] ? node['cloud']['local_ipv4'] : node['ipaddress']
2123
default['mysql']['port'] = 3306
2224
default['mysql']['nice'] = 0
2325

24-
case node['platform_family']
25-
when 'debian'
26-
default['mysql']['server']['packages'] = %w[mysql-server]
27-
default['mysql']['service_name'] = 'mysql'
28-
default['mysql']['basedir'] = '/usr'
29-
default['mysql']['data_dir'] = '/var/lib/mysql'
30-
default['mysql']['root_group'] = 'root'
31-
default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
32-
default['mysql']['mysql_bin'] = '/usr/bin/mysql'
33-
34-
default['mysql']['conf_dir'] = '/etc/mysql'
35-
default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
36-
default['mysql']['socket'] = '/var/run/mysqld/mysqld.sock'
37-
default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid'
38-
default['mysql']['old_passwords'] = 0
39-
default['mysql']['grants_path'] = '/etc/mysql/grants.sql'
40-
when 'rhel', 'fedora'
41-
if node['mysql']['version'].to_f >= 5.5
42-
default['mysql']['service_name'] = 'mysql'
43-
default['mysql']['pid_file'] = '/var/run/mysql/mysql.pid'
44-
else
45-
default['mysql']['service_name'] = 'mysqld'
46-
default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid'
47-
end
48-
default['mysql']['server']['packages'] = %w[mysql-server]
49-
default['mysql']['basedir'] = '/usr'
50-
default['mysql']['data_dir'] = '/var/lib/mysql'
51-
default['mysql']['root_group'] = 'root'
52-
default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
53-
default['mysql']['mysql_bin'] = '/usr/bin/mysql'
54-
55-
default['mysql']['conf_dir'] = '/etc'
56-
default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
57-
default['mysql']['socket'] = '/var/lib/mysql/mysql.sock'
58-
default['mysql']['old_passwords'] = 1
59-
default['mysql']['grants_path'] = '/etc/mysql_grants.sql'
60-
# RHEL/CentOS mysql package does not support this option.
61-
default['mysql']['tunable']['innodb_adaptive_flushing'] = false
62-
when 'suse'
63-
default['mysql']['service_name'] = 'mysql'
64-
default['mysql']['server']['packages'] = %w[mysql-community-server]
65-
default['mysql']['basedir'] = '/usr'
66-
default['mysql']['data_dir'] = '/var/lib/mysql'
67-
default['mysql']['root_group'] = 'root'
68-
default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
69-
default['mysql']['mysql_bin'] = '/usr/bin/mysql'
70-
default['mysql']['conf_dir'] = '/etc'
71-
default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
72-
default['mysql']['socket'] = '/var/run/mysql/mysql.sock'
73-
default['mysql']['pid_file'] = '/var/run/mysql/mysqld.pid'
74-
default['mysql']['old_passwords'] = 1
75-
default['mysql']['grants_path'] = '/etc/mysql_grants.sql'
76-
when 'freebsd'
77-
default['mysql']['server']['packages'] = %w[mysql55-server]
78-
default['mysql']['service_name'] = 'mysql-server'
79-
default['mysql']['basedir'] = '/usr/local'
80-
default['mysql']['data_dir'] = '/var/db/mysql'
81-
default['mysql']['root_group'] = 'wheel'
82-
default['mysql']['mysqladmin_bin'] = '/usr/local/bin/mysqladmin'
83-
default['mysql']['mysql_bin'] = '/usr/local/bin/mysql'
84-
85-
default['mysql']['conf_dir'] = '/usr/local/etc'
86-
default['mysql']['confd_dir'] = '/usr/local/etc/mysql/conf.d'
87-
default['mysql']['socket'] = '/tmp/mysqld.sock'
88-
default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid'
89-
default['mysql']['old_passwords'] = 0
90-
default['mysql']['grants_path'] = '/var/db/mysql/grants.sql'
91-
when 'windows'
92-
default['mysql']['server']['packages'] = ['MySQL Server 5.5']
93-
default['mysql']['version'] = '5.5.32'
94-
default['mysql']['arch'] = 'win32'
95-
default['mysql']['package_file'] = "mysql-#{mysql['version']}-#{mysql['arch']}.msi"
96-
default['mysql']['url'] = "http://www.mysql.com/get/Downloads/MySQL-5.5/#{mysql['package_file']}/from/http://mysql.mirrors.pair.com/"
97-
98-
default['mysql']['service_name'] = 'mysql'
99-
default['mysql']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\Program Files (x86)\\MySQL\\#{mysql['server']['packages'].first}"
100-
default['mysql']['data_dir'] = "#{node['mysql']['basedir']}\\Data"
101-
default['mysql']['bin_dir'] = "#{node['mysql']['basedir']}\\bin"
102-
default['mysql']['mysqladmin_bin'] = "#{node['mysql']['bin_dir']}\\mysqladmin"
103-
default['mysql']['mysql_bin'] = "#{node['mysql']['bin_dir']}\\mysql"
104-
105-
default['mysql']['conf_dir'] = node['mysql']['basedir']
106-
default['mysql']['old_passwords'] = 0
107-
default['mysql']['grants_path'] = "#{node['mysql']['conf_dir']}\\grants.sql"
108-
when 'mac_os_x'
109-
default['mysql']['server']['packages'] = %w[mysql]
110-
default['mysql']['basedir'] = '/usr/local/Cellar'
111-
default['mysql']['data_dir'] = '/usr/local/var/mysql'
112-
default['mysql']['root_group'] = 'admin'
113-
default['mysql']['mysqladmin_bin'] = '/usr/local/bin/mysqladmin'
114-
default['mysql']['mysql_bin'] = '/usr/local/bin/mysql'
115-
else
116-
default['mysql']['server']['packages'] = %w[mysql-server]
117-
default['mysql']['service_name'] = 'mysql'
118-
default['mysql']['basedir'] = '/usr'
119-
default['mysql']['data_dir'] = '/var/lib/mysql'
120-
default['mysql']['root_group'] = 'root'
121-
default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
122-
default['mysql']['mysql_bin'] = '/usr/bin/mysql'
123-
124-
default['mysql']['conf_dir'] = '/etc/mysql'
125-
default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
126-
default['mysql']['socket'] = '/var/run/mysqld/mysqld.sock'
127-
default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid'
128-
default['mysql']['old_passwords'] = 0
129-
default['mysql']['grants_path'] = '/etc/mysql/grants.sql'
130-
end
131-
26+
# eventually remove? where is this used?
13227
if attribute?('ec2')
13328
default['mysql']['ec2_path'] = '/mnt/mysql'
13429
default['mysql']['ebs_vol_dev'] = '/dev/sdi'
13530
default['mysql']['ebs_vol_size'] = 50
13631
end
13732

138-
default['mysql']['reload_action'] = 'restart' # or 'reload' or 'none'
139-
140-
default['mysql']['use_upstart'] = node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 10.04
141-
33+
# actual configs start here
14234
default['mysql']['auto-increment-increment'] = 1
14335
default['mysql']['auto-increment-offset'] = 1
14436

@@ -168,7 +60,6 @@
16860
default['mysql']['tunable']['table_cache'] = '128'
16961
default['mysql']['tunable']['table_open_cache'] = node['mysql']['tunable']['table_cache'] # table_cache is deprecated
17062
# in favor of table_open_cache
171-
17263
default['mysql']['tunable']['thread_cache_size'] = 8
17364
default['mysql']['tunable']['thread_concurrency'] = 10
17465
default['mysql']['tunable']['thread_stack'] = '256K'
@@ -240,18 +131,14 @@
240131
default['mysql']['tunable']['query_cache_limit'] = '1M'
241132
default['mysql']['tunable']['query_cache_size'] = '16M'
242133

243-
default['mysql']['tunable']['log_slow_queries'] = '/var/log/mysql/slow.log'
244-
default['mysql']['tunable']['slow_query_log'] = node['mysql']['tunable']['log_slow_queries'] # log_slow_queries is deprecated
245-
# in favor of slow_query_log
246134
default['mysql']['tunable']['long_query_time'] = 2
247-
248135
default['mysql']['tunable']['expire_logs_days'] = 10
249136
default['mysql']['tunable']['max_binlog_size'] = '100M'
250137
default['mysql']['tunable']['binlog_cache_size'] = '32K'
251138

252139
default['mysql']['tmpdir'] = ['/tmp']
253140

254-
default['mysql']['log_dir'] = node['mysql']['data_dir']
141+
# default['mysql']['log_dir'] = node['mysql']['data_dir']
255142
default['mysql']['log_files_in_group'] = false
256143
default['mysql']['innodb_status_file'] = false
257144

attributes/server_debian.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
case node['platform_family']
2+
when 'debian'
3+
4+
# Probably driven from wrapper cookbooks, environments, or roles.
5+
# Keep in this namespace for backwards compat
6+
default['mysql']['data_dir'] = '/var/lib/mysql'
7+
8+
default['mysql']['server']['packages'] = %w{ mysql-server apparmor-utils }
9+
default['mysql']['server']['slow_query_log'] = 1
10+
default['mysql']['server']['slow_query_log_file'] = '/var/log/mysql/slow.log'
11+
12+
# Platformisms.. filesystem locations and such.
13+
default['mysql']['server']['basedir'] = '/usr'
14+
default['mysql']['server']['tmpdir'] = ['/tmp']
15+
16+
default['mysql']['server']['directories']['run_dir'] = '/var/run/mysqld'
17+
default['mysql']['server']['directories']['log_dir'] = '/var/lib/mysql'
18+
default['mysql']['server']['directories']['slow_log_dir'] = '/var/log/mysql'
19+
default['mysql']['server']['directories']['confd_dir'] = '/etc/mysql/conf.d'
20+
21+
default['mysql']['server']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
22+
default['mysql']['server']['mysql_bin'] = '/usr/bin/mysql'
23+
24+
default['mysql']['server']['pid_file'] = '/var/run/mysqld/mysqld.pid'
25+
default['mysql']['server']['socket'] = '/var/run/mysqld/mysqld.sock'
26+
default['mysql']['server']['grants_path'] = '/etc/mysql_grants.sql'
27+
default['mysql']['server']['old_passwords'] = 1
28+
29+
# wat
30+
default['mysql']['tunable']['innodb_adaptive_flushing'] = false
31+
default['mysql']['server']['skip_federated'] = false
32+
end

attributes/server_freebsd.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
case node['platform_family']
2+
3+
when 'freebsd'
4+
default['mysql']['data_dir'] = '/var/db/mysql'
5+
default['mysql']['server']['packages'] = %w[mysql55-server]
6+
default['mysql']['server']['service_name'] = 'mysql-server'
7+
default['mysql']['server']['basedir'] = '/usr/local'
8+
default['mysql']['server']['root_group'] = 'wheel'
9+
default['mysql']['server']['mysqladmin_bin'] = '/usr/local/bin/mysqladmin'
10+
default['mysql']['server']['mysql_bin'] = '/usr/local/bin/mysql'
11+
default['mysql']['server']['conf_dir'] = '/usr/local/etc'
12+
default['mysql']['server']['confd_dir'] = '/usr/local/etc/mysql/conf.d'
13+
default['mysql']['server']['socket'] = '/tmp/mysqld.sock'
14+
default['mysql']['server']['pid_file'] = '/var/run/mysqld/mysqld.pid'
15+
default['mysql']['server']['old_passwords'] = 0
16+
default['mysql']['server']['grants_path'] = '/var/db/mysql/grants.sql'
17+
end

attributes/server_mac_os_x.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
case node['platform_family']
2+
when 'mac_os_x'
3+
default['mysql']['server']['packages'] = %w[mysql]
4+
default['mysql']['basedir'] = '/usr/local/Cellar'
5+
default['mysql']['data_dir'] = '/usr/local/var/mysql'
6+
default['mysql']['root_group'] = 'admin'
7+
default['mysql']['mysqladmin_bin'] = '/usr/local/bin/mysqladmin'
8+
default['mysql']['mysql_bin'] = '/usr/local/bin/mysql'
9+
end

attributes/server_rhel.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
case node['platform_family']
2+
when 'rhel'
3+
4+
# Probably driven from wrapper cookbooks, environments, or roles.
5+
# Keep in this namespace for backwards compat
6+
default['mysql']['data_dir'] = '/var/lib/mysql'
7+
8+
# switching logic to account for differences in platform native
9+
# package versions
10+
case node['platform_version'].to_i
11+
when 5
12+
default['mysql']['server']['packages'] = ['mysql-server']
13+
default['mysql']['server']['log_slow_queries'] = '/var/log/mysql/slow.log'
14+
when 6
15+
default['mysql']['server']['packages'] = ['mysql-server']
16+
default['mysql']['server']['slow_query_log'] = 1
17+
default['mysql']['server']['slow_query_log_file'] = '/var/log/mysql/slow.log'
18+
end
19+
20+
# Platformisms.. filesystem locations and such.
21+
default['mysql']['server']['basedir'] = '/usr'
22+
default['mysql']['server']['tmpdir'] = ['/tmp']
23+
24+
default['mysql']['server']['directories']['run_dir'] = '/var/run/mysqld'
25+
default['mysql']['server']['directories']['log_dir'] = '/var/lib/mysql'
26+
default['mysql']['server']['directories']['slow_log_dir'] = '/var/log/mysql'
27+
default['mysql']['server']['directories']['confd_dir'] = '/etc/mysql/conf.d'
28+
29+
default['mysql']['server']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
30+
default['mysql']['server']['mysql_bin'] = '/usr/bin/mysql'
31+
32+
default['mysql']['server']['pid_file'] = '/var/run/mysqld/mysqld.pid'
33+
default['mysql']['server']['socket'] = '/var/lib/mysql/mysql.sock'
34+
default['mysql']['server']['grants_path'] = '/etc/mysql_grants.sql'
35+
default['mysql']['server']['old_passwords'] = 1
36+
37+
# RHEL/CentOS mysql package does not support this option.
38+
default['mysql']['tunable']['innodb_adaptive_flushing'] = false
39+
default['mysql']['server']['skip_federated'] = false
40+
end

0 commit comments

Comments
 (0)