diff --git a/manifests/init.pp b/manifests/init.pp index dfa0eda..392b79a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,19 +6,19 @@ class mdadm( $config_file_manage = $::mdadm::params::config_file_manage, $config_file_options = {}, - $force_service = false, + $service_force = false, $service_ensure = 'running', $service_enable = true, $raid_check_options = {}, ) inherits mdadm::params { validate_bool($config_file_manage) validate_hash($config_file_options) - validate_bool($force_service) + validate_bool($service_force) validate_re($service_ensure, '^running$|^stopped$') validate_bool($service_enable) validate_hash($raid_check_options) - if $::force_service { + if $service_force { $use_service_ensure = $service_ensure $use_service_enable = $service_enable } elsif $::mdadm_arrays { @@ -42,8 +42,8 @@ } class { 'mdadm::mdmonitor': - ensure => $service_ensure, - enable => $service_enable, + ensure => $use_service_ensure, + enable => $use_service_enable, } class { 'mdadm::raid_check': diff --git a/spec/unit/classes/mdadm_spec.rb b/spec/unit/classes/mdadm_spec.rb index b204058..91383b6 100644 --- a/spec/unit/classes/mdadm_spec.rb +++ b/spec/unit/classes/mdadm_spec.rb @@ -22,6 +22,7 @@ :osfamily => 'RedHat', :operatingsystem => 'Scientific', :operatingsystemmajrelease => 6, + :mdadm_arrays => '/dev/md0', } end @@ -38,6 +39,44 @@ end end # no params + context 'service_force =>' do + context 'true' do + let(:params) {{ :service_force => true }} + before { facts.delete(:mdadm_arrays) } + + it do + should contain_service('mdmonitor').with({ + :ensure => 'running', + :hasrestart => true, + :hasstatus => true, + :enable => true, + }) + end + end + + context 'false' do + let(:params) {{ :service_force => false }} + before { facts.delete(:mdadm_arrays) } + + it do + should contain_service('mdmonitor').with({ + :ensure => 'stopped', + :hasrestart => true, + :hasstatus => true, + :enable => false, + }) + end + end + + context 'foo' do + let(:params) {{ :service_force => 'foo' }} + + it 'should fail' do + expect { should }.to raise_error(/is not a boolean/) + end + end + end # service_force + context 'raid_check_options =>' do context '{}' do let(:params) {{ :raid_check_options => {} }} @@ -84,7 +123,7 @@ let(:params) {{ :raid_check_options => 'some_string' }} it 'should fail' do - expect { should }.to raise_error /is not a Hash/ + expect { should }.to raise_error(/is not a Hash/) end end