Skip to content

Commit e606526

Browse files
committed
plugin::python introduce ensure parameter
1 parent 84fcbce commit e606526

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

manifests/plugin/python.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$modulepath,
44
$module,
55
$script_source,
6+
$ensure = present,
67
$config = {},
78
$order = '10',
89
) {
@@ -14,13 +15,14 @@
1415

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

2223
file {
2324
"${name}.load":
25+
ensure => $ensure,
2426
path => "${conf_dir}/${order}-${name}.conf",
2527
owner => 'root',
2628
group => $collectd::params::root_group,
@@ -31,6 +33,7 @@
3133

3234
file {
3335
"${name}.script":
36+
ensure => $ensure,
3437
path => "${modulepath}/${module}.py",
3538
owner => 'root',
3639
group => $collectd::params::root_group,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require 'spec_helper'
2+
3+
describe 'collectd::plugin::python', :type => :define do
4+
5+
context ':ensure => present' do
6+
let :facts do
7+
{
8+
:osfamily => 'Debian'
9+
}
10+
end
11+
let (:title) {'elasticsearch'}
12+
let :params do
13+
{
14+
:modulepath => '/usr/lib/collectd',
15+
:module => 'elasticsearch',
16+
:script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py',
17+
:config => {'Cluster' => 'elasticsearch'},
18+
}
19+
end
20+
21+
it 'Will create /etc/collectd/conf.d/10-elasticsearch.conf' do
22+
should contain_file('elasticsearch.load').with({
23+
:ensure => 'present',
24+
:path => '/etc/collectd/conf.d/10-elasticsearch.conf',
25+
: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",
26+
})
27+
end
28+
it 'Will create /usr/lib/collectd/elasticsearch.py' do
29+
should contain_file('elasticsearch.script').with({
30+
:ensure => 'present',
31+
:path => '/usr/lib/collectd/elasticsearch.py',
32+
#: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",
33+
})
34+
end
35+
end
36+
37+
context ':ensure => absent' do
38+
let :facts do
39+
{
40+
:osfamily => 'Debian'
41+
}
42+
end
43+
let (:title) {'elasticsearch'}
44+
let :params do
45+
{
46+
:ensure => 'absent',
47+
:modulepath => '/usr/lib/collectd',
48+
:module => 'elasticsearch',
49+
:script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py',
50+
:config => {'Cluster' => 'elasticsearch'},
51+
}
52+
end
53+
it 'Will not create /etc/collectd/conf.d/10-elasticsearch.conf' do
54+
should contain_file('elasticsearch.load').with({
55+
:ensure => 'absent',
56+
:path => '/etc/collectd/conf.d/10-elasticsearch.conf',
57+
})
58+
end
59+
it 'Will not create /usr/lib/collectd/elasticsearch.py' do
60+
should contain_file('elasticsearch.script').with({
61+
:ensure => 'absent',
62+
:path => '/usr/lib/collectd/elasticsearch.py',
63+
})
64+
end
65+
end
66+
67+
end

0 commit comments

Comments
 (0)