From bb889edea53c96a2f0a9667dedbe2d3664849d36 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Fri, 20 Mar 2020 14:38:42 +0100 Subject: [PATCH] Skip Load:ReportRelative is problematic for collectd9 Refixes https://github.com/voxpupuli/puppet-collectd/issues/901 The bug was that a ReportRelative configuration to the load plugin for collectd 5.9.0 was causing a parse error. It has been fixed for 5.9.1 collectd module now skips this configuration for collectd for collectd == 5.9.0 Previously it was '!=' 5.9. * Upsteam bug for collectd: https://github.com/voxpupuli/puppet-collectd/issues/901 * Previous incorrect commit: https://github.com/voxpupuli/puppet-collectd/commit/8edc01430d03eeabe812a7bab065f6b25200fda3 --- spec/acceptance/class_plugin_load_spec.rb | 127 ++++++++++++++++++++++ templates/plugin/load.conf.erb | 5 +- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 spec/acceptance/class_plugin_load_spec.rb diff --git a/spec/acceptance/class_plugin_load_spec.rb b/spec/acceptance/class_plugin_load_spec.rb new file mode 100644 index 000000000..17db4e16c --- /dev/null +++ b/spec/acceptance/class_plugin_load_spec.rb @@ -0,0 +1,127 @@ +require 'spec_helper_acceptance' + +describe 'collectd::plugin::load class' do + context 'basic parameters' do + # Using puppet_apply as a helper + it 'works idempotently with no errors' do + pp = <<-EOS + class{'collectd': + utils => true, + } + class{'collectd::plugin::load': } + # Add one write plugin to keep logs quiet + class{'collectd::plugin::csv':} + # Create a socket to query + class{'collectd::plugin::unixsock': + socketfile => '/var/run/collectd-sock', + socketgroup => 'root', + } + + EOS + # Run 3 times since the collectd_version + # fact is impossible until collectd is + # installed. + apply_manifest(pp, catch_failures: false) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # Wait to get some data + shell('sleep 10') + end + + describe service('collectd') do + it { is_expected.to be_running } + end + + describe command('collectdctl -s /var/run/collectd-sock listval') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{load/load$} } + its(:stdout) { is_expected.not_to match %r{load/load-relative$} } + end + end + context 'report relative false' do + # Using puppet_apply as a helper + it 'works idempotently with no errors' do + pp = <<-EOS + class{'collectd': + utils => true, + } + class{'collectd::plugin::load': + report_relative => false, + } + # Add one write plugin to keep logs quiet + class{'collectd::plugin::csv':} + # Create a socket to query + class{'collectd::plugin::unixsock': + socketfile => '/var/run/collectd-sock', + socketgroup => 'root', + } + + EOS + # Run 3 times since the collectd_version + # fact is impossible until collectd is + # installed. + apply_manifest(pp, catch_failures: false) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # Wait to get some data + shell('sleep 10') + end + + describe service('collectd') do + it { is_expected.to be_running } + end + + describe command('collectdctl -s /var/run/collectd-sock listval') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{load/load$} } + its(:stdout) { is_expected.not_to match %r{load/load-relative$} } + end + end + context 'report relative true' do + # Using puppet_apply as a helper + it 'works idempotently with no errors' do + pp = <<-EOS + class{'collectd': + utils => true, + } + class{'collectd::plugin::load': + report_relative => true, + } + # Add one write plugin to keep logs quiet + class{'collectd::plugin::csv':} + # Create a socket to query + class{'collectd::plugin::unixsock': + socketfile => '/var/run/collectd-sock', + socketgroup => 'root', + } + + EOS + # Run 3 times since the collectd_version + # fact is impossible until collectd is + # installed. + apply_manifest(pp, catch_failures: false) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # Wait to get some data + shell('sleep 10') + end + + describe service('collectd') do + it { is_expected.to be_running } + end + + describe command('collectdctl -s /var/run/collectd-sock listval') do + its(:exit_status) { is_expected.to eq 0 } + # https://github.com/voxpupuli/puppet-collectd/issues/901 + # following will fail once 5.9.1 is released in EPEL8 + if fact('osfamily') == 'RedHat' && fact('os.release.major') == '8' || + fact('osfamily') == 'Debian' && fact('os.release.major') == '8' + its(:stdout) { is_expected.not_to match %r{load/load-relative$} } + its(:stdout) { is_expected.to match %r{load/load$} } + else + its(:stdout) { is_expected.to match %r{load/load-relative$} } + its(:stdout) { is_expected.not_to match %r{load/load$} } + end + end + end +end diff --git a/templates/plugin/load.conf.erb b/templates/plugin/load.conf.erb index 44b84d742..fa5f5b35a 100644 --- a/templates/plugin/load.conf.erb +++ b/templates/plugin/load.conf.erb @@ -1,6 +1,9 @@ <% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%> -<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.9']) == 0) -%> +<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.9.0']) == 0) -%> + # ReportRelative is broken with collectd 5.9.0 + # https://github.com/collectd/collectd/issues/3180 +<% else -%> ReportRelative <%= @report_relative %> <% end -%>