Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move typesdb with concat resources #996

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@
recurse => $collectd::recurse,
}

if $_conf_content {
concat { 'collectd_typesdb':
ensure => present,
mode => $collectd::config_mode,
owner => $collectd::config_group,
path => "${collectd::collectd_dir}/typesdb.conf",
}

concat::fragment { 'collectd_typesdb_header':
order => '10',
content => template('collectd/typesdb.conf.erb'),
target => 'collectd_typesdb',
}
}

File['collectd.d'] -> Concat <| tag == 'collectd' |>
}
26 changes: 22 additions & 4 deletions manifests/typesdb.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#
# @summary This define initialize a collectd typesdb file
#
# @param path File path
# @param group File
# @param mode File mode
# @param owner File owner
# @param include Include the file in the typesdb config (require collectd::purge_config at true)
#
define collectd::typesdb (
$path = $title,
$group = $collectd::config_group,
$mode = $collectd::config_mode,
$owner = $collectd::config_owner,
String $path = $title,
String $group = $collectd::config_group,
String $mode = $collectd::config_mode,
String $owner = $collectd::config_owner,
Boolean $include = false,
) {
include collectd

Expand All @@ -14,4 +24,12 @@
ensure_newline => true,
notify => Service[$collectd::service_name],
}

if $include and $collectd::purge_config {
concat::fragment { "include_typedb_${path}":
order => '50',
target => 'collectd_typesdb',
content => "TypesDB \"${path}\"\n",
}
}
}
9 changes: 7 additions & 2 deletions spec/classes/collectd_init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd', type: :class do
on_supported_os.each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand All @@ -22,6 +24,7 @@
name: options[:service]
)
end

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_class('epel') }
end
Expand Down Expand Up @@ -68,6 +71,8 @@
it { is_expected.to contain_file('collectd.conf').without_content(%r{^CollectInternalStats}) }
it { is_expected.not_to contain_file_line('include_conf_d') }
it { is_expected.to contain_file('collectd.conf').with_content(%r{^# Generated by Puppet$}) }
it { is_expected.to contain_concat('collectd_typesdb') }
it { is_expected.to contain_concat__fragment('collectd_typesdb_header') }

context 'with fqdnlookup => false' do
let(:params) do
Expand All @@ -88,7 +93,7 @@
}
end

it { is_expected.to contain_file('collectd.conf').with_content(%r{^TypesDB "/path/to/types.db"}) }
it { is_expected.to contain_concat__fragment('collectd_typesdb_header').with_content(%r{^TypesDB "/path/to/types.db"}) }
end

context 'with write_queue_limit_low => 100' do
Expand Down
18 changes: 17 additions & 1 deletion spec/defines/collectd_typesdb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd::typesdb', type: :define do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand Down Expand Up @@ -33,6 +35,20 @@
).with_mode('0644')
end
end

context 'with include at true' do
let(:pre_condition) { 'class {"collectd": purge_config => true }' }
let(:title) { '/etc/collectd/types.db' }
let(:params) { { include: true } }

it do
is_expected.to contain_concat__fragment('include_typedb_/etc/collectd/types.db').with(
order: '50',
target: 'collectd_typesdb',
content: "TypesDB \"/etc/collectd/types.db\"\n"
)
end
end
end
end
end
4 changes: 1 addition & 3 deletions templates/collectd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ AutoLoadPlugin false
<% end -%>
#BaseDir "/var/lib/collectd"
#PluginDir "/usr/lib/collectd"
<% if @typesdb and not @typesdb.empty? -%>
TypesDB<% @typesdb.each do |path| -%> "<%= path %>"<% end %>
<% end -%>
Include "<%= scope['collectd::collectd_dir'] %>/typesdb.conf"
<% if @write_queue_limit_high -%>
WriteQueueLimitHigh <%= @write_queue_limit_high %>
<% end -%>
Expand Down
3 changes: 3 additions & 0 deletions templates/typesdb.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% if @typesdb and not @typesdb.empty? -%>
TypesDB<% @typesdb.each do |path| -%> "<%= path %>"<% end %>
<% end -%>