From 1175299cf7c6a0ca8e93cb5d4858d79dbb22d495 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Tue, 30 Sep 2014 15:20:45 +0100 Subject: [PATCH] Use the command parameter when defined with source Previously if command and source parameters were both specified, command was in fact ignored. This is not helpful when the command might need additional preamble or arguments to function. Change the logic to use the value of the command parameter if it is defined, (and therefore allow the operator to shoot themselves in the foot), otherwise behave as before by setting the command to the concatenation of the install path and the handler filename. --- manifests/handler.pp | 9 +++++++-- spec/defines/sensu_handler_spec.rb | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/manifests/handler.pp b/manifests/handler.pp index 9278dcaf64..40caac3d58 100644 --- a/manifests/handler.pp +++ b/manifests/handler.pp @@ -113,20 +113,25 @@ if $source { $filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>') - $command_real = "${install_path}/${filename}" + $handler = "${install_path}/${filename}" $file_ensure = $ensure ? { 'absent' => 'absent', default => 'file' } - file { $command_real: + file { $handler: ensure => $file_ensure, owner => 'sensu', group => 'sensu', mode => '0555', source => $source, } + + $command_real = $command ? { + undef => $handler, + default => $command, + } } else { $command_real = $command } diff --git a/spec/defines/sensu_handler_spec.rb b/spec/defines/sensu_handler_spec.rb index 83ceb409ae..b983a5fed1 100644 --- a/spec/defines/sensu_handler_spec.rb +++ b/spec/defines/sensu_handler_spec.rb @@ -7,7 +7,7 @@ let(:params) { { :type => 'pipe', - :command => 'mycommand.rb', + :command => '/etc/sensu/handlers/mycommand.rb', :source => 'puppet:///somewhere/mycommand.rb' } } it { should contain_file('/etc/sensu/handlers/mycommand.rb').with_source('puppet:///somewhere/mycommand.rb')} @@ -52,6 +52,16 @@ it { should contain_sensu_handler('myhandler').with_command('/etc/sensu/handlers/script.sh') } end + context 'source and command' do + let(:params) { { + :command => 'script.sh', + :source => 'puppet:///sensu/handler/script.sh' + } } + + it { should contain_file('/etc/sensu/handlers/script.sh').with_ensure('file') } + it { should contain_sensu_handler('myhandler').with_command('script.sh') } + end + context 'handlers' do let(:params) { { :type => 'set', :handlers => ['mailer', 'hipchat'] } } it { should contain_sensu_handler('myhandler').with(