From 8e0f4bc1736ec405d8acefec9a4da291e3fa8b6e Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 12 Jun 2015 17:33:41 +0100 Subject: [PATCH 1/4] Allow users to manage the smartd service The smartd service resource has been wrapped in an if statement and controlled by the $manage_service parameter, so that a user of the module can choose manage the service externally. --- manifests/init.pp | 24 +++++++++++++++++------- manifests/params.pp | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 408a6fc..9f3650e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -38,6 +38,13 @@ # # defaults to: `running` # +# [*manage_service*] +# `Bool` +# +# State whether or not this puppet module should manage the service. +# +# defaults to: `true` +# # [*config_file*] # `String` # @@ -101,6 +108,7 @@ $package_name = $smartd::params::package_name, $service_name = $smartd::params::service_name, $service_ensure = $smartd::params::service_ensure, + $manage_service = $smartd::params::manage_service, $config_file = $smartd::params::config_file, $devicescan = $smartd::params::devicescan, $devicescan_options = $smartd::params::devicescan_options, @@ -146,14 +154,16 @@ ensure => $pkg_ensure, } - service { $service_name: - ensure => $svc_ensure, - enable => $svc_enable, - hasrestart => true, - hasstatus => true, - } + if $manage_service { + service { $service_name: + ensure => $svc_ensure, + enable => $svc_enable, + hasrestart => true, + hasstatus => true, + } - Package[$package_name] -> Service[$service_name] + Package[$package_name] -> Service[$service_name] + } file { $config_file: ensure => $file_ensure, diff --git a/manifests/params.pp b/manifests/params.pp index 4ab6415..f370ad4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,6 +15,7 @@ class smartd::params { $package_name = 'smartmontools' $service_ensure = 'running' + $service_manage = true $devicescan = true $devicescan_options = undef $devices = [] From d5ce6cea7a3eccbf3ccb725bec3d43b4d4ab6e37 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 12 Jun 2015 18:05:33 +0100 Subject: [PATCH 2/4] Don't manage the smartd service when ensure => absent If the smartd package is not installed, puppet will attempt to stop a service that doesn't exist. For this reason, the smartd service should not be managed if ensure is set to absent or purged. If smartd is getting uninstalled, the deb script will take care to stop the service anyway. --- manifests/init.pp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9f3650e..ae82fd8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -42,6 +42,7 @@ # `Bool` # # State whether or not this puppet module should manage the service. +# This parameter is disregarded when $ensure = absent|purge. # # defaults to: `true` # @@ -138,12 +139,14 @@ $svc_ensure = $service_ensure $svc_enable = $service_ensure ? { 'running' => true, 'stopped' => false } $file_ensure = 'present' + $srv_manage = $manage_service } 'absent', 'purged': { $pkg_ensure = $ensure $svc_ensure = 'stopped' $svc_enable = false $file_ensure = 'absent' + $srv_manage = false } default: { fail("unsupported value of \$ensure: ${ensure}") @@ -154,7 +157,7 @@ ensure => $pkg_ensure, } - if $manage_service { + if $srv_manage { service { $service_name: ensure => $svc_ensure, enable => $svc_enable, From 8b633d9bccacb7aff7d415580fef3b4eb8d16406 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 12 Jun 2015 19:01:07 +0100 Subject: [PATCH 3/4] Fix wrong parameter name in params.pp It should be $manage_service not $service_manage! --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index f370ad4..81d2342 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,7 +15,7 @@ class smartd::params { $package_name = 'smartmontools' $service_ensure = 'running' - $service_manage = true + $manage_service = true $devicescan = true $devicescan_options = undef $devices = [] From 19be823edcf1471c8c0a5a53c411ecdb10e5052b Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 12 Jun 2015 19:10:46 +0100 Subject: [PATCH 4/4] Added unit tests for the $manage_service functionality I've added and amended some unit tests in order to check the $manage_service functionality introduced in previous commits. --- spec/unit/classes/smartd_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/unit/classes/smartd_spec.rb b/spec/unit/classes/smartd_spec.rb index d4f76a0..d36050d 100644 --- a/spec/unit/classes/smartd_spec.rb +++ b/spec/unit/classes/smartd_spec.rb @@ -129,7 +129,7 @@ let(:params) {{ :ensure => 'absent' }} it { should contain_package('smartmontools').with_ensure('absent') } - it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } + it { should_not contain_service('smartd') } it { should contain_file('/etc/smartd.conf').with_ensure('absent') } end @@ -137,7 +137,7 @@ let(:params) {{ :ensure => 'purged' }} it { should contain_package('smartmontools').with_ensure('purged') } - it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } + it { should_not contain_service('smartd') } it { should contain_file('/etc/smartd.conf').with_ensure('absent') } end @@ -165,6 +165,12 @@ it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } end + describe 'manage_service => false' do + let(:params) {{ :manage_service => false }} + + it { should_not contain_service('smartd') } + end + describe 'service_ensure => badvalue' do let(:params) {{ :service_ensure => 'badvalue' }}