Skip to content

Commit

Permalink
(GH-786) sensu::plugin does not work on windows without specifying in…
Browse files Browse the repository at this point in the history
…stall_path

Add Linux/Windows sensitive default values for sensu::plugin::install_path.
Adjust calls of sensu::plugin to not set install_path anymore.
  • Loading branch information
Phil-Friderici committed Aug 3, 2017
1 parent c99f0d2 commit 85e71ff
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 30 deletions.
3 changes: 1 addition & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@
#
# [*plugins*]
# String, Array of strings, Hash. Plugins to install on the node
# Strings and Arrays of strings will set 'install_path' => '/etc/sensu/plugins' as default.
# Default: []
# Example string: 'puppet:///data/sensu/plugins/plugin1.rb'
# Example array: [ 'puppet:///data/sensu/plugins/plugin1.rb', 'puppet:///data/sensu/plugins/plugin2.rb' ]
Expand Down Expand Up @@ -743,7 +742,7 @@
sensu::plugin { $plugins_dir: type => 'directory' }
} else {
case $plugins {
String,Array: { sensu::plugin { $plugins: install_path => '/etc/sensu/plugins' } }
String,Array: { sensu::plugin { $plugins: } }
Hash: { create_resources('::sensu::plugin', $plugins, $plugins_defaults ) }
default: { fail('Invalid data type for $plugins, must be a string, an array, or a hash.') }
}
Expand Down
5 changes: 4 additions & 1 deletion manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
#
define sensu::plugin (
Enum['file','url','package','directory'] $type = 'file',
String $install_path = '/etc/sensu/plugins',
Optional[String] $install_path = $::osfamily ? {
'windows' => 'C:/opt/sensu/plugins',
default => '/etc/sensu/plugins',
},
Boolean $purge = true,
Boolean $recurse = true,
Boolean $force = true,
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/sensu_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,13 @@

context 'with plugins => puppet:///data/sensu/plugins/teststring.rb' do
let(:params) { {:plugins => 'puppet:///data/sensu/plugins/teststring.rb' } }
it { should contain_sensu__plugin('puppet:///data/sensu/plugins/teststring.rb').with_install_path('/etc/sensu/plugins') }
it { should contain_sensu__plugin('puppet:///data/sensu/plugins/teststring.rb') }
end

context 'with plugins => [ puppet:///test/array1.rb, puppet:///test/array2.rb ]' do
let(:params) { {:plugins => [ 'puppet:///test/array1.rb', 'puppet:///test/array2.rb' ] } }
it { should contain_sensu__plugin('puppet:///test/array1.rb').with_install_path('/etc/sensu/plugins') }
it { should contain_sensu__plugin('puppet:///test/array2.rb').with_install_path('/etc/sensu/plugins') }
it { should contain_sensu__plugin('puppet:///test/array1.rb') }
it { should contain_sensu__plugin('puppet:///test/array2.rb') }
end

context 'with plugins set to a valid hash containing two entries with different options' do
Expand Down
148 changes: 124 additions & 24 deletions spec/defines/sensu_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,39 @@ class { '::sensu':
context 'file' do
let(:title) { 'puppet:///data/plug1' }

context 'defaults' do
it { should contain_file('/etc/sensu/plugins/plug1').with(
:source => 'puppet:///data/plug1'
) }
context 'running on Linux' do
context 'defaults' do
it do
should contain_sensu__plugins_dir('puppet:///data/plug1-/etc/sensu/plugins').with({
:path => '/etc/sensu/plugins',
})
end

it { should contain_file('/etc/sensu/plugins/plug1').with(
:source => 'puppet:///data/plug1'
) }

end
end

context 'running on Windows' do
let(:facts) do
{
:osfamily => 'windows',
:os => { :release => { :major => '2012 R2' }}, # needed for sensu::package
}
end
context 'defaults' do
it do
should contain_sensu__plugins_dir('puppet:///data/plug1-C:/opt/sensu/plugins').with({
:path => 'C:/opt/sensu/plugins',
})
end

it { should contain_file('C:/opt/sensu/plugins/plug1').with(
:source => 'puppet:///data/plug1'
) }
end
end

context 'setting params' do
Expand All @@ -31,18 +60,62 @@ class { '::sensu':

context 'url' do
let(:title) { 'https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh' }

context 'defaults' do
let(:params) { {
let(:params) do
{
:type => 'url',
:pkg_checksum => '1d58b78e9785f893889458f8e9fe8627'
} }
:pkg_checksum => '1d58b78e9785f893889458f8e9fe8627',
}
end

it { should contain_remote_file('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh').with(
:ensure => 'present',
:path => '/etc/sensu/plugins/check-mem.sh',
:checksum => '1d58b78e9785f893889458f8e9fe8627'
) }
context 'running on Linux' do
context 'defaults' do
it do
should contain_sensu__plugins_dir('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh-/etc/sensu/plugins').with({
:path => '/etc/sensu/plugins',
})
end

it { should contain_remote_file('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh').with(
:ensure => 'present',
:path => '/etc/sensu/plugins/check-mem.sh',
:checksum => '1d58b78e9785f893889458f8e9fe8627'
) }

it do
should contain_file('/etc/sensu/plugins/check-mem.sh').with({
:require => [ 'File[/etc/sensu/plugins]', 'Remote_file[https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh]', ],
})
end
end
end

context 'running on Windows' do
let(:facts) do
{
:osfamily => 'windows',
:os => { :release => { :major => '2012 R2' }}, # needed for sensu::package
}
end

context 'defaults' do
it do
should contain_sensu__plugins_dir('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh-C:/opt/sensu/plugins').with({
:path => 'C:/opt/sensu/plugins',
})
end

it { should contain_remote_file('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh').with(
:ensure => 'present',
:path => 'C:/opt/sensu/plugins/check-mem.sh',
:checksum => '1d58b78e9785f893889458f8e9fe8627'
) }

it do
should contain_file('C:/opt/sensu/plugins/check-mem.sh').with({
:require => [ 'File[C:/opt/sensu/plugins]', 'Remote_file[https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh]', ],
})
end
end
end

context 'setting params' do
Expand Down Expand Up @@ -76,18 +149,45 @@ class { '::sensu':

context 'directory' do
let(:title) { 'puppet:///data/sensu/plugins' }
let(:params) { { :type => 'directory' } }

context 'running on Linux' do
context 'defaults' do
it do
should contain_file('/etc/sensu/plugins_for_plugin_puppet:///data/sensu/plugins').with({
'ensure' => 'directory',
'path' => '/etc/sensu/plugins',
'mode' => '0555',
'source' => 'puppet:///data/sensu/plugins',
'recurse' => 'true',
'purge' => 'true',
'force' => 'true',
})
end
end
end

context 'defaults' do
let(:params) { { :type => 'directory' } }
context 'running on Windows' do
let(:facts) do
{
:osfamily => 'windows',
:os => { :release => { :major => '2012 R2' }}, # needed for sensu::package
}
end

it { should contain_file('/etc/sensu/plugins_for_plugin_puppet:///data/sensu/plugins').with(
'source' => 'puppet:///data/sensu/plugins',
'path' => '/etc/sensu/plugins',
'ensure' => 'directory',
'recurse' => 'true',
'force' => 'true',
'purge' => 'true'
) }
context 'defaults' do
it do
should contain_file('C:/opt/sensu/plugins_for_plugin_puppet:///data/sensu/plugins').with({
'ensure' => 'directory',
'path' => 'C:/opt/sensu/plugins',
'mode' => '0555',
'source' => 'puppet:///data/sensu/plugins',
'recurse' => 'true',
'purge' => 'true',
'force' => 'true',
})
end
end
end

context 'set install_path' do
Expand Down

0 comments on commit 85e71ff

Please sign in to comment.