Merge pull request #278 from apenney/fix-globals

Remove mysql::globals.
This commit is contained in:
Ashley Penney 2013-09-24 15:17:18 -07:00
commit c53390a30a
12 changed files with 106 additions and 119 deletions

View file

@ -30,7 +30,7 @@ longer work with the previous classes and configuration as before. We've
attempted to handle backwards compatibility automatically by adding a attempted to handle backwards compatibility automatically by adding a
`attempt_compatibility_mode` parameter to the main mysql class. If you set `attempt_compatibility_mode` parameter to the main mysql class. If you set
this to true it will attempt to map your previous parameters into the new this to true it will attempt to map your previous parameters into the new
mysql::globals class. mysql::server class.
###WARNING ###WARNING
@ -49,27 +49,24 @@ live. Even if it's just a no-op and a manual comparision. Please be careful!
If you just want a server installing with the default options you can run If you just want a server installing with the default options you can run
include '::mysql::server'. If you need to customize options, such as the root include '::mysql::server'. If you need to customize options, such as the root
password or /etc/my.cnf settings then you can also include mysql::globals and password or /etc/my.cnf settings then you can also include mysql::server and
pass in an override hash as seen below: pass in an override hash as seen below:
```puppet ```puppet
class { '::mysql::globals': class { '::mysql::server':
override_options => { 'mysqld' => { 'max_connections' => '1024' } } override_options => { 'mysqld' => { 'max_connections' => '1024' } }
} }
``` ```
##Usage ##Usage
The interactions with this module are split between mysql::globals and several All interaction for the server is done via mysql::server. To install the
other classes, mysql::server, mysql::client, and mysql::bindings. client you use mysql::client, and to install bindings you can use
mysql::bindings.
###mysql::globals ###Overrides
This class exists as a way to easily share values between the other mysql The hash structure for overrides in mysql::server is as follows:
classes. You can pass an override_options into this class to replace elements
of the existing default hash.
The hash structure for overrides is as follows:
```puppet ```puppet
override_options = { override_options = {
@ -91,7 +88,7 @@ care if thing is alone or set to a value, it'll happily accept both.
To add custom mysql configuration you can drop additional files into To add custom mysql configuration you can drop additional files into
/etc/mysql/conf.d/ in order to override settings or add additional ones (if you /etc/mysql/conf.d/ in order to override settings or add additional ones (if you
choose not to use override_options in mysql::globals). This location is choose not to use override_options in mysql::server). This location is
hardcoded into the my.cnf template file. hardcoded into the my.cnf template file.
##Reference ##Reference
@ -99,7 +96,6 @@ hardcoded into the my.cnf template file.
###Classes ###Classes
####Public classes ####Public classes
* mysql::globals: Settings and customizations for MySQL.
* mysql::server: Installs and configures MySQL. * mysql::server: Installs and configures MySQL.
* mysql::server::account_security: Deletes default MySQL accounts. * mysql::server::account_security: Deletes default MySQL accounts.
* mysql::server::monitor: Sets up a monitoring user. * mysql::server::monitor: Sets up a monitoring user.
@ -121,7 +117,15 @@ hardcoded into the my.cnf template file.
###Parameters ###Parameters
####mysql::globals ####mysql::server
#####`root_password`
What is the MySQL root password. Puppet will attempt to set it to this and update /root/.my.cnf.
#####`old_root_password`
What was the previous root password (REQUIRED if you wish to change the root password via Puppet.)
#####`override_options` #####`override_options`
@ -158,16 +162,6 @@ Should the service be restarted when things change?
What is the group used for root? What is the group used for root?
####mysql::server
#####`root_password`
What is the MySQL root password. Puppet will attempt to set it to this and update /root/.my.cnf.
#####`old_root_password`
What was the previous root password (REQUIRED if you wish to change the root password via Puppet.)
#####`package_ensure` #####`package_ensure`
What to set the package to. Can be present, absent, or version. What to set the package to. Can be present, absent, or version.

View file

@ -22,7 +22,7 @@ class mysql::bindings (
$ruby_package_ensure = $mysql::params::ruby_package_ensure, $ruby_package_ensure = $mysql::params::ruby_package_ensure,
$ruby_package_name = $mysql::params::ruby_package_name, $ruby_package_name = $mysql::params::ruby_package_name,
$ruby_package_provider = $mysql::params::ruby_package_provider $ruby_package_provider = $mysql::params::ruby_package_provider
) inherits mysql::globals { ) inherits mysql::params {
if $java_enable { include '::mysql::bindings::java' } if $java_enable { include '::mysql::bindings::java' }
if $perl_enable { include '::mysql::bindings::perl' } if $perl_enable { include '::mysql::bindings::perl' }

View file

@ -1,7 +1,7 @@
# #
class mysql::client ( class mysql::client (
$bindings_enable = false, $bindings_enable = false,
) inherits mysql::globals { ) inherits mysql::params {
include '::mysql::client::install' include '::mysql::client::install'

View file

@ -1,6 +1,6 @@
class mysql::client::install( class mysql::client::install(
$package_name = $mysql::globals::client_package_name, $package_name = $mysql::params::client_package_name,
$package_ensure = $mysql::globals::client_package_ensure $package_ensure = $mysql::params::client_package_ensure
) { ) {
package { 'mysql_client': package { 'mysql_client':

View file

@ -1,70 +0,0 @@
# See README.md for more details.
class mysql::globals (
$config_file = $mysql::params::config_file,
$manage_config_file = $mysql::params::manage_config_file,
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
$purge_conf_dir = $mysql::params::purge_conf_dir,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
) inherits mysql::params {
case $::operatingsystem {
'Ubuntu': {
$service_provider = upstart
}
default: {
$service_provider = undef
}
}
$default_options = {
'client' => {
'port' => '3306',
'socket' => $mysql::params::socket,
},
'mysqld_safe' => {
'nice' => '0',
'log_error' => $mysql::params::log_error,
'socket' => $mysql::params::socket,
},
'mysqld' => {
'basedir' => $mysql::params::basedir,
'bind_address' => '127.0.0.1',
'datadir' => $mysql::params::datadir,
'expire_logs_days' => '10',
'key_buffer' => '16M',
'log_error' => $mysql::params::log_error,
'max_allowed_packet' => '16M',
'max_binlog_size' => '100M',
'max_connections' => '151',
'myisam_recover' => 'BACKUP',
'pid_file' => $mysql::params::pidfile,
'port' => '3306',
'query_cache_limit' => '1M',
'query_cache_size' => '16M',
'skip-external-locking' => true,
'socket' => $mysql::params::socket,
'ssl' => false,
'ssl-ca' => $mysql::params::ssl_ca,
'ssl-cert' => $mysql::params::ssl_cert,
'ssl-key' => $mysql::params::ssl_key,
'thread_cache_size' => '8',
'thread_stack' => '256K',
'tmpdir' => $mysql::params::tmpdir,
'user' => 'mysql',
},
'mysqldump' => {
'max_allowed_packets' => '16M',
'quick' => true,
'quote-names' => true,
},
'isamchk' => {
'key_buffer' => '16M',
},
}
# Create a merged together set of options. Rightmost hashes win over left.
$options = merge($default_options, $override_options)
}

View file

@ -37,7 +37,7 @@ class mysql(
if $attempt_compatibility_mode { if $attempt_compatibility_mode {
notify { "An attempt has been made below to automatically apply your custom notify { "An attempt has been made below to automatically apply your custom
settings to mysql::globals. Please verify this works in a safe test settings to mysql::server. Please verify this works in a safe test
environment.": } environment.": }
$override_options = { $override_options = {
@ -81,20 +81,20 @@ class mysql(
$filtered_options = mysql_strip_hash($override_options) $filtered_options = mysql_strip_hash($override_options)
validate_hash($filtered_options) validate_hash($filtered_options)
notify { $filtered_options: } notify { $filtered_options: }
class { 'mysql::globals': class { 'mysql::server':
override_options => $filtered_options, override_options => $filtered_options,
} }
} else { } else {
fail("ERROR: This class has been deprecated and the functionality moved fail("ERROR: This class has been deprecated and the functionality moved
into mysql::globals. If you run mysql::server without correctly calling into mysql::server. If you run mysql::server without correctly calling
mysql:: globals with the new override_options hash syntax you will revert mysql:: server with the new override_options hash syntax you will revert
your MySQL to the stock settings. Do not proceed without removing this your MySQL to the stock settings. Do not proceed without removing this
class and using mysql::globals correctly. class and using mysql::server correctly.
If you are brave you may set attempt_compatibility_mode in this class which If you are brave you may set attempt_compatibility_mode in this class which
attempts to automap the previous settings to appropriate calls to attempts to automap the previous settings to appropriate calls to
mysql::globals") mysql::server")
} }
} }

View file

@ -166,4 +166,59 @@ class mysql::params {
} }
} }
case $::operatingsystem {
'Ubuntu': {
$service_provider = upstart
}
default: {
$service_provider = undef
}
}
$default_options = {
'client' => {
'port' => '3306',
'socket' => $mysql::params::socket,
},
'mysqld_safe' => {
'nice' => '0',
'log_error' => $mysql::params::log_error,
'socket' => $mysql::params::socket,
},
'mysqld' => {
'basedir' => $mysql::params::basedir,
'bind_address' => '127.0.0.1',
'datadir' => $mysql::params::datadir,
'expire_logs_days' => '10',
'key_buffer' => '16M',
'log_error' => $mysql::params::log_error,
'max_allowed_packet' => '16M',
'max_binlog_size' => '100M',
'max_connections' => '151',
'myisam_recover' => 'BACKUP',
'pid_file' => $mysql::params::pidfile,
'port' => '3306',
'query_cache_limit' => '1M',
'query_cache_size' => '16M',
'skip-external-locking' => true,
'socket' => $mysql::params::socket,
'ssl' => false,
'ssl-ca' => $mysql::params::ssl_ca,
'ssl-cert' => $mysql::params::ssl_cert,
'ssl-key' => $mysql::params::ssl_key,
'thread_cache_size' => '8',
'thread_stack' => '256K',
'tmpdir' => $mysql::params::tmpdir,
'user' => 'mysql',
},
'mysqldump' => {
'max_allowed_packets' => '16M',
'quick' => true,
'quote-names' => true,
},
'isamchk' => {
'key_buffer' => '16M',
},
}
} }

View file

@ -4,16 +4,23 @@ class mysql::server (
$enabled = undef, $enabled = undef,
$manage_service = undef, $manage_service = undef,
# #
$config_file = $mysql::params::config_file,
$manage_config_file = $mysql::params::manage_config_file,
$old_root_password = $mysql::params::old_root_password, $old_root_password = $mysql::params::old_root_password,
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
$package_ensure = $mysql::params::server_package_ensure, $package_ensure = $mysql::params::server_package_ensure,
$package_name = $mysql::params::server_package_name, $package_name = $mysql::params::server_package_name,
$purge_conf_dir = $mysql::params::purge_conf_dir,
$remove_default_accounts = false, $remove_default_accounts = false,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
$root_password = $mysql::params::root_password, $root_password = $mysql::params::root_password,
$service_enabled = $mysql::params::server_service_enabled, $service_enabled = $mysql::params::server_service_enabled,
$service_manage = $mysql::params::server_service_manage, $service_manage = $mysql::params::server_service_manage,
$service_name = $mysql::params::server_service_name, $service_name = $mysql::params::server_service_name,
$service_provider = $mysql::params::server_service_provider $service_provider = $mysql::params::server_service_provider
) inherits mysql::globals { ) inherits mysql::params {
# Deprecated parameters. # Deprecated parameters.
if $enabled { if $enabled {
@ -29,6 +36,9 @@ class mysql::server (
$real_service_manage = $service_manage $real_service_manage = $service_manage
} }
# Create a merged together set of options. Rightmost hashes win over left.
$options = merge($mysql::params::default_options, $override_options)
Class['mysql::server::root_password'] -> Mysql::Db <| |> Class['mysql::server::root_password'] -> Mysql::Db <| |>
include '::mysql::server::install' include '::mysql::server::install'

View file

@ -1,9 +1,11 @@
# See README.me for options. # See README.me for options.
class mysql::server::config { class mysql::server::config {
$options = $mysql::server::options
File { File {
owner => 'root', owner => 'root',
group => $mysql::globals::root_group, group => $mysql::server::root_group,
mode => '0400', mode => '0400',
notify => Class['mysql::server::service'], notify => Class['mysql::server::service'],
} }
@ -16,12 +18,12 @@ class mysql::server::config {
file { '/etc/mysql/conf.d': file { '/etc/mysql/conf.d':
ensure => directory, ensure => directory,
mode => '0755', mode => '0755',
recurse => $mysql::globals::purge_conf_dir, recurse => $mysql::server::purge_conf_dir,
purge => $mysql::globals::purge_conf_dir, purge => $mysql::server::purge_conf_dir,
} }
if $mysql::globals::manage_config_file { if $mysql::server::manage_config_file {
file { $mysql::globals::config_file: file { $mysql::server::config_file:
content => template('mysql/my.cnf.erb'), content => template('mysql/my.cnf.erb'),
mode => '0644', mode => '0644',
} }

View file

@ -1,7 +1,7 @@
# #
class mysql::server::root_password { class mysql::server::root_password {
$options = $mysql::globals::options $options = $mysql::server::options
# manage root password if it is set # manage root password if it is set
if $mysql::server::root_password != 'UNSET' { if $mysql::server::root_password != 'UNSET' {

View file

@ -3,8 +3,7 @@ require 'spec_helper_system'
describe 'mysql::server::backup class' do describe 'mysql::server::backup class' do
context 'should work with no errors' do context 'should work with no errors' do
pp = <<-EOS pp = <<-EOS
class { 'mysql::globals': override_options => { 'root_password' => 'password' } } class { 'mysql::server': override_options => { 'root_password' => 'password' } }
class { 'mysql::server': }
mysql::db { 'backup1': mysql::db { 'backup1':
user => 'backup', user => 'backup',
password => 'secret', password => 'secret',
@ -43,8 +42,7 @@ describe 'mysql::server::backup class' do
context 'should create one file per database' do context 'should create one file per database' do
pp = <<-EOS pp = <<-EOS
class { 'mysql::globals': override_options => { 'root_password' => 'password' } } class { 'mysql::server': override_options => { 'root_password' => 'password' } }
class { 'mysql::server': }
mysql::db { 'backup1': mysql::db { 'backup1':
user => 'backup', user => 'backup',
password => 'secret', password => 'secret',

View file

@ -5,8 +5,7 @@ describe 'mysql::db define' do
# Using puppet_apply as a helper # Using puppet_apply as a helper
it 'should work with no errors' do it 'should work with no errors' do
pp = <<-EOS pp = <<-EOS
class { 'mysql::globals': override_options => { 'root_password' => 'password' } } class { 'mysql::server': override_options => { 'root_password' => 'password' } }
class { 'mysql::server': }
mysql::db { 'spec1': mysql::db { 'spec1':
user => 'root1', user => 'root1',
password => 'password', password => 'password',
@ -32,8 +31,7 @@ describe 'mysql::db define' do
# Using puppet_apply as a helper # Using puppet_apply as a helper
it 'should work with no errors' do it 'should work with no errors' do
pp = <<-EOS pp = <<-EOS
class { 'mysql::globals': override_options => { 'root_password' => 'password' } } class { 'mysql::server': override_options => { 'root_password' => 'password' } }
class { 'mysql::server': }
file { '/tmp/spec.sql': file { '/tmp/spec.sql':
ensure => file, ensure => file,
content => 'CREATE TABLE table1 (id int);', content => 'CREATE TABLE table1 (id int);',