From c76b78f517dbb5785c5a7a9ac2ea83650ee6e78f Mon Sep 17 00:00:00 2001 From: Remi Ferrand Date: Wed, 16 Jul 2014 13:52:29 +0200 Subject: [PATCH] Fix bug when `package_ensure` was set to `absent`. * Service[memcached] `enable` was left to `true` --- manifests/init.pp | 4 +++- spec/classes/memcached_spec.rb | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 7f857360b..9c29710ab 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -32,8 +32,10 @@ if $package_ensure == 'absent' { $service_ensure = 'stopped' + $service_enable = false } else { $service_ensure = 'running' + $service_enable = true } package { $memcached::params::package_name: @@ -78,7 +80,7 @@ service { $memcached::params::service_name: ensure => $service_ensure, - enable => true, + enable => $service_enable, hasrestart => true, hasstatus => $memcached::params::service_hasstatus, } diff --git a/spec/classes/memcached_spec.rb b/spec/classes/memcached_spec.rb index 3ab780b1b..0bf5968b7 100644 --- a/spec/classes/memcached_spec.rb +++ b/spec/classes/memcached_spec.rb @@ -91,6 +91,10 @@ :verbosity => 'vvv', :install_dev => true, :processorcount => 1 + }, + { + :package_ensure => 'absent', + :install_dev => true } ].each do |param_set| describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do @@ -133,12 +137,21 @@ 'group' => 'root' )} - it { should contain_service("memcached").with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'hasstatus' => false - )} + it { + if param_hash[:package_ensure] == 'absent' + should contain_service("memcached").with( + 'ensure' => 'stopped', + 'enable' => false + ) + else + should contain_service("memcached").with( + 'ensure' => 'running', + 'enable' => true, + 'hasrestart' => true, + 'hasstatus' => false + ) + end + } it 'should compile the template based on the class parameters' do content = param_value( @@ -185,3 +198,5 @@ end end end + +# vim: expandtab shiftwidth=2 softtabstop=2