From 7c7195ba335f50d7fee0b685edb41d56a7ebce8f Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 19 Jul 2013 15:03:42 -0400 Subject: [PATCH] Refactor MySQL bindings and client packages. The current MySQL module is hard to modify, test, and drop in replacement components to. This work starts out by refactoring the bindings support in MySQL to a completely seperate bindings class in order to reduce the amount of parameters in the main class for a feature that is infrequently used. In addition to this start the movement of client configuration and packages to the mysql::client::* namespace. --- manifests/bindings.pp | 59 +++++++ manifests/{ => bindings}/java.pp | 8 +- manifests/{ => bindings}/perl.pp | 10 +- manifests/{ => bindings}/python.pp | 8 +- manifests/{ => bindings}/ruby.pp | 10 +- manifests/client/install.pp | 11 ++ manifests/init.pp | 36 +--- manifests/params.pp | 167 ++++++++++-------- ...va_spec.rb => mysql_bindings_java_spec.rb} | 2 +- ...rl_spec.rb => mysql_bindings_perl_spec.rb} | 4 +- ..._spec.rb => mysql_bindings_python_spec.rb} | 2 +- ...by_spec.rb => mysql_bindings_ruby_spec.rb} | 4 +- spec/classes/mysql_init_spec.rb | 2 +- spec/system/mysql_bindings_spec.rb | 90 ++++++++++ spec/system/mysql_server_spec.rb | 40 +++++ spec/system/mysql_spec.rb | 28 --- 16 files changed, 318 insertions(+), 163 deletions(-) create mode 100644 manifests/bindings.pp rename manifests/{ => bindings}/java.pp (68%) rename manifests/{ => bindings}/perl.pp (64%) rename manifests/{ => bindings}/python.pp (65%) rename manifests/{ => bindings}/ruby.pp (64%) create mode 100644 manifests/client/install.pp rename spec/classes/{mysql_java_spec.rb => mysql_bindings_java_spec.rb} (97%) rename spec/classes/{mysql_perl_spec.rb => mysql_bindings_perl_spec.rb} (92%) rename spec/classes/{mysql_python_spec.rb => mysql_bindings_python_spec.rb} (97%) rename spec/classes/{mysql_ruby_spec.rb => mysql_bindings_ruby_spec.rb} (92%) create mode 100644 spec/system/mysql_bindings_spec.rb create mode 100644 spec/system/mysql_server_spec.rb delete mode 100644 spec/system/mysql_spec.rb diff --git a/manifests/bindings.pp b/manifests/bindings.pp new file mode 100644 index 0000000..14a6813 --- /dev/null +++ b/manifests/bindings.pp @@ -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' } + +} diff --git a/manifests/java.pp b/manifests/bindings/java.pp similarity index 68% rename from manifests/java.pp rename to manifests/bindings/java.pp index 09b41dd..9602a8a 100644 --- a/manifests/java.pp +++ b/manifests/bindings/java.pp @@ -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': diff --git a/manifests/perl.pp b/manifests/bindings/perl.pp similarity index 64% rename from manifests/perl.pp rename to manifests/bindings/perl.pp index 54665bb..9bb8704 100644 --- a/manifests/perl.pp +++ b/manifests/bindings/perl.pp @@ -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': diff --git a/manifests/python.pp b/manifests/bindings/python.pp similarity index 65% rename from manifests/python.pp rename to manifests/bindings/python.pp index 790d84c..6760368 100644 --- a/manifests/python.pp +++ b/manifests/bindings/python.pp @@ -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': diff --git a/manifests/ruby.pp b/manifests/bindings/ruby.pp similarity index 64% rename from manifests/ruby.pp rename to manifests/bindings/ruby.pp index 3a5b5af..58b0838 100644 --- a/manifests/ruby.pp +++ b/manifests/bindings/ruby.pp @@ -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': diff --git a/manifests/client/install.pp b/manifests/client/install.pp new file mode 100644 index 0000000..487b73d --- /dev/null +++ b/manifests/client/install.pp @@ -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, + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index dd28016..86be2f0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 <| |> diff --git a/manifests/params.pp b/manifests/params.pp index 5a7ec52..2977976 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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: { diff --git a/spec/classes/mysql_java_spec.rb b/spec/classes/mysql_bindings_java_spec.rb similarity index 97% rename from spec/classes/mysql_java_spec.rb rename to spec/classes/mysql_bindings_java_spec.rb index 428d41a..2c8b17a 100644 --- a/spec/classes/mysql_java_spec.rb +++ b/spec/classes/mysql_bindings_java_spec.rb @@ -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 diff --git a/spec/classes/mysql_perl_spec.rb b/spec/classes/mysql_bindings_perl_spec.rb similarity index 92% rename from spec/classes/mysql_perl_spec.rb rename to spec/classes/mysql_bindings_perl_spec.rb index 03037a8..b94c7ae 100644 --- a/spec/classes/mysql_perl_spec.rb +++ b/spec/classes/mysql_bindings_perl_spec.rb @@ -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 diff --git a/spec/classes/mysql_python_spec.rb b/spec/classes/mysql_bindings_python_spec.rb similarity index 97% rename from spec/classes/mysql_python_spec.rb rename to spec/classes/mysql_bindings_python_spec.rb index 502e138..6d5cfc3 100644 --- a/spec/classes/mysql_python_spec.rb +++ b/spec/classes/mysql_bindings_python_spec.rb @@ -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 diff --git a/spec/classes/mysql_ruby_spec.rb b/spec/classes/mysql_bindings_ruby_spec.rb similarity index 92% rename from spec/classes/mysql_ruby_spec.rb rename to spec/classes/mysql_bindings_ruby_spec.rb index c55a757..c16947f 100644 --- a/spec/classes/mysql_ruby_spec.rb +++ b/spec/classes/mysql_bindings_ruby_spec.rb @@ -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 diff --git a/spec/classes/mysql_init_spec.rb b/spec/classes/mysql_init_spec.rb index e4ce308..3e94b32 100644 --- a/spec/classes/mysql_init_spec.rb +++ b/spec/classes/mysql_init_spec.rb @@ -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', diff --git a/spec/system/mysql_bindings_spec.rb b/spec/system/mysql_bindings_spec.rb new file mode 100644 index 0000000..694cf57 --- /dev/null +++ b/spec/system/mysql_bindings_spec.rb @@ -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 diff --git a/spec/system/mysql_server_spec.rb b/spec/system/mysql_server_spec.rb new file mode 100644 index 0000000..6cde536 --- /dev/null +++ b/spec/system/mysql_server_spec.rb @@ -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 diff --git a/spec/system/mysql_spec.rb b/spec/system/mysql_spec.rb deleted file mode 100644 index b291ee9..0000000 --- a/spec/system/mysql_spec.rb +++ /dev/null @@ -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