Skip to content

Commit

Permalink
add config_file_manage param to class mdadm
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed May 20, 2014
1 parent 9f785e0 commit 844aade
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ include ::mdadm
```puppet
# defaults
class { '::mdadm':
config_file_manage => true,
config_options => {},
force_service => false,
service_ensure => 'running',
Expand All @@ -62,6 +63,12 @@ class { '::mdadm':
}
```

##### `config_file_manage`

`Bool` defaults to `true`

Enables/disables management of the `mdadm.conf` configuration file.

##### `config_options`

`Hash` defaults to '{}'
Expand Down
15 changes: 9 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
# documentation.
#
class mdadm(
$config_file_manage = $::mdadm::params::config_file_manage,
$config_options = {},
$force_service = false,
$service_ensure = 'running',
$service_enable = true,
$raid_check_options = {},
) {
) inherits mdadm::params {
validate_bool($config_file_manage)
validate_hash($config_options)
validate_bool($force_service)
validate_re($service_ensure, '^running$|^stopped$')
validate_bool($service_enable)
validate_hash($raid_check_options)

include mdadm::params

if $::force_service {
$use_service_ensure = $service_ensure
$use_service_enable = $service_enable
Expand All @@ -33,8 +33,12 @@
ensure => present,
}

class { 'mdadm::config':
options => $config_options,
if $config_file_manage {
Package[$mdadm::params::mdadm_package] ->
class { 'mdadm::config':
options => $config_options,
} ->
Class['mdadm::mdmonitor']
}

class { 'mdadm::mdmonitor':
Expand All @@ -48,7 +52,6 @@

anchor { 'mdadm::begin': } ->
Package[$mdadm::params::mdadm_package] ->
Class['mdadm::config'] ->
Class['mdadm::mdmonitor'] ->
Class['mdadm::raid_check'] ->
anchor { 'mdadm::end': }
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This class should be considered private.
#
class mdadm::params {
$config_file_manage = true

case $::osfamily {
'redhat': {
case $::operatingsystemmajrelease {
Expand Down
39 changes: 38 additions & 1 deletion spec/unit/classes/mdadm_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
it { should_not contain_augeas('mdadm.conf mailaddr') }
end

# config_file_manage should have no visiable behavior without config_options
context 'config_file_manage =>' do
context 'true' do
let(:params) {{ :config_file_manage => true }}

it { should_not contain_augeas('mdadm.conf mailaddr') }
end

context 'false' do
let(:params) {{ :config_file_manage => false }}

it { should_not contain_augeas('mdadm.conf mailaddr') }
end

context 'foo' do
let(:params) {{ :config_file_manage => 'foo' }}

it 'should fail' do
expect { should }.to raise_error(/is not a boolean/)
end
end
end # config_file_manage =>

context 'config_options =>' do
context '{}' do
let(:params) {{ :config_options => {}}}
Expand Down Expand Up @@ -42,7 +65,21 @@
should execute.idempotently
end
end
end

context 'and config_file_manage =>' do
context 'true' do
before { params[:config_file_manage] = true }

it { should contain_augeas('mdadm.conf mailaddr') }
end

context 'false' do
before { params[:config_file_manage] = false }

it { should_not contain_augeas('mdadm.conf mailaddr') }
end
end
end # { mailaddr => foo }

context 'undef' do
let(:params) {{ :config_options => nil }}
Expand Down

0 comments on commit 844aade

Please sign in to comment.