Skip to content

Commit

Permalink
plugin::python introduce ensure parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bogus-py committed Dec 13, 2014
1 parent 84fcbce commit e606526
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
5 changes: 4 additions & 1 deletion manifests/plugin/python.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$modulepath,
$module,
$script_source,
$ensure = present,
$config = {},
$order = '10',
) {
Expand All @@ -14,13 +15,14 @@

# This is deprecated file naming ensuring old style file removed, and should be removed in next major relese
file { "${name}.load-deprecated":
path => "${conf_dir}/${name}.conf",
ensure => absent,
path => "${conf_dir}/${name}.conf",
}
# End deprecation

file {
"${name}.load":
ensure => $ensure,
path => "${conf_dir}/${order}-${name}.conf",
owner => 'root',
group => $collectd::params::root_group,
Expand All @@ -31,6 +33,7 @@

file {
"${name}.script":
ensure => $ensure,
path => "${modulepath}/${module}.py",
owner => 'root',
group => $collectd::params::root_group,
Expand Down
67 changes: 67 additions & 0 deletions spec/defines/collectd_plugin_python_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'spec_helper'

describe 'collectd::plugin::python', :type => :define do

context ':ensure => present' do
let :facts do
{
:osfamily => 'Debian'
}
end
let (:title) {'elasticsearch'}
let :params do
{
:modulepath => '/usr/lib/collectd',
:module => 'elasticsearch',
:script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py',
:config => {'Cluster' => 'elasticsearch'},
}
end

it 'Will create /etc/collectd/conf.d/10-elasticsearch.conf' do
should contain_file('elasticsearch.load').with({
:ensure => 'present',
:path => '/etc/collectd/conf.d/10-elasticsearch.conf',
:content => "<LoadPlugin \"python\">\n Globals true\n</LoadPlugin>\n\n<Plugin \"python\">\n ModulePath \"/usr/lib/collectd\"\n\n Import \"elasticsearch\"\n\n <Module \"elasticsearch\">\n Verbose false\n\t\tCluster \"elasticsearch\"\n </Module>\n</Plugin>\n",
})
end
it 'Will create /usr/lib/collectd/elasticsearch.py' do
should contain_file('elasticsearch.script').with({
:ensure => 'present',
:path => '/usr/lib/collectd/elasticsearch.py',
#:content => "<Plugin network>\n <Server \"node1\" \"1234\">\n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n </Server>\n</Plugin>\n",
})
end
end

context ':ensure => absent' do
let :facts do
{
:osfamily => 'Debian'
}
end
let (:title) {'elasticsearch'}
let :params do
{
:ensure => 'absent',
:modulepath => '/usr/lib/collectd',
:module => 'elasticsearch',
:script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py',
:config => {'Cluster' => 'elasticsearch'},
}
end
it 'Will not create /etc/collectd/conf.d/10-elasticsearch.conf' do
should contain_file('elasticsearch.load').with({
:ensure => 'absent',
:path => '/etc/collectd/conf.d/10-elasticsearch.conf',
})
end
it 'Will not create /usr/lib/collectd/elasticsearch.py' do
should contain_file('elasticsearch.script').with({
:ensure => 'absent',
:path => '/usr/lib/collectd/elasticsearch.py',
})
end
end

end

0 comments on commit e606526

Please sign in to comment.