Skip to content

Commit 07a6b98

Browse files
committed
[agent6][spec] fixes + spec test work
[spec] fix for older rubies. [agent6] consistent YAML experience across puppets [spec][agent6] cover old puppet ZAML regex
1 parent a68bcd6 commit 07a6b98

47 files changed

Lines changed: 2464 additions & 2046 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source "https://rubygems.org"
22

33
group :test do
44
gem "syck"
5+
gem "public_suffix", "~> 2.0.5"
56
gem "safe_yaml", "~> 1.0.4"
67
gem "hiera-eyaml", "~> 2.1.0"
78
gem "listen", "~> 3.0.0"

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PuppetLint.configuration.fail_on_warnings = true
1919
PuppetLint.configuration.send('disable_class_parameter_defaults')
2020
# http://puppet-lint.com/checks/class_inherits_from_params_class/
2121
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
22+
PuppetLint.configuration.send('disable_variable_scope')
2223

2324
exclude_paths = [
2425
"pkg/**/*",

lib/puppet/reports/datadog_reports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
Puppet::Reports.register_report(:datadog_reports) do
1111

12-
configfile = "/etc/dd-agent/datadog.yaml"
12+
configfile = "/etc/datadog-agent/datadog-reports.yaml"
1313
raise(Puppet::ParseError, "Datadog report config file #{configfile} not readable") unless File.readable?(configfile)
1414
config = YAML.load_file(configfile)
1515
API_KEY = config[:datadog_api_key]

manifests/init.pp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
$sd_template_dir = '',
249249
$sd_jmx_enable = false,
250250
$consul_token = '',
251-
$agent6_enable = false,
251+
$agent6_enable = $datadog_agent::params::agent6_enable,
252252
$conf_dir = $datadog_agent::params::conf_dir,
253253
$conf6_dir = $datadog_agent::params::conf6_dir,
254254
$conf_dir_purge = $datadog_agent::params::conf_dir_purge,
@@ -385,6 +385,16 @@
385385
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
386386
}
387387

388+
# required by reports even in agent5 scenario
389+
file { '/etc/datadog-agent':
390+
ensure => directory,
391+
owner => $dd_user,
392+
group => $dd_group,
393+
mode => '0755',
394+
require => Package['datadog-agent'],
395+
}
396+
397+
388398
if !$agent6_enable {
389399
file { '/etc/dd-agent':
390400
ensure => directory,
@@ -393,17 +403,7 @@
393403
mode => '0755',
394404
require => Package['datadog-agent'],
395405
}
396-
} else {
397-
file { '/etc/datadog-agent':
398-
ensure => directory,
399-
owner => $dd_user,
400-
group => $dd_group,
401-
mode => '0755',
402-
require => Package['datadog-agent'],
403-
}
404-
}
405406

406-
if !$agent6_enable {
407407
file { $conf_dir:
408408
ensure => directory,
409409
purge => $conf_dir_purge,
@@ -413,19 +413,7 @@
413413
group => $dd_group,
414414
notify => Service['datadog-agent']
415415
}
416-
} else {
417-
file { $conf6_dir:
418-
ensure => directory,
419-
purge => $conf_dir_purge,
420-
recurse => true,
421-
force => $conf_dir_purge,
422-
owner => $dd_user,
423-
group => $dd_group,
424-
notify => Service['datadog-agent']
425-
}
426-
}
427416

428-
if !agent6_enable {
429417
concat {'/etc/dd-agent/datadog.conf':
430418
owner => $datadog_agent::params::dd_user,
431419
group => $datadog_agent::params::dd_group,
@@ -469,18 +457,30 @@
469457
order => $apm_footer_order,
470458
}
471459
} else {
460+
461+
file { $conf6_dir:
462+
ensure => directory,
463+
purge => $conf_dir_purge,
464+
recurse => true,
465+
force => $conf_dir_purge,
466+
owner => $dd_user,
467+
group => $dd_group,
468+
notify => Service['datadog-agent']
469+
}
470+
472471
$agent_config = {
473472
'api_key' => $api_key,
474473
'dd_url' => $dd_url,
475474
'cmd_port' => 5001,
476-
'conf_path' => $datadog_agent::params::conf6_path,
475+
'conf_path' => $datadog_agent::params::conf6_dir,
477476
'enable_metadata_collection' => $collect_instance_metadata,
478477
'dogstatsd_port' => $dogstatsd_port,
479478
'dogstatsd_socket' => $dogstatsd_socket,
480479
'dogstatsd_non_local_traffic' => $non_local_traffic,
481480
'log_file' => $agent6_log_file,
482481
'log_level' => $log_level,
483482
}
483+
484484
file { '/etc/datadog-agent/datadog.yaml':
485485
owner => 'dd-agent',
486486
group => 'dd-agent',

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Sample Usage:
1616
#
1717
class datadog_agent::params {
18+
$agent6_enable = false
1819
$conf_dir = '/etc/dd-agent/conf.d'
1920
$conf6_dir = '/etc/datadog-agent/conf.d'
2021
$dd_user = 'dd-agent'

manifests/redhat/agent6.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
require => Exec['install-gpg-key'],
4141
}
4242

43-
Package { require => Yumrepo['datadog']}
43+
Package { require => Yumrepo['datadog-beta']}
4444
}
4545

4646
package { 'datadog-agent-base':

manifests/reports.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
}
4040
}
4141

42-
file { '/etc/dd-agent/datadog.yaml':
42+
file { '/etc/datadog-agent/datadog-reports.yaml':
4343
ensure => file,
44-
content => template('datadog_agent/datadog.yaml.erb'),
44+
content => template('datadog_agent/datadog-reports.yaml.erb'),
4545
owner => $puppetmaster_user,
4646
group => 'root',
4747
mode => '0640',
48-
require => File['/etc/dd-agent'],
48+
require => File['/etc/datadog-agent'],
4949
}
5050

5151
package{'dogapi':
Lines changed: 90 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,98 @@
11
require 'spec_helper'
22

33
describe 'datadog_agent::integrations::apache' do
4-
let(:facts) {{
5-
operatingsystem: 'Ubuntu',
6-
}}
7-
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8-
let(:dd_user) { 'dd-agent' }
9-
let(:dd_group) { 'root' }
10-
let(:dd_package) { 'datadog-agent' }
11-
let(:dd_service) { 'datadog-agent' }
12-
let(:conf_file) { "#{conf_dir}/apache.yaml" }
13-
14-
it { should compile.with_all_deps }
15-
it { should contain_file(conf_file).with(
16-
owner: dd_user,
17-
group: dd_group,
18-
mode: '0600',
19-
)}
20-
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
21-
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
22-
23-
context 'with default parameters' do
24-
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) }
25-
it { should contain_file(conf_file).without_content(/tags:/) }
26-
it { should contain_file(conf_file).without_content(/apache_user:/) }
27-
it { should contain_file(conf_file).without_content(/apache_password:/) }
28-
end
29-
30-
context 'with parameters set' do
31-
let(:params) {{
32-
url: 'http://foobar',
33-
username: 'userfoo',
34-
password: 'passfoo',
35-
tags: %w{foo bar baz},
36-
}}
37-
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
38-
it { should contain_file(conf_file).with_content(/apache_user: userfoo/) }
39-
it { should contain_file(conf_file).with_content(/apache_password: passfoo/) }
40-
end
41-
42-
context 'with tags parameter single value' do
43-
let(:params) {{
44-
tags: 'foo',
45-
}}
46-
it { should_not compile }
47-
48-
skip "this is currently unimplemented behavior" do
49-
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) }
50-
end
51-
end
52-
53-
context 'with tags parameter array' do
54-
let(:params) {{
55-
tags: %w{ foo bar baz },
56-
}}
57-
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
58-
end
59-
60-
context 'with tags parameter empty values' do
61-
context 'mixed in with other tags' do
62-
let(:params) {{
63-
tags: [ 'foo', '', 'baz' ]
64-
}}
65-
66-
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
67-
end
68-
69-
context 'single element array of an empty string' do
70-
let(:params) {{
71-
tags: [''],
72-
}}
73-
74-
skip("undefined behavior")
75-
end
76-
77-
context 'single value empty string' do
78-
let(:params) {{
79-
tags: '',
4+
context 'supported agents - v5 and v6' do
5+
agents = { '5' => false, '6' => true }
6+
agents.each do |_, enabled|
7+
let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" }
8+
let(:facts) {{
9+
operatingsystem: 'Ubuntu',
8010
}}
11+
if !enabled
12+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
13+
else
14+
let(:conf_dir) { '/etc/datadog-agent/conf.d' }
15+
end
16+
let(:dd_user) { 'dd-agent' }
17+
let(:dd_group) { 'root' }
18+
let(:dd_package) { 'datadog-agent' }
19+
let(:dd_service) { 'datadog-agent' }
20+
let(:agent6_enable) { enabled }
21+
let(:conf_file) { "#{conf_dir}/apache.yaml" }
22+
23+
it { should compile.with_all_deps }
8124

82-
skip("doubly undefined behavior")
25+
it { should contain_class('datadog_agent') }
26+
it { should contain_file(conf_file).with(
27+
owner: dd_user,
28+
group: dd_group,
29+
mode: '0600',
30+
)}
31+
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
32+
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
33+
34+
context 'with default parameters' do
35+
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) }
36+
it { should contain_file(conf_file).without_content(/tags:/) }
37+
it { should contain_file(conf_file).without_content(/apache_user:/) }
38+
it { should contain_file(conf_file).without_content(/apache_password:/) }
39+
end
40+
41+
context 'with parameters set' do
42+
let(:params) {{
43+
url: 'http://foobar',
44+
username: 'userfoo',
45+
password: 'passfoo',
46+
tags: %w{foo bar baz},
47+
}}
48+
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
49+
it { should contain_file(conf_file).with_content(/apache_user: userfoo/) }
50+
it { should contain_file(conf_file).with_content(/apache_password: passfoo/) }
51+
end
52+
53+
context 'with tags parameter single value' do
54+
let(:params) {{
55+
tags: 'foo',
56+
}}
57+
it { should_not compile }
58+
59+
skip "this is currently unimplemented behavior" do
60+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) }
61+
end
62+
end
63+
64+
context 'with tags parameter array' do
65+
let(:params) {{
66+
tags: %w{ foo bar baz },
67+
}}
68+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
69+
end
70+
71+
context 'with tags parameter empty values' do
72+
context 'mixed in with other tags' do
73+
let(:params) {{
74+
tags: [ 'foo', '', 'baz' ]
75+
}}
76+
77+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
78+
end
79+
80+
context 'single element array of an empty string' do
81+
let(:params) {{
82+
tags: [''],
83+
}}
84+
85+
skip("undefined behavior")
86+
end
87+
88+
context 'single value empty string' do
89+
let(:params) {{
90+
tags: '',
91+
}}
92+
93+
skip("doubly undefined behavior")
94+
end
95+
end
8396
end
8497
end
8598
end
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
require 'spec_helper'
22

33
describe 'datadog_agent::integrations::cacti' do
4-
let(:facts) {{
5-
operatingsystem: 'Ubuntu',
6-
}}
7-
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8-
let(:dd_user) { 'dd-agent' }
9-
let(:dd_group) { 'root' }
10-
let(:dd_package) { 'datadog-agent' }
11-
let(:dd_service) { 'datadog-agent' }
12-
let(:conf_file) { "#{conf_dir}/cacti.yaml" }
4+
context 'supported agents - v5 and v6' do
5+
agents = { '5' => false, '6' => true }
6+
agents.each do |agent, enabled|
7+
let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" }
8+
let(:facts) {{
9+
operatingsystem: 'Ubuntu',
10+
}}
11+
if !enabled
12+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
13+
else
14+
let(:conf_dir) { '/etc/datadog-agent/conf.d' }
15+
end
16+
let(:dd_user) { 'dd-agent' }
17+
let(:dd_group) { 'root' }
18+
let(:dd_package) { 'datadog-agent' }
19+
let(:dd_service) { 'datadog-agent' }
20+
let(:agent6_enable) { enabled }
21+
let(:conf_file) { "#{conf_dir}/cacti.yaml" }
1322

14-
context 'with default parameters' do
15-
it { should compile }
16-
end
23+
context 'with default parameters' do
24+
it { should compile }
25+
end
1726

18-
context 'with parameters set' do
19-
let(:params) {{
20-
mysql_host: 'localhost',
21-
mysql_user: 'foo',
22-
mysql_password: 'bar',
23-
rrd_path: 'path',
24-
}}
25-
it { should contain_file(conf_file).with_content(/mysql_host: localhost/) }
26-
it { should contain_file(conf_file).with_content(/mysql_user: foo/) }
27-
it { should contain_file(conf_file).with_content(/mysql_password: bar/) }
28-
it { should contain_file(conf_file).with_content(/rrd_path: path/) }
27+
context 'with parameters set' do
28+
let(:params) {{
29+
mysql_host: 'localhost',
30+
mysql_user: 'foo',
31+
mysql_password: 'bar',
32+
rrd_path: 'path',
33+
}}
34+
it { should contain_file(conf_file).with_content(/mysql_host: localhost/) }
35+
it { should contain_file(conf_file).with_content(/mysql_user: foo/) }
36+
it { should contain_file(conf_file).with_content(/mysql_password: bar/) }
37+
it { should contain_file(conf_file).with_content(/rrd_path: path/) }
38+
end
39+
end
2940
end
3041
end

0 commit comments

Comments
 (0)