Skip to content

Commit

Permalink
add class smartd $service_ensure param
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Sep 14, 2013
1 parent 6475a9e commit 834f73f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
16 changes: 13 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# String.
#
# Standard Puppet ensure semantics (and supports `purged` state if your
# package provider does).
# package provider does). Valid values are: '^present$|^latest$|^absent$|^purged$'
#
# defaults to: `present`
#
Expand All @@ -28,6 +28,14 @@
#
# defaults to: 'smartd'
#
# [*service_ensure*]
# String.
#
# State of the smartmontools monitoring daemon. Valid values are:
# '^running$|^stopped$'
#
# defaults to: 'running'
#
# [*config_file*]
# String.
#
Expand Down Expand Up @@ -104,6 +112,7 @@
$ensure = 'present',
$package_name = $smartd::params::package_name,
$config_file = $smartd::params::config_file,
$service_ensure = $smartd::params::service_ensure,
$devicescan = $smartd::params::devicescan,
$devicescan_options = $smartd::params::devicescan_options,
$devices = $smartd::params::devices,
Expand All @@ -113,6 +122,7 @@
$enable_monit = $smartd::params::enable_monit,
) inherits smartd::params {
validate_re($ensure, '^present$|^latest$|^absent$|^purged$')
validate_re($service_ensure, '^running$|^stopped$')

# Validate our booleans
validate_bool($devicescan)
Expand All @@ -129,8 +139,8 @@
case $ensure {
'present','latest': {
$pkg_ensure = $ensure
$svc_ensure = 'running'
$svc_enable = true
$svc_ensure = $service_ensure
$svc_enable = $service_ensure ? { 'running' => true, 'stopped' => false }
$file_ensure = 'present'
}
'absent','purged': {
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class smartd::params {
$package_name = 'smartmontools'
$service_name = 'smartd'
$service_ensure = 'running'
$devicescan = true
$devicescan_options = false
$devices = []
Expand Down
24 changes: 24 additions & 0 deletions spec/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@
end
end

describe 'service_ensure => running' do
let(:params) {{ :service_ensure => 'running' }}

it { should contain_package('smartmontools').with_ensure('present') }
it { should contain_service('smartd').with_ensure('running').with_enable(true) }
end

describe 'service_ensure => stopped' do
let(:params) {{ :service_ensure => 'stopped' }}

it { should contain_package('smartmontools').with_ensure('present') }
it { should contain_service('smartd').with_ensure('stopped').with_enable(false) }
end

describe 'service_ensure => badvalue' do
let(:params) {{ :service_ensure => 'badvalue' }}

it 'should fail' do
expect {
should raise_error(Puppet::Error, /unsupported value of/)
}
end
end

describe 'devicescan => false' do
let(:params) {{ :devicescan => false }}

Expand Down

0 comments on commit 834f73f

Please sign in to comment.