commit
d66607d21a
9 changed files with 142 additions and 24 deletions
|
@ -44,16 +44,29 @@ class mysql::config(
|
|||
$ssl_cert = $mysql::params::ssl_cert,
|
||||
$ssl_key = $mysql::params::ssl_key,
|
||||
$log_error = $mysql::params::log_error,
|
||||
$default_engine = 'UNSET'
|
||||
$default_engine = 'UNSET',
|
||||
$root_group = $mysql::params::root_group
|
||||
) inherits mysql::params {
|
||||
|
||||
File {
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
group => $root_group,
|
||||
mode => '0400',
|
||||
notify => Exec['mysqld-restart'],
|
||||
}
|
||||
|
||||
if $ssl and $ssl_ca == undef {
|
||||
fail('The ssl_ca parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if $ssl and $ssl_cert == undef {
|
||||
fail('The ssl_cert parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if $ssl and $ssl_key == undef {
|
||||
fail('The ssl_key parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
# This kind of sucks, that I have to specify a difference resource for
|
||||
# restart. the reason is that I need the service to be started before mods
|
||||
# to the config file which can cause a refresh
|
||||
|
@ -75,7 +88,7 @@ class mysql::config(
|
|||
command => "mysqladmin -u root ${old_pw} password ${root_password}",
|
||||
logoutput => true,
|
||||
unless => "mysqladmin -u root -p${root_password} status > /dev/null",
|
||||
path => '/usr/local/sbin:/usr/bin',
|
||||
path => '/usr/local/sbin:/usr/bin:/usr/local/bin',
|
||||
notify => Exec['mysqld-restart'],
|
||||
require => File['/etc/mysql/conf.d'],
|
||||
}
|
||||
|
|
|
@ -14,13 +14,8 @@ class mysql::params {
|
|||
|
||||
$bind_address = '127.0.0.1'
|
||||
$port = 3306
|
||||
$server_package_name = 'mysql-server'
|
||||
$etc_root_password = false
|
||||
$datadir = '/var/lib/mysql'
|
||||
$ssl = false
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
|
||||
case $::operatingsystem {
|
||||
"Ubuntu": {
|
||||
|
@ -33,8 +28,11 @@ class mysql::params {
|
|||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
$basedir = '/usr'
|
||||
$datadir = '/var/lib/mysql'
|
||||
$service_name = 'mysqld'
|
||||
$client_package_name = 'mysql'
|
||||
$server_package_name = 'mysql-server'
|
||||
$socket = '/var/lib/mysql/mysql.sock'
|
||||
$config_file = '/etc/my.cnf'
|
||||
$log_error = '/var/log/mysqld.log'
|
||||
|
@ -42,21 +40,51 @@ class mysql::params {
|
|||
$ruby_package_provider = 'gem'
|
||||
$python_package_name = 'MySQL-python'
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$root_group = 'root'
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$basedir = '/usr'
|
||||
$datadir = '/var/lib/mysql'
|
||||
$service_name = 'mysql'
|
||||
$client_package_name = 'mysql-client'
|
||||
$server_package_name = 'mysql-server'
|
||||
$socket = '/var/run/mysqld/mysqld.sock'
|
||||
$config_file = '/etc/mysql/my.cnf'
|
||||
$log_error = '/var/log/mysql/error.log'
|
||||
$ruby_package_name = 'libmysql-ruby'
|
||||
$python_package_name = 'python-mysqldb'
|
||||
$java_package_name = 'libmysql-java'
|
||||
$root_group = 'root'
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
}
|
||||
|
||||
'FreeBSD': {
|
||||
$basedir = '/usr/local'
|
||||
$datadir = '/var/db/mysql'
|
||||
$service_name = 'mysql-server'
|
||||
$client_package_name = 'databases/mysql55-client'
|
||||
$server_package_name = 'databases/mysql55-server'
|
||||
$socket = '/tmp/mysql.sock'
|
||||
$config_file = '/var/db/mysql/my.cnf'
|
||||
$log_error = "/var/db/mysql/${::hostname}.err"
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
$python_package_name = 'databases/py-MySQLdb'
|
||||
$java_package_name = 'databases/mysql-connector-java'
|
||||
$root_group = 'wheel'
|
||||
$ssl_ca = undef
|
||||
$ssl_cert = undef
|
||||
$ssl_key = undef
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat and Debian")
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat Debian and FreeBSD")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,23 +11,37 @@ describe 'mysql::config' do
|
|||
:datadir => '/var/lib/mysql',
|
||||
:default_engine => 'UNSET',
|
||||
:ssl => false,
|
||||
:ssl_ca => '/etc/mysql/cacert.pem',
|
||||
:ssl_cert => '/etc/mysql/server-cert.pem',
|
||||
:ssl_key => '/etc/mysql/server-key.pem'
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with osfamily specific defaults' do
|
||||
{
|
||||
'Debian' => {
|
||||
:datadir => '/var/lib/mysql',
|
||||
:service_name => 'mysql',
|
||||
:config_file => '/etc/mysql/my.cnf',
|
||||
:socket => '/var/run/mysqld/mysqld.sock'
|
||||
:socket => '/var/run/mysqld/mysqld.sock',
|
||||
: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',
|
||||
:root_group => 'wheel',
|
||||
},
|
||||
'Redhat' => {
|
||||
:datadir => '/var/lib/mysql',
|
||||
:service_name => 'mysqld',
|
||||
:config_file => '/etc/my.cnf',
|
||||
:socket => '/var/lib/mysql/mysql.sock'
|
||||
:socket => '/var/lib/mysql/mysql.sock',
|
||||
:root_group => 'root',
|
||||
:ssl_ca => '/etc/mysql/cacert.pem',
|
||||
:ssl_cert => '/etc/mysql/server-cert.pem',
|
||||
:ssl_key => '/etc/mysql/server-key.pem'
|
||||
}
|
||||
}.each do |osfamily, osparams|
|
||||
|
||||
|
@ -48,7 +62,7 @@ describe 'mysql::config' do
|
|||
'command' => 'mysqladmin -u root password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
||||
)}
|
||||
|
||||
it { should contain_file('/root/.my.cnf').with(
|
||||
|
@ -67,7 +81,7 @@ describe 'mysql::config' do
|
|||
'command' => 'mysqladmin -u root -pbar password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
||||
)}
|
||||
|
||||
end
|
||||
|
@ -116,21 +130,21 @@ describe 'mysql::config' do
|
|||
|
||||
it { should contain_file('/etc/mysql').with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'group' => param_values[:root_group],
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'ensure' => 'directory',
|
||||
'mode' => '0755'
|
||||
)}
|
||||
it { should contain_file('/etc/mysql/conf.d').with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'group' => param_values[:root_group],
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'ensure' => 'directory',
|
||||
'mode' => '0755'
|
||||
)}
|
||||
it { should contain_file(param_values[:config_file]).with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'group' => param_values[:root_group],
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'mode' => '0644'
|
||||
)}
|
||||
|
@ -175,7 +189,7 @@ describe 'mysql::config' do
|
|||
'command' => 'mysqladmin -u root -pbar password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin'
|
||||
)}
|
||||
|
||||
it { should contain_file('/root/.my.cnf').with(
|
||||
|
@ -202,4 +216,21 @@ describe 'mysql::config' do
|
|||
|
||||
end
|
||||
|
||||
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
|
||||
expect do
|
||||
subject
|
||||
end.should raise_error(Puppet::Error, /required when ssl is true/)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,6 +12,16 @@ describe 'mysql' do
|
|||
)}
|
||||
end
|
||||
|
||||
describe 'on a freebsd based os' do
|
||||
let :facts do
|
||||
{ :osfamily => 'FreeBSD'}
|
||||
end
|
||||
it { should contain_package('mysql_client').with(
|
||||
:name => 'databases/mysql55-client',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do
|
||||
{:osfamily => 'Redhat'}
|
||||
|
|
|
@ -12,6 +12,16 @@ describe 'mysql::java' do
|
|||
)}
|
||||
end
|
||||
|
||||
describe 'on a freebsd based os' do
|
||||
let :facts do
|
||||
{ :osfamily => 'FreeBSD'}
|
||||
end
|
||||
it { should contain_package('mysql-connector-java').with(
|
||||
:name => 'databases/mysql-connector-java',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do
|
||||
{:osfamily => 'Redhat'}
|
||||
|
|
|
@ -12,6 +12,16 @@ describe 'mysql::python' do
|
|||
)}
|
||||
end
|
||||
|
||||
describe 'on a freebsd based os' do
|
||||
let :facts do
|
||||
{ :osfamily => 'FreeBSD'}
|
||||
end
|
||||
it { should contain_package('python-mysqldb').with(
|
||||
:name => 'databases/py-MySQLdb',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do
|
||||
{:osfamily => 'Redhat'}
|
||||
|
|
|
@ -15,6 +15,17 @@ describe 'mysql::ruby' do
|
|||
)}
|
||||
end
|
||||
|
||||
describe 'on a freebsd based os' do
|
||||
let :facts do
|
||||
{ :osfamily => 'FreeBSD'}
|
||||
end
|
||||
it { should contain_package('ruby_mysql').with(
|
||||
:name => 'ruby-mysql',
|
||||
:ensure => 'present',
|
||||
:provider => 'gem'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do
|
||||
{:osfamily => 'Redhat'}
|
||||
|
|
|
@ -4,7 +4,6 @@ describe 'mysql::server' do
|
|||
let :constant_parameter_defaults do
|
||||
{:config_hash => {},
|
||||
:package_ensure => 'present',
|
||||
:package_name => 'mysql-server'
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -27,10 +26,16 @@ describe 'mysql::server' do
|
|||
describe 'with osfamily specific defaults' do
|
||||
{
|
||||
'Debian' => {
|
||||
:service_name => 'mysql'
|
||||
:service_name => 'mysql',
|
||||
:package_name => 'mysql-server'
|
||||
},
|
||||
'FreeBSD' => {
|
||||
:service_name => 'mysql-server',
|
||||
:package_name => 'databases/mysql55-server'
|
||||
},
|
||||
'Redhat' => {
|
||||
:service_name => 'mysqld'
|
||||
:service_name => 'mysqld',
|
||||
:package_name => 'mysql-server'
|
||||
}
|
||||
}.each do |osfamily, osparams|
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ nice = 0
|
|||
user = mysql
|
||||
socket = <%= socket %>
|
||||
port = <%= port %>
|
||||
basedir = /usr
|
||||
basedir = <%= basedir %>
|
||||
datadir = <%= datadir %>
|
||||
tmpdir = /tmp
|
||||
skip-external-locking
|
||||
|
|
Loading…
Reference in a new issue