Skip to content

Commit 516648a

Browse files
authored
Allow removing check config files (DataDog#675)
Adds a new 'ensure' argument to 'datadog_agent::integration' that can be 'present' (default) or 'absent' (to remove the file).
1 parent 08a1201 commit 516648a

2 files changed

Lines changed: 43 additions & 22 deletions

File tree

manifests/integration.pp

Lines changed: 8 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
@@ -20,8 +21,10 @@
2021
$dst = "${datadog_agent::params::legacy_conf_dir}/${integration}.yaml"
2122
}
2223

24+
$file_ensure = $ensure ? { default => file, 'absent' => absent }
25+
2326
file { $dst:
24-
ensure => file,
27+
ensure => $file_ensure,
2528
owner => $datadog_agent::dd_user,
2629
group => $datadog_agent::dd_group,
2730
mode => $datadog_agent::params::permissions_file,

spec/defines/datadog_agent__integration_spec.rb

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,34 @@
1313
end
1414

1515
let(:title) { 'test' }
16-
let(:params) do
17-
{
18-
instances: [
19-
{
20-
one: 'two',
21-
},
22-
],
23-
}
24-
end
2516

26-
it { is_expected.to compile }
17+
gem_spec = Gem.loaded_specs['puppet']
18+
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+
35+
it { is_expected.to compile }
36+
if gem_spec.version >= Gem::Version.new('4.0.0')
37+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
38+
else
39+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
40+
end
41+
it { is_expected.to contain_file(conf_file).with_ensure('file') }
42+
end
43+
3944
context 'with logs' do
4045
let(:params) do
4146
{
@@ -48,11 +53,24 @@
4853
}
4954
end
5055

56+
it { is_expected.to compile }
5157
if gem_spec.version >= Gem::Version.new('4.0.0')
5258
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n- one\n- two}) }
5359
else
5460
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n - one\n - two}) }
5561
end
62+
it { is_expected.to contain_file(conf_file).with_ensure('file') }
63+
end
64+
65+
context 'with ensure absent' do
66+
let(:params) do
67+
{
68+
ensure: 'absent',
69+
}
70+
end
71+
72+
it { is_expected.to compile }
73+
it { is_expected.to contain_file(conf_file).with_ensure('absent') }
5674
end
5775
end
5876
end

0 commit comments

Comments
 (0)