From 05d7e23fe8833ec1caf8ec9a5e7a6c70623a614a Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Tue, 1 May 2012 21:42:34 -0700 Subject: [PATCH 1/2] (#14330) Add support for FreeBSD Note: ssl_ca, ssl_cert, and ssl_key do not have sane defaults in FreeBSD. Setting ssl to true will require setting the parameters mentioned above. --- manifests/config.pp | 19 ++++++++++++--- manifests/params.pp | 40 ++++++++++++++++++++++++++----- spec/classes/mysql_config_spec.rb | 6 ++--- templates/my.cnf.erb | 2 +- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 2274f37..fc98efe 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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'], } diff --git a/manifests/params.pp b/manifests/params.pp index 95ea2d5..1cec72f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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") } } diff --git a/spec/classes/mysql_config_spec.rb b/spec/classes/mysql_config_spec.rb index 39c07f1..2bc7bbc 100644 --- a/spec/classes/mysql_config_spec.rb +++ b/spec/classes/mysql_config_spec.rb @@ -48,7 +48,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 +67,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 @@ -175,7 +175,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( diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb index 5e434ae..e09c7c9 100644 --- a/templates/my.cnf.erb +++ b/templates/my.cnf.erb @@ -8,7 +8,7 @@ nice = 0 user = mysql socket = <%= socket %> port = <%= port %> -basedir = /usr +basedir = <%= basedir %> datadir = <%= datadir %> tmpdir = /tmp skip-external-locking From f572b90f9e268389aed7ee509341bcb326da973e Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Wed, 9 May 2012 21:55:16 -0700 Subject: [PATCH 2/2] (#14330) Add FreeBSD spec tests --- spec/classes/mysql_config_spec.rb | 47 +++++++++++++++++++++++++------ spec/classes/mysql_init_spec.rb | 10 +++++++ spec/classes/mysql_java_spec.rb | 10 +++++++ spec/classes/mysql_python_spec.rb | 10 +++++++ spec/classes/mysql_ruby_spec.rb | 11 ++++++++ spec/classes/mysql_server_spec.rb | 11 ++++++-- 6 files changed, 88 insertions(+), 11 deletions(-) diff --git a/spec/classes/mysql_config_spec.rb b/spec/classes/mysql_config_spec.rb index 2bc7bbc..c71d0ca 100644 --- a/spec/classes/mysql_config_spec.rb +++ b/spec/classes/mysql_config_spec.rb @@ -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| @@ -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' )} @@ -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 diff --git a/spec/classes/mysql_init_spec.rb b/spec/classes/mysql_init_spec.rb index be91c0c..de7cb65 100644 --- a/spec/classes/mysql_init_spec.rb +++ b/spec/classes/mysql_init_spec.rb @@ -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'} diff --git a/spec/classes/mysql_java_spec.rb b/spec/classes/mysql_java_spec.rb index d47aaa6..6a4387f 100644 --- a/spec/classes/mysql_java_spec.rb +++ b/spec/classes/mysql_java_spec.rb @@ -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'} diff --git a/spec/classes/mysql_python_spec.rb b/spec/classes/mysql_python_spec.rb index 4a0f199..2082b30 100644 --- a/spec/classes/mysql_python_spec.rb +++ b/spec/classes/mysql_python_spec.rb @@ -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'} diff --git a/spec/classes/mysql_ruby_spec.rb b/spec/classes/mysql_ruby_spec.rb index d605886..f25129d 100644 --- a/spec/classes/mysql_ruby_spec.rb +++ b/spec/classes/mysql_ruby_spec.rb @@ -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'} diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index 6b59786..c248e41 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -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|