Skip to content

Commit

Permalink
Allow removing check config files (#675)
Browse files Browse the repository at this point in the history
Adds a new 'ensure' argument to 'datadog_agent::integration' that can be
'present' (default) or 'absent' (to remove the file).
  • Loading branch information
albertvaka authored Dec 2, 2020
1 parent 0822e66 commit 9cfe58a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
13 changes: 8 additions & 5 deletions manifests/integration.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define datadog_agent::integration (
Array $instances,
Optional[Hash] $init_config = undef,
Optional[Array] $logs = undef,
String $integration = $title,
Array $instances = [],
Optional[Hash] $init_config = undef,
Optional[Array] $logs = undef,
String $integration = $title,
Enum['present', 'absent'] $ensure = 'present',
){

include datadog_agent
Expand All @@ -20,8 +21,10 @@
$dst = "${datadog_agent::params::legacy_conf_dir}/${integration}.yaml"
}

$file_ensure = $ensure ? { default => file, 'absent' => absent }

file { $dst:
ensure => file,
ensure => $file_ensure,
owner => $datadog_agent::dd_user,
group => $datadog_agent::dd_group,
mode => $datadog_agent::params::permissions_file,
Expand Down
52 changes: 35 additions & 17 deletions spec/defines/datadog_agent__integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@
end

let(:title) { 'test' }
let(:params) do
{
instances: [
{
one: 'two',
},
],
}
end

it { is_expected.to compile }
gem_spec = Gem.loaded_specs['puppet']

if agent_major_version == 5
it { is_expected.to contain_file(conf_dir.to_s).that_comes_before("File[#{conf_file}]") }
end
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{init_config: }) }
gem_spec = Gem.loaded_specs['puppet']
if gem_spec.version >= Gem::Version.new('4.0.0')
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
else
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
end
it { is_expected.to contain_file(conf_file.to_s).that_notifies("Service[#{SERVICE_NAME}]") }

context 'with instances' do
let(:params) do
{
instances: [
{
one: 'two',
},
],
}
end

it { is_expected.to compile }
if gem_spec.version >= Gem::Version.new('4.0.0')
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
else
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
end
it { is_expected.to contain_file(conf_file).with_ensure('file') }
end

context 'with logs' do
let(:params) do
{
Expand All @@ -48,11 +53,24 @@
}
end

it { is_expected.to compile }
if gem_spec.version >= Gem::Version.new('4.0.0')
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n- one\n- two}) }
else
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n - one\n - two}) }
end
it { is_expected.to contain_file(conf_file).with_ensure('file') }
end

context 'with ensure absent' do
let(:params) do
{
ensure: 'absent',
}
end

it { is_expected.to compile }
it { is_expected.to contain_file(conf_file).with_ensure('absent') }
end
end
end
Expand Down

0 comments on commit 9cfe58a

Please sign in to comment.