Skip to content

Commit 731036e

Browse files
committed
Merge pull request #167 from abraham1901/master
Implement character_set and other options
2 parents aa5d1f0 + 9d69afc commit 731036e

File tree

4 files changed

+285
-88
lines changed

4 files changed

+285
-88
lines changed

manifests/config.pp

+111-45
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,73 @@
11
# Class: mysql::config
22
#
33
# Parameters:
4-
# [*bind_address*] - address to bind service.
5-
# [*config_file*] - my.cnf configuration file path.
6-
# [*datadir*] - path to datadir.
7-
# [*tmpdir*] - path to tmpdir.
8-
# [*default_engine] - configure a default table engine
9-
# [*etc_root_password*] - whether to save /etc/my.cnf.
10-
# [*log_error] - path to mysql error log
11-
# [*manage_config_file*] - if the config file should be managed (default: true)
12-
# [*max_allowed_packet*] - Maximum network packet size mysqld will accept
13-
# [*old_root_password*] - previous root user password,
14-
# [*port*] - port to bind service.
15-
# [*restart] - whether to restart mysqld (true/false)
16-
# [*root_group] - use specified group for root-owned files
17-
# [*root_password*] - root user password.
18-
# [*service_name*] - mysql service name.
19-
# [*socket*] - mysql socket.
20-
# [*ssl] - enable ssl
21-
# [*ssl_ca] - path to ssl-ca
22-
# [*ssl_cert] - path to ssl-cert
23-
# [*ssl_key] - path to ssl-key
244
#
5+
# [*root_password*] - root user password.
6+
# [*old_root_password*] - previous root user password,
7+
# [*bind_address*] - address to bind service.
8+
# [*port*] - port to bind service.
9+
# [*etc_root_password*] - whether to save /etc/my.cnf.
10+
# [*service_name*] - mysql service name.
11+
# [*config_file*] - my.cnf configuration file path.
12+
# [*socket*] - mysql socket.
13+
# [*datadir*] - path to datadir.
14+
# [*ssl] - enable ssl
15+
# [*ssl_ca] - path to ssl-ca
16+
# [*ssl_cert] - path to ssl-cert
17+
# [*ssl_key] - path to ssl-key
18+
# [*log_error] - path to mysql error log
19+
# [*default_engine] - configure a default table engine
20+
# [*root_group] - use specified group for root-owned files
21+
# [*restart] - whether to restart mysqld (true/false)
22+
# [*character_set] - You can change the default server and
23+
# client character set
24+
# [*key_buffer] - Index blocks for MyISAM tables are buffered and
25+
# are shared by all threads. key_buffer_size is the size of the buffer used
26+
# for index blocks.
27+
# [*max_allowed_packet] - The maximum size of one packet or any
28+
# generated/intermediate string, or any parameter sent by the
29+
# mysql_stmt_send_long_data() C API function.
30+
# [*thread_stack] - The stack size for each thread.
31+
# [*thread_cache_size] - How many threads server should cache for reuse.
32+
# [*myisam-recover] - Set the MyISAM storage engine recovery mode.
33+
# [*query_cache_limit] - Do not cache results that are larger than this
34+
# number of bytes.
35+
# [*query_cache_size] - The amount of memory allocated for caching query
36+
# results.
37+
# [*max_connections] - The maximum permitted number of simultaneous
38+
# client connections.
39+
# [*tmp_table_size] - The maximum size of internal in-memory temporary
40+
# tables.
41+
# [*max_heap_table_size] - This variable sets the maximum size to which
42+
# user-created MEMORY tables are permitted to grow.
43+
# [*table_open_cache] - The number of open tables for all threads.
44+
# [*long_query_time] - If a query takes longer than this many seconds,
45+
# the server increments the Slow_queries status variable.
46+
# [*server_id] - The server ID, used in replication to give each
47+
# master and slave a unique identity.
48+
# [*sql_log_bin] - This variable controls whether logging to the
49+
# binary log is done. The default value is 1.
50+
# [*log_bin] - Enable binary logging. The server logs all
51+
# statements that change data to the binary log, which is used for backup
52+
# and replication.
53+
# [*max_binlog_size] - If a write to the binary log causes the current
54+
# log file size to exceed the value of this variable, the server rotates
55+
# the binary logs (closes the current file and opens the next one).
56+
# [*binlog_do_db] - This option affects binary logging in a manner
57+
# similar to the way that --replicate-do-db affects replication.
58+
# [*expire_logs_days] - The number of days for automatic binary log file
59+
# removal.
60+
# [*log_bin_trust_function_creators] - It controls whether stored function
61+
# creators can be trusted not to create stored functions that will cause
62+
# unsafe events to be written to the binary log.
63+
# [*replicate_ignore_table] - Tells the slave SQL thread not to
64+
# replicate any statement that updates the specified table, even if any
65+
# other tables might be updated by the same statement.
66+
# [*replicate_wild_do_table] - Tells the slave thread to restrict
67+
# replication to statements where any of the updated tables match the
68+
# specified database and table name patterns.
69+
# [*replicate_wild_ignore_table] - Tells the slave thread not to
70+
# replicate a statement where any table matches the given wildcard pattern.
2571
#
2672
# Actions:
2773
#
@@ -37,37 +83,57 @@
3783
# }
3884
#
3985
class mysql::config(
40-
$bind_address = $mysql::bind_address,
41-
$config_file = $mysql::config_file,
42-
$datadir = $mysql::datadir,
43-
$tmpdir = $mysql::tmpdir,
44-
$default_engine = $mysql::default_engine,
45-
$etc_root_password = $mysql::etc_root_password,
46-
$manage_config_file = $mysql::manage_config_file,
47-
$max_allowed_packet = $mysql::max_allowed_packet,
48-
$log_error = $mysql::log_error,
49-
$pidfile = $mysql::pidfile,
50-
$port = $mysql::port,
51-
$purge_conf_dir = $mysql::purge_conf_dir,
52-
$max_connections = $mysql::max_connections,
53-
$restart = $mysql::restart,
54-
$root_group = $mysql::root_group,
55-
$root_password = $mysql::root_password,
56-
$old_root_password = $mysql::old_root_password,
57-
$service_name = $mysql::service_name,
58-
$socket = $mysql::socket,
59-
$ssl = $mysql::ssl,
60-
$ssl_ca = $mysql::ssl_ca,
61-
$ssl_cert = $mysql::ssl_cert,
62-
$ssl_key = $mysql::ssl_key
86+
$root_password = $mysql::root_password,
87+
$old_root_password = $mysql::old_root_password,
88+
$bind_address = $mysql::bind_address,
89+
$port = $mysql::port,
90+
$etc_root_password = $mysql::etc_root_password,
91+
$manage_config_file = $mysql::manage_config_file,
92+
$service_name = $mysql::service_name,
93+
$config_file = $mysql::config_file,
94+
$socket = $mysql::socket,
95+
$pidfile = $mysql::pidfile,
96+
$datadir = $mysql::datadir,
97+
$ssl = $mysql::ssl,
98+
$ssl_ca = $mysql::ssl_ca,
99+
$ssl_cert = $mysql::ssl_cert,
100+
$ssl_key = $mysql::ssl_key,
101+
$log_error = $mysql::log_error,
102+
$default_engine = $mysql::default_engine,
103+
$root_group = $mysql::root_group,
104+
$restart = $mysql::restart,
105+
$purge_conf_dir = $mysql::purge_conf_dir,
106+
$key_buffer = $mysql::key_buffer,
107+
$max_allowed_packet = $mysql::max_allowed_packet,
108+
$thread_stack = $mysql::thread_stack,
109+
$thread_cache_size = $mysql::thread_cache_size,
110+
$myisam_recover = $mysql::myisam_recover,
111+
$query_cache_limit = $mysql::query_cache_limit,
112+
$query_cache_size = $mysql::query_cache_size,
113+
$max_binlog_size = $mysql::max_binlog_size,
114+
$expire_logs_days = $mysql::expire_logs_days,
115+
$max_connections = $mysql::max_connections,
116+
$tmp_table_size = 'UNSET',
117+
$max_heap_table_size = 'UNSET',
118+
$table_open_cache = 'UNSET',
119+
$long_query_time = 'UNSET',
120+
$character_set = 'UNSET',
121+
$server_id = 'UNSET',
122+
$sql_log_bin = 'UNSET',
123+
$log_bin = 'UNSET',
124+
$binlog_do_db = 'UNSET',
125+
$log_bin_trust_function_creators = 'UNSET',
126+
$replicate_ignore_table = 'UNSET',
127+
$replicate_wild_do_table = 'UNSET',
128+
$replicate_wild_ignore_table = 'UNSET'
63129
) inherits mysql {
64130

65131
File {
66132
owner => 'root',
67133
group => $root_group,
68134
mode => '0400',
69-
notify => $restart ? {
70-
true => Exec['mysqld-restart'],
135+
notify => $restart ? {
136+
true => Exec['mysqld-restart'],
71137
false => undef,
72138
},
73139
}

manifests/params.pp

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
$root_password = 'UNSET'
2727
$restart = true
2828
$ssl = false
29+
$key_buffer = '16M'
30+
$thread_stack = '256K'
31+
$thread_cache_size = 8
32+
$myisam_recover = 'BACKUP'
33+
$query_cache_limit = '1M'
34+
$query_cache_size = '16M'
35+
$expire_logs_days = 10
36+
$max_binlog_size = 100M
2937

3038
case $::operatingsystem {
3139
'Ubuntu': {

spec/classes/mysql_config_spec.rb

+101-27
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,37 @@
33

44
let :constant_parameter_defaults do
55
{
6-
:root_password => 'UNSET',
7-
:old_root_password => '',
8-
:max_connections => '151',
9-
:bind_address => '127.0.0.1',
10-
:port => '3306',
11-
:max_allowed_packet => '16M',
12-
:etc_root_password => false,
13-
:datadir => '/var/lib/mysql',
14-
:default_engine => 'UNSET',
15-
:ssl => false,
6+
:root_password => 'UNSET',
7+
:old_root_password => '',
8+
:max_connections => '151',
9+
:bind_address => '127.0.0.1',
10+
:port => '3306',
11+
:etc_root_password => false,
12+
:datadir => '/var/lib/mysql',
13+
:default_engine => 'UNSET',
14+
:ssl => false,
15+
:key_buffer => '16M',
16+
:max_allowed_packet => '16M',
17+
:thread_stack => '256K',
18+
:thread_cache_size => 8,
19+
:myisam_recover => 'BACKUP',
20+
:query_cache_limit => '1M',
21+
:query_cache_size => '16M',
22+
:max_binlog_size => '100M',
23+
:expire_logs_days => 10,
24+
:character_set => 'UNSET',
25+
:tmp_table_size => 'UNSET',
26+
:max_heap_table_size => 'UNSET',
27+
:table_open_cache => 'UNSET',
28+
:long_query_time => 'UNSET',
29+
:server_id => 'UNSET',
30+
:sql_log_bin => 'UNSET',
31+
:log_bin => 'UNSET',
32+
:binlog_do_db => 'UNSET',
33+
:log_bin_trust_function_creators => 'UNSET',
34+
:replicate_ignore_table => 'UNSET',
35+
:replicate_wild_do_table => 'UNSET',
36+
:replicate_wild_ignore_table => 'UNSET'
1637
}
1738
end
1839

@@ -110,20 +131,29 @@
110131
[
111132
{},
112133
{
113-
:service_name => 'dans_service',
114-
:config_file => '/home/dan/mysql.conf',
115-
:service_name => 'dans_mysql',
116-
:pidfile => '/home/dan/mysql.pid',
117-
:socket => '/home/dan/mysql.sock',
118-
:bind_address => '0.0.0.0',
119-
:port => '3306',
120-
:max_allowed_packet => '32M',
121-
:datadir => '/path/to/datadir',
122-
:default_engine => 'InnoDB',
123-
:ssl => true,
124-
:ssl_ca => '/path/to/cacert.pem',
125-
:ssl_cert => '/path/to/server-cert.pem',
126-
:ssl_key => '/path/to/server-key.pem'
134+
:service_name => 'dans_service',
135+
:config_file => '/home/dan/mysql.conf',
136+
:service_name => 'dans_mysql',
137+
:pidfile => '/home/dan/mysql.pid',
138+
:socket => '/home/dan/mysql.sock',
139+
:bind_address => '0.0.0.0',
140+
:port => '3306',
141+
:datadir => '/path/to/datadir',
142+
:default_engine => 'InnoDB',
143+
:ssl => true,
144+
:ssl_ca => '/path/to/cacert.pem',
145+
:ssl_cert => '/path/to/server-cert.pem',
146+
:ssl_key => '/path/to/server-key.pem',
147+
:key_buffer => '16M',
148+
:max_allowed_packet => '32M',
149+
:thread_stack => '256K',
150+
:query_cache_size => '16M',
151+
:character_set => 'utf8',
152+
:max_connections => 1000,
153+
:tmp_table_size => '4096M',
154+
:max_heap_table_size => '4096M',
155+
:table_open_cache => 2048,
156+
:long_query_time => 0.5
127157
}
128158
].each do |passed_params|
129159

@@ -174,19 +204,63 @@
174204
it 'should have a template with the correct contents' do
175205
content = param_value(subject, 'file', param_values[:config_file], 'content')
176206
expected_lines = [
177-
"port = #{param_values[:port]}",
207+
"port = #{param_values[:port]}",
178208
"socket = #{param_values[:socket]}",
179209
"pid-file = #{param_values[:pidfile]}",
180210
"datadir = #{param_values[:datadir]}",
181211
"max_connections = #{param_values[:max_connections]}",
182-
"bind-address = #{param_values[:bind_address]}",
183-
"max_allowed_packet = #{param_values[:max_allowed_packet]}"
212+
"bind-address = #{param_values[:bind_address]}",
213+
"key_buffer = #{param_values[:key_buffer]}",
214+
"max_allowed_packet = #{param_values[:max_allowed_packet]}",
215+
"thread_stack = #{param_values[:thread_stack]}",
216+
"thread_cache_size = #{param_values[:thread_cache_size]}",
217+
"myisam-recover = #{param_values[:myisam_recover]}",
218+
"query_cache_limit = #{param_values[:query_cache_limit]}",
219+
"query_cache_size = #{param_values[:query_cache_size]}",
220+
"expire_logs_days = #{param_values[:expire_logs_days]}",
221+
"max_binlog_size = #{param_values[:max_binlog_size]}"
184222
]
223+
if param_values[:tmp_table_size] != 'UNSET'
224+
expected_lines = expected_lines | [ "tmp_table_size = #{param_values[:tmp_table_size]}" ]
225+
end
226+
if param_values[:max_heap_table_size] != 'UNSET'
227+
expected_lines = expected_lines | [ "max_heap_table_size = #{param_values[:max_heap_table_size]}" ]
228+
end
229+
if param_values[:table_open_cache] != 'UNSET'
230+
expected_lines = expected_lines | [ "table_open_cache = #{param_values[:table_open_cache]}" ]
231+
end
232+
if param_values[:long_query_time] != 'UNSET'
233+
expected_lines = expected_lines | [ "long_query_time = #{param_values[:long_query_time]}" ]
234+
end
185235
if param_values[:default_engine] != 'UNSET'
186236
expected_lines = expected_lines | [ "default-storage-engine = #{param_values[:default_engine]}" ]
187237
else
188238
content.should_not match(/^default-storage-engine = /)
189239
end
240+
if param_values[:character_set] != 'UNSET'
241+
expected_lines = expected_lines | [ "character-set-server = #{param_values[:character_set]}" ]
242+
end
243+
if param_values[:sql_log_bin] != 'UNSET'
244+
expected_lines = expected_lines | [ "sql_log_bin = #{param_values[:sql_log_bin]}" ]
245+
end
246+
if param_values[:log_bin] != 'UNSET'
247+
expected_lines = expected_lines | [ "log-bin = #{param_values[:log_bin]}" ]
248+
end
249+
if param_values[:binlog_do_db] != 'UNSET'
250+
expected_lines = expected_lines | [ "binlog-do-db = #{param_values[:binlog_do_db]}" ]
251+
end
252+
if param_values[:log_bin_trust_function_creators] != 'UNSET'
253+
expected_lines = expected_lines | [ "log_bin_trust_function_creators = #{param_values[:log_bin_trust_function_creators]}" ]
254+
end
255+
if param_values[:replicate_ignore_table] != 'UNSET'
256+
expected_lines = expected_lines | [ "replicate-ignore-table = #{param_values[:replicate_ignore_table]}" ]
257+
end
258+
if param_values[:replicate_wild_do_table] != 'UNSET'
259+
expected_lines = expected_lines | [ "replicate-wild-do-table = #{param_values[:replicate_wild_do_table]}" ]
260+
end
261+
if param_values[:replicate_wild_ignore_table] != 'UNSET'
262+
expected_lines = expected_lines | [ "replicate-wild-ignore-table = #{param_values[:replicate_wild_ignore_table]}" ]
263+
end
190264
if param_values[:ssl]
191265
expected_lines = expected_lines |
192266
[

0 commit comments

Comments
 (0)