(MODULES-1143) Add package_manage parameter

This patch adds a package_manage parameter for both mysql::server and
mysql::client
This commit is contained in:
juniorsysadmin 2014-12-07 19:23:18 +11:00
parent b64ca51cfb
commit f5a693b826
8 changed files with 70 additions and 30 deletions

View file

@ -217,6 +217,10 @@ What is the group used for root?
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
#####`package_manage`
Whether to manage the mysql server package. Defaults to true.
#####`package_name`
The name of the mysql server package to install.
@ -471,6 +475,10 @@ Pass install_options array to managed package resources. You must be sure to pas
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
#####`package_manage`
Whether to manage the mysql client package. Defaults to true.
#####`package_name`
What is the name of the mysql client package to install.

View file

@ -3,6 +3,7 @@ class mysql::client (
$bindings_enable = $mysql::params::bindings_enable,
$install_options = undef,
$package_ensure = $mysql::params::client_package_ensure,
$package_manage = $mysql::params::client_package_manage,
$package_name = $mysql::params::client_package_name,
) inherits mysql::params {

View file

@ -1,9 +1,13 @@
class mysql::client::install {
package { 'mysql_client':
ensure => $mysql::client::package_ensure,
install_options => $mysql::client::install_options,
name => $mysql::client::package_name,
if $mysql::client::package_manage {
package { 'mysql_client':
ensure => $mysql::client::package_ensure,
install_options => $mysql::client::install_options,
name => $mysql::client::package_name,
}
}
}

View file

@ -7,9 +7,11 @@ class mysql::params {
$restart = false
$root_password = 'UNSET'
$server_package_ensure = 'present'
$server_package_manage = true
$server_service_manage = true
$server_service_enabled = true
$client_package_ensure = 'present'
$client_package_manage = true
$create_root_user = true
$create_root_my_cnf = true
# mysql::bindings

View file

@ -7,6 +7,7 @@ class mysql::server (
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
$package_ensure = $mysql::params::server_package_ensure,
$package_manage = $mysql::params::server_package_manage,
$package_name = $mysql::params::server_package_name,
$purge_conf_dir = $mysql::params::purge_conf_dir,
$remove_default_accounts = false,

View file

@ -1,35 +1,38 @@
#
class mysql::server::install {
package { 'mysql-server':
ensure => $mysql::server::package_ensure,
install_options => $mysql::server::install_options,
name => $mysql::server::package_name,
}
if $mysql::server::package_manage {
# Build the initial databases.
$mysqluser = $mysql::server::options['mysqld']['user']
$datadir = $mysql::server::options['mysqld']['datadir']
$basedir = $mysql::server::options['mysqld']['basedir']
$config_file = $mysql::server::config_file
package { 'mysql-server':
ensure => $mysql::server::package_ensure,
install_options => $mysql::server::install_options,
name => $mysql::server::package_name,
}
if $mysql::server::manage_config_file {
$install_db_args = "--basedir=${basedir} --defaults-extra-file=${config_file} --datadir=${datadir} --user=${mysqluser}"
} else {
$install_db_args = "--basedir=${basedir} --datadir=${datadir} --user=${mysqluser}"
}
# Build the initial databases.
$mysqluser = $mysql::server::options['mysqld']['user']
$datadir = $mysql::server::options['mysqld']['datadir']
$basedir = $mysql::server::options['mysqld']['basedir']
$config_file = $mysql::server::config_file
exec { 'mysql_install_db':
command => "mysql_install_db ${install_db_args}",
creates => "${datadir}/mysql",
logoutput => on_failure,
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
require => Package['mysql-server'],
}
if $mysql::server::manage_config_file {
$install_db_args = "--basedir=${basedir} --defaults-extra-file=${config_file} --datadir=${datadir} --user=${mysqluser}"
} else {
$install_db_args = "--basedir=${basedir} --datadir=${datadir} --user=${mysqluser}"
}
if $mysql::server::restart {
Exec['mysql_install_db'] {
notify => Class['mysql::server::service'],
exec { 'mysql_install_db':
command => "mysql_install_db ${install_db_args}",
creates => "${datadir}/mysql",
logoutput => on_failure,
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
require => Package['mysql-server'],
}
if $mysql::server::restart {
Exec['mysql_install_db'] {
notify => Class['mysql::server::service'],
}
}
}

View file

@ -17,6 +17,19 @@ describe 'mysql::client' do
it { is_expected.to contain_class('mysql::bindings') }
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to true' do
let(:params) {{ :package_manage => true }}
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to false' do
let(:params) {{ :package_manage => false }}
it { is_expected.not_to contain_package('mysql_client') }
end
end
end
end

View file

@ -20,11 +20,19 @@ describe 'mysql::server' do
end
context 'mysql::server::install' do
it 'contains the package' do
it 'contains the package by default' do
is_expected.to contain_package('mysql-server').with({
:ensure => :present,
})
end
context 'with package_manage set to true' do
let(:params) {{ :package_manage => true }}
it { is_expected.to contain_package('mysql-server') }
end
context 'with package_manage set to false' do
let(:params) {{ :package_manage => false }}
it { is_expected.not_to contain_package('mysql-server') }
end
context 'with datadir overridden' do
let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }}
it { is_expected.to contain_exec('mysql_install_db') }