Merge pull request #232 from apenney/refactor-round-1

Refactor MySQL bindings and client packages.
This commit is contained in:
Ashley Penney 2013-07-23 11:16:05 -07:00
commit 1820b056f0
16 changed files with 318 additions and 163 deletions

59
manifests/bindings.pp Normal file
View file

@ -0,0 +1,59 @@
# Class: mysql::bindings
#
# This class installs various bindings for mysql.
#
# Parameters:
#
# [*java_enable*] - Boolean to determine if we should include the java bindings.
#
# [*perl_enable*] - Boolean to determine if we should include the perl bindings.
#
# [*python_enable*] - Boolean to determine if we should include the python bindings.
#
# [*ruby_enable*] - Boolean to determine if we should include the ruby bindings.
#
# [*java_package_name*] - The name of the java package containing the java connector
#
# [*java_package_ensure*] - State of the java binding packages.
#
# [*perl_package_ensure*] - State of the perl binding packages.
#
# [*perl_package_name*] - The name of the perl mysql package to install
#
# [*perl_package_provider*] - The provider to use when installing the perl package.
#
# [*python_package_ensure*] - State of the python binding packages.
#
# [*python_package_name*] - The name of the python mysql package to install
#
# [*ruby_ensure*] - State of the ruby binding packages.
#
# [*ruby_package_name*] - The name of the ruby mysql package to install
#
# [*ruby_package_provider*] - The provider to use when installing the ruby package.
#
class mysql::bindings (
# Boolean to determine if we should include the classes.
$java_enable = false,
$perl_enable = false,
$python_enable = false,
$ruby_enable = false,
# Settings for the various classes.
$java_package_ensure = $mysql::params::java_package_ensure,
$java_package_name = $mysql::params::java_package_name,
$perl_package_ensure = $mysql::params::perl_package_ensure,
$perl_package_name = $mysql::params::perl_package_name,
$perl_package_provider = $mysql::params::perl_package_provider,
$python_package_ensure = $mysql::params::python_package_ensure,
$python_package_name = $mysql::params::python_package_name,
$ruby_package_ensure = $mysql::params::ruby_package_ensure,
$ruby_package_name = $mysql::params::ruby_package_name,
$ruby_package_provider = $mysql::params::ruby_package_provider,
) inherits mysql::params {
if $java_enable { include '::mysql::bindings::java' }
if $perl_enable { include '::mysql::bindings::perl' }
if $python_enable { include '::mysql::bindings::python' }
if $ruby_enable { include '::mysql::bindings::ruby' }
}

View file

@ -1,4 +1,4 @@
# Class: mysql::java
# Class: mysql::bindings::java
#
# This class installs the mysql-java-connector.
#
@ -11,9 +11,9 @@
#
# Sample Usage:
#
class mysql::java (
$package_ensure = 'present',
$package_name = $mysql::java_package_name
class mysql::bindings::java (
$package_ensure = $mysql::bindings::java_package_ensure,
$package_name = $mysql::bindings::java_package_name
) inherits mysql {
package { 'mysql-connector-java':

View file

@ -1,4 +1,4 @@
# Class: mysql::perl
# Class: mysql::bindings::perl
#
# installs the perl bindings for mysql
#
@ -13,10 +13,10 @@
#
# Sample Usage:
#
class mysql::perl (
$package_ensure = 'present',
$package_name = $mysql::perl_package_name,
$package_provider = $mysql::perl_package_provider
class mysql::bindings::perl (
$package_ensure = $mysql::bindings::perl_package_ensure,
$package_name = $mysql::bindings::perl_package_name,
$package_provider = $mysql::bindings::perl_package_provider
) inherits mysql {
package{ 'perl_mysql':

View file

@ -1,4 +1,4 @@
# Class: mysql::python
# Class: mysql::bindings::python
#
# This class installs the python libs for mysql.
#
@ -12,9 +12,9 @@
#
# Sample Usage:
#
class mysql::python(
$package_ensure = 'present',
$package_name = $mysql::python_package_name
class mysql::bindings::python(
$package_ensure = $mysql::bindings::python_package_ensure,
$package_name = $mysql::bindings::python_package_name
) inherits mysql {
package { 'python-mysqldb':

View file

@ -1,4 +1,4 @@
# Class: mysql::ruby
# Class: mysql::bindings::ruby
#
# installs the ruby bindings for mysql
#
@ -13,10 +13,10 @@
#
# Sample Usage:
#
class mysql::ruby (
$package_ensure = 'present',
$package_name = $mysql::ruby_package_name,
$package_provider = $mysql::ruby_package_provider
class mysql::bindings::ruby (
$package_ensure = $mysql::bindings::ruby_package_ensure,
$package_name = $mysql::bindings::ruby_package_name,
$package_provider = $mysql::bindings::ruby_package_provider
) inherits mysql {
package{ 'ruby_mysql':

View file

@ -0,0 +1,11 @@
class mysql::client::install(
$package_name = $mysql::client_package_name,
$package_ensure = $mysql::client_package_ensure
) {
package { 'mysql_client':
ensure => $package_ensure,
name => $package_name,
}
}

View file

@ -10,6 +10,8 @@
#
# [*client_package_name*] - The name of the mysql client package.
#
# [*client_package_ensure*] - State of the client package.
#
# [*config_file*] - The location of the server config file
#
# [*config_template*] - The template to use to generate my.cnf.
@ -22,8 +24,6 @@
#
# [*etc_root_password*] - Whether or not to add the mysql root password to /etc/my.cnf
#
# [*java_package_name*] - The name of the java package containing the java connector
#
# [*log_error*] - Where to log errors
#
# [*manage_config_file*] - if the config file should be managed (default: true)
@ -38,10 +38,6 @@
#
# [*package_name*] - legacy parameter used to specify the client package. Should not be used going forward
#
# [*perl_package_name*] - The name of the perl mysql package to install
#
# [*perl_package_provider*] - The installation suite to use when installing the perl package.
#
# [*php_package_name*] - The name of the phpmysql package to install
#
# [*pidfile*] - The location mysql will expect the pidfile to be, and will put it when starting the service.
@ -50,19 +46,12 @@
#
# [*purge_conf_dir*] - Value fed to recurse and purge parameters of the /etc/mysql/conf.d resource
#
# [*python_package_name*] - The name of the python mysql package to install
#
# [*restart*] - Whether to restart mysqld (true/false)
#
# [*root_group*] - Use specified group for root-owned files
#
# [*root_password*] - The root MySQL password to use
#
# [*ruby_package_name*] - The name of the ruby mysql package to install
#
# [*ruby_package_provider*] - The installation suite to use when installing the ruby package.
# FreeBSD Does not use this.
#
# [*server_package_ensure*] - ensure value for server packages.
#
# [*server_package_name*] - The name of the server package to install
@ -91,33 +80,27 @@ class mysql(
$basedir = $mysql::params::basedir,
$bind_address = $mysql::params::bind_address,
$client_package_name = $mysql::params::client_package_name,
$client_package_ensure = $mysql::params::client_package_ensure,
$config_file = $mysql::params::config_file,
$config_template = $mysql::params::config_template,
$datadir = $mysql::params::datadir,
$tmpdir = $mysql::params::tmpdir,
$default_engine = $mysql::params::default_engine,
$etc_root_password = $mysql::params::etc_root_password,
$java_package_name = $mysql::params::java_package_name,
$log_error = $mysql::params::log_error,
$manage_config_file = true,
$manage_service = $mysql::params::manage_service,
$max_allowed_packet = $mysql::params::max_allowed_packet,
$old_root_password = $mysql::params::old_root_password,
$package_ensure = $mysql::params::package_ensure,
$package_name = undef,
$perl_package_name = $mysql::params::perl_package_name,
$perl_package_provider = $mysql::params::perl_package_provider,
$php_package_name = $mysql::params::php_package_name,
$pidfile = $mysql::params::pidfile,
$port = $mysql::params::port,
$purge_conf_dir = $mysql::params::purge_conf_dir,
$python_package_name = $mysql::params::python_package_name,
$max_connections = $mysql::params::max_connections,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
$root_password = $mysql::params::root_password,
$ruby_package_name = $mysql::params::ruby_package_name,
$ruby_package_provider = $mysql::params::ruby_package_provider,
$server_package_name = $mysql::params::server_package_name,
$service_name = $mysql::params::service_name,
$service_provider = $mysql::params::service_provider,
@ -127,16 +110,9 @@ class mysql(
$ssl_cert = $mysql::params::ssl_cert,
$ssl_key = $mysql::params::ssl_key
) inherits mysql::params{
if $package_name {
warning('Using $package_name has been deprecated in favor of $client_package_name and will be removed.')
$client_package_name_real = $package_name
} else {
$client_package_name_real = $client_package_name
}
package { 'mysql_client':
ensure => $package_ensure,
name => $client_package_name_real,
}
include '::mysql::client::install'
include '::mysql::bindings'
Class['mysql::config'] -> Mysql::Db <| |>

View file

@ -12,28 +12,35 @@
#
class mysql::params {
$bind_address = '127.0.0.1'
$config_template = 'mysql/my.cnf.erb'
$default_engine = 'UNSET'
$etc_root_password = false
$manage_service = true
$old_root_password = ''
$package_ensure = 'present'
$purge_conf_dir = false
$max_connections = 151
$port = 3306
$max_allowed_packet = '16M'
$root_password = 'UNSET'
$restart = true
$ssl = false
$key_buffer = '16M'
$thread_stack = '256K'
$thread_cache_size = 8
$myisam_recover = 'BACKUP'
$query_cache_limit = '1M'
$query_cache_size = '16M'
$expire_logs_days = 10
$max_binlog_size = '100M'
$bind_address = '127.0.0.1'
$client_package_ensure = 'present'
$config_template = 'mysql/my.cnf.erb'
$default_engine = 'UNSET'
$etc_root_password = false
$expire_logs_days = 10
$key_buffer = '16M'
$manage_service = true
$max_allowed_packet = '16M'
$max_binlog_size = '100M'
$max_connections = 151
$myisam_recover = 'BACKUP'
$old_root_password = ''
$package_ensure = 'present'
$port = 3306
$purge_conf_dir = false
$query_cache_limit = '1M'
$query_cache_size = '16M'
$restart = true
$root_password = 'UNSET'
$ssl = false
$thread_cache_size = 8
$thread_stack = '256K'
# mysql::bindings
$java_package_ensure = 'present'
$perl_package_ensure = 'present'
$python_package_ensure = 'present'
$ruby_package_ensure = 'present'
case $::operatingsystem {
'Ubuntu': {
@ -56,82 +63,85 @@ class mysql::params {
$basedir = '/usr'
$config_file = '/etc/my.cnf'
$datadir = '/var/lib/mysql'
$tmpdir = '/tmp'
$java_package_name = 'mysql-connector-java'
$log_error = '/var/log/mysqld.log'
$perl_package_name = 'perl-DBD-MySQL'
$php_package_name = 'php-mysql'
$pidfile = '/var/run/mysqld/mysqld.pid'
$python_package_name = 'MySQL-python'
$root_group = 'root'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
$service_name = 'mysqld'
$socket = '/var/lib/mysql/mysql.sock'
$ssl_ca = '/etc/mysql/cacert.pem'
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-DBD-MySQL'
$python_package_name = 'MySQL-python'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
}
'Suse': {
$basedir = '/usr'
$datadir = '/var/lib/mysql'
$tmpdir = '/tmp'
$service_name = 'mysql'
$config_file = '/etc/my.cnf'
$client_package_name = $::operatingsystem ? {
/OpenSuSE/ => 'mysql-community-server-client',
/(SLES|SLED)/ => 'mysql-client',
}
$server_package_name = $::operatingsystem ? {
/OpenSuSE/ => 'mysql-community-server',
/(SLES|SLED)/ => 'mysql',
}
$socket = $::operatingsystem ? {
/OpenSuSE/ => '/var/run/mysql/mysql.sock',
/(SLES|SLED)/ => '/var/lib/mysql/mysql.sock',
}
$pidfile = $::operatingsystem ? {
/OpenSuSE/ => '/var/run/mysql/mysqld.pid',
/(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid',
}
$config_file = '/etc/my.cnf'
$datadir = '/var/lib/mysql'
$log_error = $::operatingsystem ? {
/OpenSuSE/ => '/var/log/mysql/mysqld.log',
/(SLES|SLED)/ => '/var/log/mysqld.log',
}
$ruby_package_name = $::operatingsystem ? {
/OpenSuSE/ => 'rubygem-mysql',
/(SLES|SLED)/ => 'ruby-mysql',
}
$python_package_name = 'python-mysql'
$perl_package_name = 'perl-DBD-mysql'
$java_package_name = 'mysql-connector-java'
}
$pidfile = $::operatingsystem ? {
/OpenSuSE/ => '/var/run/mysql/mysqld.pid',
/(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid',
}
$root_group = 'root'
$server_package_name = $::operatingsystem ? {
/OpenSuSE/ => 'mysql-community-server',
/(SLES|SLED)/ => 'mysql',
}
$service_name = 'mysql'
$socket = $::operatingsystem ? {
/OpenSuSE/ => '/var/run/mysql/mysql.sock',
/(SLES|SLED)/ => '/var/lib/mysql/mysql.sock',
}
$ssl_ca = '/etc/mysql/cacert.pem'
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-DBD-mysql'
$python_package_name = 'python-mysql'
$ruby_package_name = $::operatingsystem ? {
/OpenSuSE/ => 'rubygem-mysql',
/(SLES|SLED)/ => 'ruby-mysql',
}
}
'Debian': {
$basedir = '/usr'
$datadir = '/var/lib/mysql'
$tmpdir = '/tmp'
$service_name = 'mysql'
$client_package_name = 'mysql-client'
$server_package_name = 'mysql-server'
$socket = '/var/run/mysqld/mysqld.sock'
$pidfile = '/var/run/mysqld/mysqld.pid'
$config_file = '/etc/mysql/my.cnf'
$datadir = '/var/lib/mysql'
$log_error = '/var/log/mysql/error.log'
$perl_package_name = 'libdbd-mysql-perl'
$ruby_package_name = 'libmysql-ruby'
$python_package_name = 'python-mysqldb'
$php_package_name = 'php5-mysql'
$java_package_name = 'libmysql-java'
$pidfile = '/var/run/mysqld/mysqld.pid'
$root_group = 'root'
$server_package_name = 'mysql-server'
$service_name = 'mysql'
$socket = '/var/run/mysqld/mysqld.sock'
$ssl_ca = '/etc/mysql/cacert.pem'
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
# mysql::bindings
$java_package_name = 'libmysql-java'
$perl_package_name = 'libdbd-mysql-perl'
$python_package_name = 'python-mysqldb'
$ruby_package_name = 'libmysql-ruby'
}
'FreeBSD': {
@ -145,41 +155,42 @@ class mysql::params {
$pidfile = '/var/db/mysql/mysql.pid'
$config_file = '/var/db/mysql/my.cnf'
$log_error = "/var/db/mysql/${::hostname}.err"
$perl_package_name = 'p5-DBD-mysql'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
$python_package_name = 'databases/py-MySQLdb'
$php_package_name = 'php5-mysql'
$java_package_name = 'databases/mysql-connector-java'
$root_group = 'wheel'
$ssl_ca = undef
$ssl_cert = undef
$ssl_key = undef
# mysql::bindings
$java_package_name = 'databases/mysql-connector-java'
$perl_package_name = 'p5-DBD-mysql'
$python_package_name = 'databases/py-MySQLdb'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
}
default: {
case $::operatingsystem {
'Amazon': {
$basedir = '/usr'
$datadir = '/var/lib/mysql'
$tmpdir = '/tmp'
$service_name = 'mysqld'
$client_package_name = 'mysql'
$server_package_name = 'mysql-server'
$socket = '/var/lib/mysql/mysql.sock'
$config_file = '/etc/my.cnf'
$datadir = '/var/lib/mysql'
$log_error = '/var/log/mysqld.log'
# XXX validate...
$perl_package_name = 'perl-DBD-MySQL'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
$python_package_name = 'MySQL-python'
$php_package_name = 'php-mysql'
$java_package_name = 'mysql-connector-java'
$root_group = 'root'
$server_package_name = 'mysql-server'
$service_name = 'mysqld'
$socket = '/var/lib/mysql/mysql.sock'
$ssl_ca = '/etc/mysql/cacert.pem'
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-DBD-MySQL'
$python_package_name = 'MySQL-python'
$ruby_package_name = 'ruby-mysql'
$ruby_package_provider = 'gem'
}
default: {

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'mysql::java' do
describe 'mysql::bindings::java' do
describe 'on a debian based os' do
let :facts do

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'mysql::perl' do
describe 'mysql::bindings::perl' do
describe 'on a debian based os' do
let :facts do
@ -9,8 +9,6 @@ describe 'mysql::perl' do
it { should contain_package('perl_mysql').with(
:name => 'libdbd-mysql-perl',
:ensure => 'present',
# TODO is this what we want? does this actually work
# if the provider is blank
:provider => ''
)}
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'mysql::python' do
describe 'mysql::bindings::python' do
describe 'on a debian based os' do
let :facts do

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'mysql::ruby' do
describe 'mysql::bindings::ruby' do
describe 'on a debian based os' do
let :facts do
@ -9,8 +9,6 @@ describe 'mysql::ruby' do
it { should contain_package('ruby_mysql').with(
:name => 'libmysql-ruby',
:ensure => 'present',
# TODO is this what we want? does this actually work
# if the provider is blank
:provider => ''
)}
end

View file

@ -32,7 +32,7 @@ describe 'mysql' do
)}
describe 'when parameters are supplied' do
let :params do
{:package_ensure => 'latest', :client_package_name => 'mysql_client'}
{:client_package_ensure => 'latest', :client_package_name => 'mysql_client'}
end
it { should contain_package('mysql_client').with(
:name => 'mysql_client',

View file

@ -0,0 +1,90 @@
require 'spec_helper_system'
describe 'mysql::bindings class' do
let(:os) {
node.facts['osfamily']
}
case node.facts['osfamily']
when 'RedHat'
java_package = 'mysql-connector-java'
perl_package = 'perl-DBD-MySQL'
python_package = 'MySQL-python'
ruby_package = 'ruby-mysql'
when 'Suse'
java_package = 'mysql-connector-java'
perl_package = 'perl-DBD-MySQL'
python_package = 'python-mysql'
case node.facts['operatingsystem']
when /OpenSuSE/
ruby_package = 'rubygem-mysql'
when /(SLES|SLED)/
ruby_package = 'ruby-mysql'
end
when 'Debian'
java_package = 'libmysql-java'
perl_package = 'libdbd-mysql-perl'
python_package = 'python-mysqldb'
ruby_package = 'libmysql-ruby'
when 'FreeBSD'
java_package = 'databases/mysql-connector-java'
perl_package = 'p5-DBD-mysql'
python_package = 'databases/py-MySQLdb'
ruby_package = 'ruby-mysql'
else
case node.facts['operatingsystem']
when 'Amazon'
java_package = 'mysql-connector-java'
perl_package = 'perl-DBD-MySQL'
python_package = 'MySQL-python'
ruby_package = 'ruby-mysql'
end
end
describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'mysql::bindings': }
EOS
# Run it twice and test for idempotency
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.refresh
r.exit_code.should be_zero
end
end
end
describe 'enabling bindings' do
it 'should work with no errors' do
puppet_apply(%{
class { 'mysql::bindings':
java_enable => true,
perl_enable => true,
python_enable => true,
ruby_enable => true,
}
})
end
describe package(java_package) do
it { should be_installed }
end
describe package(perl_package) do
it { should be_installed }
end
describe package(python_package) do
it { should be_installed }
end
describe package(ruby_package) do
it { should be_installed }
end
end
end

View file

@ -0,0 +1,40 @@
require 'spec_helper_system'
describe 'mysql class' do
case node.facts['osfamily']
when 'RedHat'
package_name = 'mysql-server'
service_name = 'mysqld'
when 'Suse'
package_name = 'mysql-community-server'
service_name = 'mysql'
when 'Debian'
package_name = 'mysql-server'
service_name = 'mysql'
end
describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'mysql::server': }
EOS
# Run it twice and test for idempotency
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.refresh
r.exit_code.should be_zero
end
end
end
describe package(package_name) do
it { should be_installed }
end
describe service(service_name) do
it { should be_running }
it { should be_enabled }
end
end

View file

@ -1,28 +0,0 @@
require 'spec_helper_system'
describe 'mysql class' do
describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'mysql': }
EOS
# Run it twice and test for idempotency
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.refresh
r.exit_code.should be_zero
end
end
end
describe package('mysql') do
it { should be_installed }
end
describe service('mysql') do
it { should_not be_running }
it { should_not be_enabled }
end
end