2012-03-15 08:54:33 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
describe 'mysql::config' do
|
|
|
|
|
|
|
|
let :constant_parameter_defaults do
|
2012-03-16 07:33:17 +01:00
|
|
|
{
|
2013-04-08 17:23:24 +02:00
|
|
|
:root_password => 'UNSET',
|
|
|
|
:old_root_password => '',
|
|
|
|
:bind_address => '127.0.0.1',
|
|
|
|
:port => '3306',
|
|
|
|
:etc_root_password => false,
|
|
|
|
:datadir => '/var/lib/mysql',
|
|
|
|
:default_engine => 'UNSET',
|
|
|
|
:ssl => false,
|
|
|
|
:key_buffer => '16M',
|
|
|
|
:max_allowed_packet => '16M',
|
|
|
|
:thread_stack => '256K',
|
|
|
|
:thread_cache_size => 8,
|
|
|
|
:myisam_recover => 'BACKUP',
|
|
|
|
:query_cache_limit => '1M',
|
|
|
|
:query_cache_size => '16M',
|
|
|
|
:max_binlog_size => '100M',
|
|
|
|
:expire_logs_days => 10,
|
|
|
|
:character_set => 'UNSET',
|
|
|
|
:max_connections => 'UNSET',
|
|
|
|
:tmp_table_size => 'UNSET',
|
|
|
|
:max_heap_table_size => 'UNSET',
|
|
|
|
:table_open_cache => 'UNSET',
|
|
|
|
:long_query_time => 'UNSET',
|
|
|
|
:server_id => 'UNSET',
|
|
|
|
:sql_log_bin => 'UNSET',
|
|
|
|
:log_bin => 'UNSET',
|
|
|
|
:binlog_do_db => 'UNSET',
|
|
|
|
:log_bin_trust_function_creators => 'UNSET',
|
|
|
|
:replicate_ignore_table => 'UNSET',
|
|
|
|
:replicate_wild_do_table => 'UNSET',
|
2013-05-20 23:21:38 +02:00
|
|
|
:replicate_wild_ignore_table => 'UNSET'
|
2012-03-16 07:33:17 +01:00
|
|
|
}
|
2012-03-15 08:54:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with osfamily specific defaults' do
|
|
|
|
{
|
|
|
|
'Debian' => {
|
2012-05-10 06:55:16 +02:00
|
|
|
:datadir => '/var/lib/mysql',
|
2012-03-15 08:54:33 +01:00
|
|
|
:service_name => 'mysql',
|
|
|
|
:config_file => '/etc/mysql/my.cnf',
|
2012-05-10 06:55:16 +02:00
|
|
|
:socket => '/var/run/mysqld/mysqld.sock',
|
2012-08-22 03:09:48 +02:00
|
|
|
:pidfile => '/var/run/mysqld/mysqld.pid',
|
2012-05-10 06:55:16 +02:00
|
|
|
:root_group => 'root',
|
|
|
|
:ssl_ca => '/etc/mysql/cacert.pem',
|
|
|
|
:ssl_cert => '/etc/mysql/server-cert.pem',
|
|
|
|
:ssl_key => '/etc/mysql/server-key.pem'
|
|
|
|
},
|
|
|
|
'FreeBSD' => {
|
|
|
|
:datadir => '/var/db/mysql',
|
|
|
|
:service_name => 'mysql-server',
|
|
|
|
:config_file => '/var/db/mysql/my.cnf',
|
|
|
|
:socket => '/tmp/mysql.sock',
|
2012-08-22 03:09:48 +02:00
|
|
|
:pidfile => '/var/db/mysql/mysql.pid',
|
2013-06-16 17:41:29 +02:00
|
|
|
:root_group => 'wheel'
|
2012-03-15 08:54:33 +01:00
|
|
|
},
|
|
|
|
'Redhat' => {
|
2012-05-10 06:55:16 +02:00
|
|
|
:datadir => '/var/lib/mysql',
|
2012-03-15 08:54:33 +01:00
|
|
|
:service_name => 'mysqld',
|
|
|
|
:config_file => '/etc/my.cnf',
|
2012-05-10 06:55:16 +02:00
|
|
|
:socket => '/var/lib/mysql/mysql.sock',
|
2012-08-22 03:09:48 +02:00
|
|
|
:pidfile => '/var/run/mysqld/mysqld.pid',
|
2012-05-10 06:55:16 +02:00
|
|
|
:root_group => 'root',
|
|
|
|
:ssl_ca => '/etc/mysql/cacert.pem',
|
|
|
|
:ssl_cert => '/etc/mysql/server-cert.pem',
|
|
|
|
:ssl_key => '/etc/mysql/server-key.pem'
|
2012-03-15 08:54:33 +01:00
|
|
|
}
|
|
|
|
}.each do |osfamily, osparams|
|
|
|
|
|
|
|
|
|
|
|
|
describe "when osfamily is #{osfamily}" do
|
|
|
|
|
|
|
|
let :facts do
|
|
|
|
{:osfamily => osfamily}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when root password is set' do
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
{:root_password => 'foo'}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_exec('set_mysql_rootpw').with(
|
2012-05-11 06:46:54 +02:00
|
|
|
'command' => 'mysqladmin -u root password \'foo\'',
|
2012-03-15 08:54:33 +01:00
|
|
|
'logoutput' => true,
|
2012-05-11 06:46:54 +02:00
|
|
|
'unless' => "mysqladmin -u root -p\'foo\' status > /dev/null",
|
2012-05-02 06:42:34 +02:00
|
|
|
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
2012-03-15 08:54:33 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
it { should contain_file('/root/.my.cnf').with(
|
|
|
|
'content' => "[client]\nuser=root\nhost=localhost\npassword=foo\n",
|
|
|
|
'require' => 'Exec[set_mysql_rootpw]'
|
|
|
|
)}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when root password and old password are set' do
|
|
|
|
let :params do
|
|
|
|
{:root_password => 'foo', :old_root_password => 'bar'}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_exec('set_mysql_rootpw').with(
|
2012-05-11 06:46:54 +02:00
|
|
|
'command' => 'mysqladmin -u root -p\'bar\' password \'foo\'',
|
2012-03-15 08:54:33 +01:00
|
|
|
'logoutput' => true,
|
2012-05-11 06:46:54 +02:00
|
|
|
'unless' => "mysqladmin -u root -p\'foo\' status > /dev/null",
|
2012-05-02 06:42:34 +02:00
|
|
|
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
2012-03-15 08:54:33 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
{},
|
|
|
|
{
|
2013-04-07 22:20:36 +02:00
|
|
|
:service_name => 'dans_service',
|
|
|
|
:config_file => '/home/dan/mysql.conf',
|
|
|
|
:service_name => 'dans_mysql',
|
|
|
|
:pidfile => '/home/dan/mysql.pid',
|
|
|
|
:socket => '/home/dan/mysql.sock',
|
|
|
|
:bind_address => '0.0.0.0',
|
|
|
|
:port => '3306',
|
|
|
|
:datadir => '/path/to/datadir',
|
|
|
|
:default_engine => 'InnoDB',
|
|
|
|
:ssl => true,
|
|
|
|
:ssl_ca => '/path/to/cacert.pem',
|
|
|
|
:ssl_cert => '/path/to/server-cert.pem',
|
|
|
|
:ssl_key => '/path/to/server-key.pem',
|
2013-06-16 17:41:29 +02:00
|
|
|
:key_buffer => '16M',
|
|
|
|
:thread_stack => '256K',
|
|
|
|
:query_cache_size => '16M',
|
2013-04-07 22:20:36 +02:00
|
|
|
:character_set => 'utf8',
|
|
|
|
:max_connections => 1000,
|
|
|
|
:tmp_table_size => '4096M',
|
|
|
|
:max_heap_table_size => '4096M',
|
|
|
|
:table_open_cache => 2048,
|
2013-05-20 23:21:38 +02:00
|
|
|
:long_query_time => 0.5
|
2012-03-15 08:54:33 +01:00
|
|
|
}
|
|
|
|
].each do |passed_params|
|
|
|
|
|
|
|
|
describe "with #{passed_params == {} ? 'default' : 'specified'} parameters" do
|
|
|
|
|
|
|
|
let :parameter_defaults do
|
|
|
|
constant_parameter_defaults.merge(osparams)
|
|
|
|
end
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
passed_params
|
|
|
|
end
|
|
|
|
|
|
|
|
let :param_values do
|
|
|
|
parameter_defaults.merge(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_exec('mysqld-restart').with(
|
|
|
|
:refreshonly => true,
|
2012-03-16 19:52:30 +01:00
|
|
|
:path => '/sbin/:/usr/sbin/:/usr/bin/:/bin/',
|
2012-03-15 08:54:33 +01:00
|
|
|
:command => "service #{param_values[:service_name]} restart"
|
|
|
|
)}
|
|
|
|
|
|
|
|
it { should_not contain_exec('set_mysql_rootpw') }
|
|
|
|
|
2012-10-13 11:35:38 +02:00
|
|
|
it { should contain_file('/root/.my.cnf')}
|
2012-03-15 08:54:33 +01:00
|
|
|
|
|
|
|
it { should contain_file('/etc/mysql').with(
|
|
|
|
'owner' => 'root',
|
2012-05-10 06:55:16 +02:00
|
|
|
'group' => param_values[:root_group],
|
2012-03-15 08:54:33 +01:00
|
|
|
'notify' => 'Exec[mysqld-restart]',
|
|
|
|
'ensure' => 'directory',
|
|
|
|
'mode' => '0755'
|
|
|
|
)}
|
|
|
|
it { should contain_file('/etc/mysql/conf.d').with(
|
|
|
|
'owner' => 'root',
|
2012-05-10 06:55:16 +02:00
|
|
|
'group' => param_values[:root_group],
|
2012-03-15 08:54:33 +01:00
|
|
|
'notify' => 'Exec[mysqld-restart]',
|
|
|
|
'ensure' => 'directory',
|
|
|
|
'mode' => '0755'
|
|
|
|
)}
|
|
|
|
it { should contain_file(param_values[:config_file]).with(
|
|
|
|
'owner' => 'root',
|
2012-05-10 06:55:16 +02:00
|
|
|
'group' => param_values[:root_group],
|
2012-03-15 08:54:33 +01:00
|
|
|
'notify' => 'Exec[mysqld-restart]',
|
|
|
|
'mode' => '0644'
|
|
|
|
)}
|
|
|
|
it 'should have a template with the correct contents' do
|
|
|
|
content = param_value(subject, 'file', param_values[:config_file], 'content')
|
|
|
|
expected_lines = [
|
2013-04-07 22:20:36 +02:00
|
|
|
"port = #{param_values[:port]}",
|
2012-03-15 08:54:33 +01:00
|
|
|
"socket = #{param_values[:socket]}",
|
2012-08-22 03:09:48 +02:00
|
|
|
"pid-file = #{param_values[:pidfile]}",
|
2012-03-16 07:33:17 +01:00
|
|
|
"datadir = #{param_values[:datadir]}",
|
2013-04-08 17:23:24 +02:00
|
|
|
"bind-address = #{param_values[:bind_address]}",
|
|
|
|
"key_buffer = #{param_values[:key_buffer]}",
|
|
|
|
"max_allowed_packet = #{param_values[:max_allowed_packet]}",
|
|
|
|
"thread_stack = #{param_values[:thread_stack]}",
|
|
|
|
"thread_cache_size = #{param_values[:thread_cache_size]}",
|
|
|
|
"myisam-recover = #{param_values[:myisam_recover]}",
|
|
|
|
"query_cache_limit = #{param_values[:query_cache_limit]}",
|
|
|
|
"query_cache_size = #{param_values[:query_cache_size]}",
|
|
|
|
"expire_logs_days = #{param_values[:expire_logs_days]}",
|
2013-05-20 23:21:38 +02:00
|
|
|
"max_binlog_size = #{param_values[:max_binlog_size]}"
|
2012-03-15 08:54:33 +01:00
|
|
|
]
|
2013-04-07 22:20:36 +02:00
|
|
|
if param_values[:max_connections] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "max_connections = #{param_values[:max_connections]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:tmp_table_size] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "tmp_table_size = #{param_values[:tmp_table_size]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:max_heap_table_size] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "max_heap_table_size = #{param_values[:max_heap_table_size]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:table_open_cache] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "table_open_cache = #{param_values[:table_open_cache]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:long_query_time] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "long_query_time = #{param_values[:long_query_time]}" ]
|
|
|
|
end
|
2012-05-15 19:42:32 +02:00
|
|
|
if param_values[:default_engine] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "default-storage-engine = #{param_values[:default_engine]}" ]
|
2013-04-26 00:30:09 +02:00
|
|
|
else
|
|
|
|
content.should_not match(/^default-storage-engine = /)
|
2012-05-15 19:42:32 +02:00
|
|
|
end
|
2013-04-07 22:20:36 +02:00
|
|
|
if param_values[:character_set] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "character-set-server = #{param_values[:character_set]}" ]
|
|
|
|
end
|
2013-04-08 17:23:24 +02:00
|
|
|
if param_values[:sql_log_bin] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "sql_log_bin = #{param_values[:sql_log_bin]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:log_bin] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "log-bin = #{param_values[:log_bin]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:binlog_do_db] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "binlog-do-db = #{param_values[:binlog_do_db]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:log_bin_trust_function_creators] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "log_bin_trust_function_creators = #{param_values[:log_bin_trust_function_creators]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:replicate_ignore_table] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "replicate-ignore-table = #{param_values[:replicate_ignore_table]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:replicate_wild_do_table] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "replicate-wild-do-table = #{param_values[:replicate_wild_do_table]}" ]
|
|
|
|
end
|
|
|
|
if param_values[:replicate_wild_ignore_table] != 'UNSET'
|
|
|
|
expected_lines = expected_lines | [ "replicate-wild-ignore-table = #{param_values[:replicate_wild_ignore_table]}" ]
|
|
|
|
end
|
2012-03-20 00:24:01 +01:00
|
|
|
if param_values[:ssl]
|
|
|
|
expected_lines = expected_lines |
|
|
|
|
[
|
|
|
|
"ssl-ca = #{param_values[:ssl_ca]}",
|
|
|
|
"ssl-cert = #{param_values[:ssl_cert]}",
|
|
|
|
"ssl-key = #{param_values[:ssl_key]}"
|
|
|
|
]
|
|
|
|
end
|
2012-03-15 08:54:33 +01:00
|
|
|
(content.split("\n") & expected_lines).should == expected_lines
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when etc_root_password is set with password' do
|
|
|
|
|
|
|
|
let :facts do
|
|
|
|
{:osfamily => 'Debian'}
|
|
|
|
end
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
{:root_password => 'foo', :old_root_password => 'bar', :etc_root_password => true}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_exec('set_mysql_rootpw').with(
|
2012-05-11 06:46:54 +02:00
|
|
|
'command' => 'mysqladmin -u root -p\'bar\' password \'foo\'',
|
2012-03-15 08:54:33 +01:00
|
|
|
'logoutput' => true,
|
2012-05-11 06:46:54 +02:00
|
|
|
'unless' => "mysqladmin -u root -p\'foo\' status > /dev/null",
|
2012-05-02 06:42:34 +02:00
|
|
|
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
2012-03-15 08:54:33 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
it { should contain_file('/root/.my.cnf').with(
|
|
|
|
'content' => "[client]\nuser=root\nhost=localhost\npassword=foo\n",
|
|
|
|
'require' => 'Exec[set_mysql_rootpw]'
|
|
|
|
)}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'setting etc_root_password should fail on redhat' do
|
|
|
|
let :facts do
|
|
|
|
{:osfamily => 'Redhat'}
|
|
|
|
end
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
{:root_password => 'foo', :old_root_password => 'bar', :etc_root_password => true}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail' do
|
2012-07-24 01:39:37 +02:00
|
|
|
expect { subject }.to raise_error(Puppet::Error, /Duplicate (declaration|definition)/)
|
2012-03-15 08:54:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-05-10 06:55:16 +02:00
|
|
|
describe 'unset ssl params should fail when ssl is true on freebsd' do
|
|
|
|
let :facts do
|
|
|
|
{:osfamily => 'FreeBSD'}
|
|
|
|
end
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
{ :ssl => true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail' do
|
2012-07-24 01:39:37 +02:00
|
|
|
expect { subject }.to raise_error(Puppet::Error, /required when ssl is true/)
|
2012-05-10 06:55:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-03-15 08:54:33 +01:00
|
|
|
end
|