Skip to content

Commit 3fae4b2

Browse files
committed
Merge pull request redhat-openstack#200 from txaj/loadplugin-options2
Uses the LoadPlugin syntax with bracket when supported
2 parents 2e515ea + 3f33f0d commit 3fae4b2

6 files changed

Lines changed: 57 additions & 12 deletions

File tree

manifests/plugin.pp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#
22
define collectd::plugin (
3-
$ensure = 'present',
4-
$content = undef,
5-
$order = '10',
6-
$plugin = $name
3+
$ensure = 'present',
4+
$content = undef,
5+
$order = '10',
6+
$globals = false,
7+
$interval = undef,
8+
$plugin = $name
79
) {
810

911
include collectd::params
@@ -16,7 +18,7 @@
1618
owner => root,
1719
group => $root_group,
1820
mode => '0640',
19-
content => "# Generated by Puppet\nLoadPlugin ${plugin}\n\n${content}",
21+
content => template('collectd/loadplugin.conf.erb'),
2022
notify => Service['collectd'],
2123
}
2224

manifests/plugin/perl.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
collectd::plugin { 'perl':
1111
ensure => $ensure,
12+
globals => true,
1213
order => $order,
1314
content => template('collectd/plugin/perl.conf.erb')
1415
}

spec/classes/collectd_plugin_swap_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
should contain_file('swap.load').with({
2727
:ensure => 'present',
2828
:path => '/etc/collectd.d/10-swap.conf',
29-
:content => "# Generated by Puppet\nLoadPlugin swap\n\n<Plugin swap>\n ReportByDevice false\n</Plugin>\n",
29+
:content => "# Generated by Puppet\n<LoadPlugin swap>\n Globals false\n</LoadPlugin>\n\n<Plugin swap>\n ReportByDevice false\n</Plugin>\n\n",
3030
})
3131
end
3232
end
@@ -42,7 +42,7 @@
4242
should contain_file('swap.load').with({
4343
:ensure => 'present',
4444
:path => '/etc/collectd.d/10-swap.conf',
45-
:content => "# Generated by Puppet\nLoadPlugin swap\n\n<Plugin swap>\n ReportByDevice false\n ReportBytes true\n</Plugin>\n",
45+
:content => "# Generated by Puppet\n<LoadPlugin swap>\n Globals false\n</LoadPlugin>\n\n<Plugin swap>\n ReportByDevice false\n ReportBytes true\n</Plugin>\n\n",
4646
})
4747
end
4848
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
3+
describe 'collectd::plugin', :type => :define do
4+
5+
context 'loading a plugin on collectd <= 4.9.4' do
6+
let(:title) { 'test' }
7+
let :facts do
8+
{
9+
:collectd_version => '5.3',
10+
:osfamily => 'Debian',
11+
}
12+
end
13+
14+
it 'Will create /etc/collectd/conf.d/10-test.conf with the LoadPlugin syntax with brackets' do
15+
should contain_file('test.load').with_content(/<LoadPlugin/)
16+
end
17+
end
18+
19+
20+
context 'loading a plugin on collectd => 4.9.3' do
21+
let(:title) { 'test' }
22+
let :facts do
23+
{
24+
:collectd_version => '4.9.3',
25+
:osfamily => 'Debian',
26+
}
27+
end
28+
29+
it 'Will create /etc/collectd/conf.d/10-test.conf with the LoadPlugin syntax without brackets' do
30+
should contain_file('test.load').without_content(/<LoadPlugin/)
31+
end
32+
end
33+
34+
end

templates/loadplugin.conf.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generated by Puppet
2+
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.9.4']) >= 0) -%>
3+
<LoadPlugin <%= @plugin %>>
4+
Globals <%= @globals %>
5+
<% if @interval and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.2']) >= 0) -%>
6+
Interval <%= @interval %>
7+
<% end -%>
8+
</LoadPlugin>
9+
<% else -%>
10+
LoadPlugin <%= @plugin %>
11+
<% end -%>
12+
13+
<%= @content %>

templates/plugin/perl.conf.erb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
#
2-
<LoadPlugin perl>
3-
Globals true
4-
</LoadPlugin>
5-
61
Include "<%= @conf_dir %>/perl/*.conf"
72

0 commit comments

Comments
 (0)