Skip to content

Commit

Permalink
Use the command parameter when defined with source
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bodgit committed Sep 30, 2014
1 parent 1e961b9 commit 1175299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions manifests/handler.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion spec/defines/sensu_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1175299

Please sign in to comment.