Skip to content

Commit 8328e40

Browse files
committed
Allow removing check config files
Adds a new 'ensure' argument to 'datadog_agent::integration' that can be 'present' (default) or 'absent' (to remove the file).
1 parent 0822e66 commit 8328e40

2 files changed

Lines changed: 40 additions & 25 deletions

File tree

manifests/integration.pp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define datadog_agent::integration (
2-
Array $instances,
3-
Optional[Hash] $init_config = undef,
4-
Optional[Array] $logs = undef,
5-
String $integration = $title,
2+
Array $instances = [],
3+
Optional[Hash] $init_config = undef,
4+
Optional[Array] $logs = undef,
5+
String $integration = $title,
6+
Enum['present', 'absent'] $ensure = 'present',
67
){
78

89
include datadog_agent
@@ -21,7 +22,7 @@
2122
}
2223

2324
file { $dst:
24-
ensure => file,
25+
ensure => $ensure ? { default => file, 'absent' => absent },
2526
owner => $datadog_agent::dd_user,
2627
group => $datadog_agent::dd_group,
2728
mode => $datadog_agent::params::permissions_file,

spec/defines/datadog_agent__integration_spec.rb

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,41 @@
44
context 'supported agents' do
55
ALL_SUPPORTED_AGENTS.each do |agent_major_version|
66
let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" }
7+
8+
let(:title) { 'test' }
9+
710
if agent_major_version == 5
811
let(:conf_file) { '/etc/dd-agent/conf.d/test.yaml' }
9-
1012
else
1113
let(:conf_dir) { "#{CONF_DIR}/test.d" }
1214
let(:conf_file) { "#{conf_dir}/conf.yaml" }
1315
end
1416

15-
let(:title) { 'test' }
16-
let(:params) do
17-
{
18-
instances: [
19-
{
20-
one: 'two',
21-
},
22-
],
23-
}
24-
end
17+
gem_spec = Gem.loaded_specs['puppet']
2518

26-
it { is_expected.to compile }
2719
if agent_major_version == 5
2820
it { is_expected.to contain_file(conf_dir.to_s).that_comes_before("File[#{conf_file}]") }
2921
end
30-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{init_config: }) }
31-
gem_spec = Gem.loaded_specs['puppet']
32-
if gem_spec.version >= Gem::Version.new('4.0.0')
33-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
34-
else
35-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
36-
end
3722
it { is_expected.to contain_file(conf_file.to_s).that_notifies("Service[#{SERVICE_NAME}]") }
3823

24+
context 'with instances' do
25+
let(:params) do
26+
{
27+
instances: [
28+
{
29+
one: 'two',
30+
},
31+
],
32+
}
33+
end
34+
it { is_expected.to compile }
35+
if gem_spec.version >= Gem::Version.new('4.0.0')
36+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config:\ninstances:\n- one: two\n}) }
37+
else
38+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config:\n instances: \n - one: two}) }
39+
end
40+
end
41+
3942
context 'with logs' do
4043
let(:params) do
4144
{
@@ -47,13 +50,24 @@
4750
logs: ['one', 'two'],
4851
}
4952
end
50-
53+
it { is_expected.to compile }
5154
if gem_spec.version >= Gem::Version.new('4.0.0')
5255
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n- one\n- two}) }
5356
else
5457
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n - one\n - two}) }
5558
end
5659
end
60+
61+
context 'with ensure absent' do
62+
let(:params) do
63+
{
64+
ensure: 'absent',
65+
}
66+
end
67+
it { is_expected.to compile }
68+
it { is_expected.to contain_file(conf_file).with_ensure('absent') }
69+
end
70+
5771
end
5872
end
5973
end

0 commit comments

Comments
 (0)