From b4fa1378defa43d7bfa464af37a902b5c86cf3ec Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 12:18:47 -0800 Subject: [PATCH 01/22] adds tests for apache integration --- manifests/integrations/apache.pp | 1 + .../datadog_agent_integrations_apache_spec.rb | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_apache_spec.rb diff --git a/manifests/integrations/apache.pp b/manifests/integrations/apache.pp index 5c64a7b5..7a25a078 100644 --- a/manifests/integrations/apache.pp +++ b/manifests/integrations/apache.pp @@ -32,6 +32,7 @@ $password = undef, $tags = [] ) inherits datadog_agent::params { + include datadog_agent validate_string($url) validate_array($tags) diff --git a/spec/classes/datadog_agent_integrations_apache_spec.rb b/spec/classes/datadog_agent_integrations_apache_spec.rb new file mode 100644 index 00000000..bc11140d --- /dev/null +++ b/spec/classes/datadog_agent_integrations_apache_spec.rb @@ -0,0 +1,88 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::apache' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/apache.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) } + it { should contain_file(conf_file).without_content(/tags:/) } + it { should contain_file(conf_file).without_content(/apache_user:/) } + it { should contain_file(conf_file).without_content(/apache_password:/) } + end + + context 'with parameters set' do + let(:params) {{ + url: 'http://foobar', + username: 'userfoo', + password: 'passfoo', + tags: %w{foo bar baz}, + }} + it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) } + it { should contain_file(conf_file).with_content(/apache_user: userfoo/) } + it { should contain_file(conf_file).with_content(/apache_password: passfoo/) } + end + + context 'with tags parameter single value' do + let(:params) {{ + tags: 'foo', + }} + it { should_not compile } + + skip "this is currently unimplemented behavior" do + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) } + end + end + + context 'with tags parameter array' do + let(:params) {{ + tags: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } + end + + context 'with tags parameter with an empty tag' do + end + + context 'with tags parameter empty values' do + context 'mixed in with other tags' do + let(:params) {{ + tags: [ 'foo', '', 'baz' ] + }} + + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } + end + + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} + + skip("undefined behavior") + end + + context 'single value empty string' do + let(:params) {{ + tags: '', + }} + + skip("doubly undefined behavior") + end + end +end From c7e7d07961ab14ae419023ac20e2a3d19a585ca4 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 15:13:17 -0800 Subject: [PATCH 02/22] removed empty context --- spec/classes/datadog_agent_integrations_apache_spec.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/classes/datadog_agent_integrations_apache_spec.rb b/spec/classes/datadog_agent_integrations_apache_spec.rb index bc11140d..c68839da 100644 --- a/spec/classes/datadog_agent_integrations_apache_spec.rb +++ b/spec/classes/datadog_agent_integrations_apache_spec.rb @@ -57,9 +57,6 @@ it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } end - context 'with tags parameter with an empty tag' do - end - context 'with tags parameter empty values' do context 'mixed in with other tags' do let(:params) {{ From e849574993b1761480d44c29aa14b6d60480c0d7 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 15:16:18 -0800 Subject: [PATCH 03/22] adds test for docker integration --- manifests/integrations/docker.pp | 1 + .../datadog_agent_integrations_docker_spec.rb | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_docker_spec.rb diff --git a/manifests/integrations/docker.pp b/manifests/integrations/docker.pp index 57ac2443..a05c3e25 100644 --- a/manifests/integrations/docker.pp +++ b/manifests/integrations/docker.pp @@ -24,6 +24,7 @@ $url = 'unix://var/run/docker.sock', $tags = [], ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/docker.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_docker_spec.rb b/spec/classes/datadog_agent_integrations_docker_spec.rb new file mode 100644 index 00000000..b701a181 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_docker_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::docker' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/docker.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0644', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: unix://var/run/docker.sock}) } + it { should contain_file(conf_file).with_content(/new_tag_names: true/) } + it { should contain_file(conf_file).without_content(/tags: /) } + end + + context 'with parameters set' do + let(:params) {{ + url: 'unix://foo/bar/baz.sock', + new_tag_names: false, + }} + it { should contain_file(conf_file).with_content(%r{url: unix://foo/bar/baz.sock}) } + it { should contain_file(conf_file).with_content(/new_tag_names: false/) } + end + + context 'with tags parameter array' do + let(:params) {{ + tags: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } + end + + context 'with tags parameter with an empty tag' do + end + + context 'with tags parameter empty values' do + context 'mixed in with other tags' do + let(:params) {{ + tags: [ 'foo', '', 'baz' ] + }} + + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } + end + + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} + + skip("undefined behavior") + end + + context 'single value empty string' do + let(:params) {{ + tags: '', + }} + + skip("doubly undefined behavior") + end + end + +end From 9ed0a322d293c49fb87d71a5f5229f11bcf86780 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 15:26:43 -0800 Subject: [PATCH 04/22] adds tests for elasticsearch integration --- manifests/integrations/elasticsearch.pp | 1 + ...g_agent_integrations_elasticsearch_spec.rb | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_elasticsearch_spec.rb diff --git a/manifests/integrations/elasticsearch.pp b/manifests/integrations/elasticsearch.pp index 8e9f2d43..c2ac6d54 100644 --- a/manifests/integrations/elasticsearch.pp +++ b/manifests/integrations/elasticsearch.pp @@ -15,6 +15,7 @@ class datadog_agent::integrations::elasticsearch( $url = 'http://localhost:9200' ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/elastic.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb new file mode 100644 index 00000000..7853b748 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::elasticsearch' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/elastic.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0644', + )} + + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: http://localhost:9200}) } + end + + context 'with parameters set' do + let(:params) {{ + url: 'http://foo:4242', + }} + it { should contain_file(conf_file).with_content(%r{http://foo:4242}) } + end + +end From 91bbd3f82aa1cef10a49b50b8733dcd2ae261f0b Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 15:37:13 -0800 Subject: [PATCH 05/22] adds tests for haproxy integration --- manifests/integrations/haproxy.pp | 1 + ...datadog_agent_integrations_haproxy_spec.rb | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_haproxy_spec.rb diff --git a/manifests/integrations/haproxy.pp b/manifests/integrations/haproxy.pp index 551564c7..ce8d4ac5 100644 --- a/manifests/integrations/haproxy.pp +++ b/manifests/integrations/haproxy.pp @@ -19,6 +19,7 @@ $creds = {}, $url = "http://${::ipaddress}:8080", ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/haproxy.yaml": diff --git a/spec/classes/datadog_agent_integrations_haproxy_spec.rb b/spec/classes/datadog_agent_integrations_haproxy_spec.rb new file mode 100644 index 00000000..1fc6f20f --- /dev/null +++ b/spec/classes/datadog_agent_integrations_haproxy_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::haproxy' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + ipaddress: '1.2.3.4', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/haproxy.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0644', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: http://1.2.3.4:8080}) } + it { should contain_file(conf_file).without_content(%r{username: }) } + it { should contain_file(conf_file).without_content(%r{password: }) } + end + + context 'with url set' do + let(:params) {{ + url: 'http://foo.bar:8421', + }} + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar:8421}) } + end + + context 'with creds set correctly' do + let(:params) {{ + creds: { + 'username' => 'foo', + 'password' => 'bar', + }, + }} + it { should contain_file(conf_file).with_content(%r{username: foo}) } + it { should contain_file(conf_file).with_content(%r{password: bar}) } + end + + context 'with creds set incorrectly' do + let(:params) {{ + 'invalid' => 'is this real life', + }} + + skip 'functionality not yet implemented' do + it { should contain_file(conf_file).without_content(/invalid: is this real life/) } + end + end +end From 50b86feaa787c62b820e9c5bb20cb4d82a501aee Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 16:06:40 -0800 Subject: [PATCH 06/22] adds tests for http check integration --- manifests/integrations/http_check.pp | 1 + ...adog_agent_integrations_http_check_spec.rb | 128 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_http_check_spec.rb diff --git a/manifests/integrations/http_check.pp b/manifests/integrations/http_check.pp index 87a3e09a..2e57e4bb 100644 --- a/manifests/integrations/http_check.pp +++ b/manifests/integrations/http_check.pp @@ -87,6 +87,7 @@ $tags = [], $contact = [], ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/http_check.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_http_check_spec.rb b/spec/classes/datadog_agent_integrations_http_check_spec.rb new file mode 100644 index 00000000..543acfc9 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_http_check_spec.rb @@ -0,0 +1,128 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::http_check' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/http_check.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + it { should contain_file(conf_file).with_content(%r{name: datadog_agent::integrations::http_check}) } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: }) } + it { should contain_file(conf_file).without_content(%r{username: }) } + it { should contain_file(conf_file).without_content(%r{password: }) } + it { should contain_file(conf_file).with_content(%r{timeout: 1}) } + it { should contain_file(conf_file).without_content(%{threshold: }) } + it { should contain_file(conf_file).without_content(%r{window: }) } + it { should contain_file(conf_file).without_content(%r{include_content: true}) } + it { should contain_file(conf_file).with_content(%r{collect_response_time: true}) } + it { should contain_file(conf_file).with_content(%r{disable_ssl_validation: false}) } + it { should contain_file(conf_file).without_content(%r{headers: }) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + end + + context 'with parameters set' do + let(:params) {{ + url: 'http://foo.bar.baz:4096', + username: 'foouser', + password: 'barpassword', + timeout: 123, + threshold: 456, + window: 789, + include_content: true, + collect_response_time: false, + disable_ssl_validation: true, + }} + + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:4096}) } + it { should contain_file(conf_file).with_content(%r{username: foouser}) } + it { should contain_file(conf_file).with_content(%r{password: barpassword}) } + it { should contain_file(conf_file).with_content(%r{timeout: 123}) } + it { should contain_file(conf_file).with_content(%r{threshold: 456}) } + it { should contain_file(conf_file).with_content(%r{window: 789}) } + it { should contain_file(conf_file).with_content(%r{include_content: true}) } + it { should contain_file(conf_file).without_content(%r{collect_response_time: true}) } + it { should contain_file(conf_file).with_content(%r{disable_ssl_validation: true}) } + end + + context 'with headers parameter array' do + let(:params) {{ + headers: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/headers:\s+foo\s+bar\s+baz\s*?[^-]/m) } + end + + context 'with headers parameter empty values' do + context 'mixed in with other headers' do + let(:params) {{ + headers: [ 'foo', '', 'baz' ] + }} + + it { should contain_file(conf_file).with_content(/headers:\s+foo\s+baz\s*?[^-]/m) } + end + + context 'single element array of an empty string' do + let(:params) {{ + headers: [''], + }} + + skip("undefined behavior") + end + + context 'single value empty string' do + let(:params) {{ + headers: '', + }} + + skip("doubly undefined behavior") + end + end + + + context 'with tags parameter array' do + let(:params) {{ + tags: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } + end + + context 'with tags parameter empty values' do + context 'mixed in with other tags' do + let(:params) {{ + tags: [ 'foo', '', 'baz' ] + }} + + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } + end + + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} + + skip("undefined behavior") + end + + context 'single value empty string' do + let(:params) {{ + tags: '', + }} + + skip("doubly undefined behavior") + end + end +end From 54ff3e31b46085c194f62e9dedba0e03bf0ff581 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 16:11:41 -0800 Subject: [PATCH 07/22] adds tests for jenkins integration --- manifests/integrations/jenkins.pp | 1 + ...datadog_agent_integrations_jenkins_spec.rb | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_jenkins_spec.rb diff --git a/manifests/integrations/jenkins.pp b/manifests/integrations/jenkins.pp index db590cd7..ea206aca 100644 --- a/manifests/integrations/jenkins.pp +++ b/manifests/integrations/jenkins.pp @@ -16,6 +16,7 @@ class datadog_agent::integrations::jenkins( $path = '/var/lib/jenkins' ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/jenkins.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_jenkins_spec.rb b/spec/classes/datadog_agent_integrations_jenkins_spec.rb new file mode 100644 index 00000000..2d504368 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_jenkins_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::jenkins' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/jenkins.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{jenkins_home: /var/lib/jenkins}) } + end + + context 'with parameters set' do + let(:params) {{ + path: '/foo/bar/baz', + }} + it { should contain_file(conf_file).with_content(%r{jenkins_home: /foo/bar/baz}) } + end + +end From 48bdbf3b8bd53f2cf88200982b9d1bafe5502091 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 16:18:53 -0800 Subject: [PATCH 08/22] adds tests for marathon integration --- manifests/integrations/marathon.pp | 1 + ...atadog_agent_integrations_marathon_spec.rb | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_marathon_spec.rb diff --git a/manifests/integrations/marathon.pp b/manifests/integrations/marathon.pp index f45a3440..206e3f84 100644 --- a/manifests/integrations/marathon.pp +++ b/manifests/integrations/marathon.pp @@ -16,6 +16,7 @@ $marathon_timeout = 5, $url = 'http://localhost:8080' ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/marathon.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_marathon_spec.rb b/spec/classes/datadog_agent_integrations_marathon_spec.rb new file mode 100644 index 00000000..045d3b50 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_marathon_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::marathon' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/marathon.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0644', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{default_timeout: 5}) } + it { should contain_file(conf_file).with_content(%r{url: http://localhost:8080}) } + end + + context 'with params set' do + let(:params) {{ + marathon_timeout: 867, + url: 'http://foo.bar.baz:5309', + }} + + it { should contain_file(conf_file).with_content(%r{default_timeout: 867}) } + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:5309}) } + end +end From a7f0acaa4689deab9b263edadc3c108b879ff7be Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 16:24:38 -0800 Subject: [PATCH 09/22] adds test for mesos integration --- manifests/integrations/mesos.pp | 1 + .../datadog_agent_integrations_mesos_spec.rb | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_mesos_spec.rb diff --git a/manifests/integrations/mesos.pp b/manifests/integrations/mesos.pp index 7b0ab913..d833339f 100644 --- a/manifests/integrations/mesos.pp +++ b/manifests/integrations/mesos.pp @@ -16,6 +16,7 @@ $mesos_timeout = 5, $url = 'http://localhost:5050' ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/mesos.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_mesos_spec.rb b/spec/classes/datadog_agent_integrations_mesos_spec.rb new file mode 100644 index 00000000..836b263f --- /dev/null +++ b/spec/classes/datadog_agent_integrations_mesos_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::mesos' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/mesos.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0644', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{default_timeout: 5}) } + it { should contain_file(conf_file).with_content(%r{url: http://localhost:5050}) } + end + + context 'with parameters set' do + let(:params) {{ + mesos_timeout: 867, + url: 'http://foo.bar.baz:5309', + }} + it { should contain_file(conf_file).with_content(%r{default_timeout: 867}) } + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:5309}) } + end +end From fd478a984171f1a30378c6bf7884bb169b6e99bc Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 16:41:29 -0800 Subject: [PATCH 10/22] adds tests for mongo integration --- manifests/integrations/mongo.pp | 1 + .../datadog_agent_integrations_mongo_spec.rb | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_mongo_spec.rb diff --git a/manifests/integrations/mongo.pp b/manifests/integrations/mongo.pp index 678465b3..df42ae65 100644 --- a/manifests/integrations/mongo.pp +++ b/manifests/integrations/mongo.pp @@ -30,6 +30,7 @@ class datadog_agent::integrations::mongo( $servers = [{'host' => 'localhost', 'port' => '27017'}] ) inherits datadog_agent::params { + include datadog_agent validate_array($servers) diff --git a/spec/classes/datadog_agent_integrations_mongo_spec.rb b/spec/classes/datadog_agent_integrations_mongo_spec.rb new file mode 100644 index 00000000..9f88f8fa --- /dev/null +++ b/spec/classes/datadog_agent_integrations_mongo_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::mongo' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/mongo.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{- server: mongodb://localhost:27017}) } + it { should contain_file(conf_file).without_content(%r{tags:}) } + end + + context 'with one mongo' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '12345', + 'tags' => %w{ foo bar baz }, + } + ] + }} + + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345\s+tags:\s+- foo\s+- bar\s+- baz}) } + end + + context 'with multiple mongos' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '34567', + 'tags' => %w{foo bar}, + }, + { + 'host' => '127.0.0.2', + 'port' => '45678', + 'tags' => %w{baz bat}, + } + ] + }} + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:34567\s+tags:\s+- foo\s+- bar}) } + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678\s+tags:\s+- baz\s+- bat}) } + it { should contain_file(conf_file).with_content(%r{server:.*127.0.0.1.*server:.*127.0.0.2}m) } + end + + context 'without tags' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '12345', + } + ] + }} + + end + + context 'weird tags' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '56789', + 'tags' => 'word' + } + ] + }} + it { should_not compile } + end +end From 73c2f97d9645c46a349bb98d8837d24407a89b98 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Mon, 16 Nov 2015 17:01:32 -0800 Subject: [PATCH 11/22] adds tests for mysql integration --- manifests/integrations/mysql.pp | 1 + .../datadog_agent_integrations_mysql_spec.rb | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_mysql_spec.rb diff --git a/manifests/integrations/mysql.pp b/manifests/integrations/mysql.pp index c0f823a5..aafab8d3 100644 --- a/manifests/integrations/mysql.pp +++ b/manifests/integrations/mysql.pp @@ -36,6 +36,7 @@ $replication = '0', $galera_cluster = '0' ) inherits datadog_agent::params { + include datadog_agent validate_array($tags) diff --git a/spec/classes/datadog_agent_integrations_mysql_spec.rb b/spec/classes/datadog_agent_integrations_mysql_spec.rb new file mode 100644 index 00000000..ece7ded5 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_mysql_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::mysql' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/mysql.yaml" } + + context 'with default parameters' do + it { should_not compile } + end + + context 'with password set' do + let(:params) {{ + password: 'foobar', + }} + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + it { should contain_file(conf_file).with_content(%r{pass: foobar}) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + + context 'with defaults' do + it { should contain_file(conf_file).with_content(%r{server: localhost}) } + it { should contain_file(conf_file).with_content(%r{user: datadog}) } + it { should contain_file(conf_file).without_content(%r{sock: }) } + it { should contain_file(conf_file).with_content(%r{replication: 0}) } + it { should contain_file(conf_file).with_content(%r{galera_cluster: 0}) } + end + + context 'with parameters set' do + let(:params) {{ + password: 'foobar', + host: 'mysql1', + user: 'baz', + sock: '/tmp/mysql.foo.sock', + replication: '1', + galera_cluster: '1', + }} + + it { should contain_file(conf_file).with_content(%r{pass: foobar}) } + it { should contain_file(conf_file).with_content(%r{server: mysql1}) } + it { should contain_file(conf_file).with_content(%r{user: baz}) } + it { should contain_file(conf_file).with_content(%r{sock: /tmp/mysql.foo.sock}) } + it { should contain_file(conf_file).with_content(%r{replication: 1}) } + it { should contain_file(conf_file).with_content(%r{galera_cluster: 1}) } + end + + context 'with tags parameter array' do + let(:params) {{ + password: 'foobar', + tags: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/tags:[^-]+- foo\s+- bar\s+- baz\s*?[^-]/m) } + end + + context 'tags not array' do + let(:params) {{ + password: 'foobar', + tags: 'aoeu', + }} + + it { should_not compile } + end + end +end From 28f98e223d731df3161cac3f34b0cdec14fe6529 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 10:26:44 -0800 Subject: [PATCH 12/22] adds tests for nginx integration --- manifests/integrations/nginx.pp | 1 + .../datadog_agent_integrations_nginx_spec.rb | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_nginx_spec.rb diff --git a/manifests/integrations/nginx.pp b/manifests/integrations/nginx.pp index 14f5e44c..9066da12 100644 --- a/manifests/integrations/nginx.pp +++ b/manifests/integrations/nginx.pp @@ -25,6 +25,7 @@ class datadog_agent::integrations::nginx( $instances = [], ) inherits datadog_agent::params { + include datadog_agent validate_array($instances) diff --git a/spec/classes/datadog_agent_integrations_nginx_spec.rb b/spec/classes/datadog_agent_integrations_nginx_spec.rb new file mode 100644 index 00000000..99cdd1f4 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_nginx_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::nginx' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/nginx.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'default parameters' do + it { should contain_file(conf_file).without_content(/^[^#]*nginx_status_url/) } + end + + context 'parameters set' do + let(:params) {{ + instances: [ + { + 'nginx_status_url' => 'http://foo.bar:1941/check', + 'tags' => %w{foo bar baz} + } + ] + }} + + it { should contain_file(conf_file).with_content(%r{nginx_status_url:.*http://foo.bar:1941/check}m) } + it { should contain_file(conf_file).with_content(%r{tags:.*foo.*bar.*baz}m) } + end +end From 8e14823725025e8c38f42dec1224898c374353a7 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 10:36:57 -0800 Subject: [PATCH 13/22] adds tests for ntp integration --- manifests/integrations/ntp.pp | 1 + .../datadog_agent_integrations_ntp_spec.rb | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_ntp_spec.rb diff --git a/manifests/integrations/ntp.pp b/manifests/integrations/ntp.pp index 0ec8a288..a5199b51 100644 --- a/manifests/integrations/ntp.pp +++ b/manifests/integrations/ntp.pp @@ -16,6 +16,7 @@ class datadog_agent::integrations::ntp( $offset_threshold = 60, ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/ntp.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_ntp_spec.rb b/spec/classes/datadog_agent_integrations_ntp_spec.rb new file mode 100644 index 00000000..f6cfa537 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_ntp_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::ntp' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/ntp.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(/offset_threshold: 60/) } + end + + context 'with parameters set' do + let(:params) {{ + offset_threshold: 42, + }} + it { should contain_file(conf_file).with_content(/offset_threshold: 42/) } + end + + +end From 0f443fb42ddce1afbf59addb0f7d10e9ef9fed4d Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 11:08:08 -0800 Subject: [PATCH 14/22] adds a skipped test for missing functionality in http_check --- .../datadog_agent_integrations_http_check_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/classes/datadog_agent_integrations_http_check_spec.rb b/spec/classes/datadog_agent_integrations_http_check_spec.rb index 543acfc9..60cad4bb 100644 --- a/spec/classes/datadog_agent_integrations_http_check_spec.rb +++ b/spec/classes/datadog_agent_integrations_http_check_spec.rb @@ -125,4 +125,15 @@ skip("doubly undefined behavior") end end + + context 'with contact set' do + let(:params) {{ + contact: %r{alice bob carlo} + }} + + # the parameter is '$contact' and the template uses '@contacts', so neither is used + skip "this functionality appears to not be functional" do + it { should contain_file(conf_file).with_content(%r{notify:\s+- alice\s+bob\s+carlo}) } + end + end end From be6092903245d16abec0b6c7fd2d72775c25a616 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 11:13:44 -0800 Subject: [PATCH 15/22] adds tests for postgres integration --- manifests/integrations/postgres.pp | 1 + ...atadog_agent_integrations_postgres_spec.rb | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_postgres_spec.rb diff --git a/manifests/integrations/postgres.pp b/manifests/integrations/postgres.pp index 40375e43..ae0b9583 100644 --- a/manifests/integrations/postgres.pp +++ b/manifests/integrations/postgres.pp @@ -39,6 +39,7 @@ $tags = [], $tables = [] ) inherits datadog_agent::params { + include datadog_agent validate_array($tags) validate_array($tables) diff --git a/spec/classes/datadog_agent_integrations_postgres_spec.rb b/spec/classes/datadog_agent_integrations_postgres_spec.rb new file mode 100644 index 00000000..f7e514c9 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_postgres_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::postgres' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/postgres.yaml" } + + context 'with default parameters' do + it { should_not compile } + end + + context 'with password set' do + let(:params) {{ + password: 'abc123', + }} + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + it { should contain_file(conf_file).with_content(/password: abc123/) } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).with_content(%r{dbname: postgres}) } + it { should contain_file(conf_file).with_content(%r{port: 5432}) } + it { should contain_file(conf_file).with_content(%r{username: datadog}) } + it { should contain_file(conf_file).without_content(%r{tags: })} + it { should contain_file(conf_file).without_content(%r{^[^#]*relations: }) } + end + + context 'with parameters set' do + let(:params) {{ + host: 'postgres1', + dbname: 'cats', + port: 4142, + username: 'monitoring', + password: 'abc123', + tags: %w{foo bar baz}, + tables: %w{furry fuzzy funky} + }} + it { should contain_file(conf_file).with_content(%r{host: postgres1}) } + it { should contain_file(conf_file).with_content(%r{dbname: cats}) } + it { should contain_file(conf_file).with_content(%r{port: 4142}) } + it { should contain_file(conf_file).with_content(%r{username: monitoring}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*tags:\s+- foo\s+- bar\s+- baz}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*relations:\s+- furry\s+- fuzzy\s+- funky}) } + end + end + +end From b1cc2d6660665ed6aec2eb34c2165e6c9d7756cd Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 13:15:15 -0800 Subject: [PATCH 16/22] adds tests for process integration --- manifests/integrations/process.pp | 1 + ...datadog_agent_integrations_process_spec.rb | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_process_spec.rb diff --git a/manifests/integrations/process.pp b/manifests/integrations/process.pp index bbe39830..4cc9b1ca 100644 --- a/manifests/integrations/process.pp +++ b/manifests/integrations/process.pp @@ -41,6 +41,7 @@ class datadog_agent::integrations::process( $processes = [], ) inherits datadog_agent::params { + include datadog_agent validate_array( $processes ) diff --git a/spec/classes/datadog_agent_integrations_process_spec.rb b/spec/classes/datadog_agent_integrations_process_spec.rb new file mode 100644 index 00000000..89412c42 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_process_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::process' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/process.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).without_content(%r{^[^#]*name:}) } + end + + context 'with parameters set' do + let(:params) {{ + processes: [ + { + 'name' => 'foo', + 'search_string' => 'bar', + 'exact_match' => true + } + ] + }} + it { should contain_file(conf_file).with_content(%r{name: foo}) } + it { should contain_file(conf_file).with_content(%r{search_string: bar}) } + it { should contain_file(conf_file).with_content(%r{exact_match: true}) } + end +end From 1f4e98717ef03c96bcab2a8d128343561ee9ced5 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Tue, 17 Nov 2015 13:32:41 -0800 Subject: [PATCH 17/22] adds tests for rabbitmq integration --- manifests/integrations/rabbitmq.pp | 1 + ...atadog_agent_integrations_rabbitmq_spec.rb | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_rabbitmq_spec.rb diff --git a/manifests/integrations/rabbitmq.pp b/manifests/integrations/rabbitmq.pp index 53363d26..70c0fa6e 100644 --- a/manifests/integrations/rabbitmq.pp +++ b/manifests/integrations/rabbitmq.pp @@ -28,6 +28,7 @@ $queues = undef, $vhosts = undef, ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/rabbitmq.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb b/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb new file mode 100644 index 00000000..0c0b4531 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::rabbitmq' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/rabbitmq.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{rabbitmq_api_url: }) } + it { should contain_file(conf_file).without_content(%r{rabbitmq_user: }) } + it { should contain_file(conf_file).without_content(%r{rabbitmq_pass: }) } + it { should contain_file(conf_file).without_content(%r{queues: }) } + it { should contain_file(conf_file).without_content(%r{vhosts: }) } + end + + context 'with parameters set' do + let(:params) {{ + url: 'http://rabbit1:15672/', + username: 'foo', + password: 'bar', + queues: %w{ queue1 queue2 queue3 }, + vhosts: %w{ vhost1 vhost2 vhost3 }, + }} + it { should contain_file(conf_file).with_content(%r{rabbitmq_api_url: http://rabbit1:15672/}) } + it { should contain_file(conf_file).with_content(%r{rabbitmq_user: foo}) } + it { should contain_file(conf_file).with_content(%r{rabbitmq_pass: bar}) } + it { should contain_file(conf_file).with_content(%r{queues:\s+- queue1\s+- queue2\s+- queue3}) } + it { should contain_file(conf_file).with_content(%r{vhosts:\s+- vhost1\s+- vhost2\s+- vhost3}) } + end +end From c6d0db9b5b5ab6e055a7b9bc3293069fd02d86c7 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Wed, 18 Nov 2015 10:27:05 -0800 Subject: [PATCH 18/22] adds tests for redis integration --- manifests/integrations/redis.pp | 1 + .../datadog_agent_integrations_redis_spec.rb | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_redis_spec.rb diff --git a/manifests/integrations/redis.pp b/manifests/integrations/redis.pp index a79016df..86830d8f 100644 --- a/manifests/integrations/redis.pp +++ b/manifests/integrations/redis.pp @@ -32,6 +32,7 @@ $keys = [], $warn_on_missing_keys = true, ) inherits datadog_agent::params { + include datadog_agent validate_re($port, '^\d+$') validate_array($tags) diff --git a/spec/classes/datadog_agent_integrations_redis_spec.rb b/spec/classes/datadog_agent_integrations_redis_spec.rb new file mode 100644 index 00000000..16c30562 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_redis_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::redis' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/redisdb.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).without_content(%r{^[^#]*password: }) } + it { should contain_file(conf_file).with_content(%r{port: 6379}) } + it { should contain_file(conf_file).without_content(%r{^[^#]*slowlog-max-len: }) } + it { should contain_file(conf_file).without_content(%r{tags:}) } + it { should contain_file(conf_file).without_content(%r{\bkeys:}) } + it { should contain_file(conf_file).with_content(%r{warn_on_missing_keys: true}) } + end + + context 'with parameters set' do + let(:params) {{ + host: 'redis1', + password: 'hunter2', + port: 867, + slowlog_max_len: 5309, + tags: %w{foo bar}, + keys: %w{baz bat}, + warn_on_missing_keys: false, + }} + it { should contain_file(conf_file).with_content(%r{host: redis1}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*password: hunter2}) } + it { should contain_file(conf_file).with_content(%r{port: 867}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*slowlog-max-len: 5309}) } + it { should contain_file(conf_file).with_content(%r{tags:.*\s+- foo\s+- bar}) } + it { should contain_file(conf_file).with_content(%r{keys:.*\s+- baz\s+- bat}) } + it { should contain_file(conf_file).with_content(%r{warn_on_missing_keys: false}) } + end + +end From c403667b8cae222f8a0a0fe3463b8f9fd60dc470 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Wed, 18 Nov 2015 10:43:16 -0800 Subject: [PATCH 19/22] adds tests for solr integration --- manifests/integrations/solr.pp | 4 +- .../datadog_agent_integrations_solr_spec.rb | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 spec/classes/datadog_agent_integrations_solr_spec.rb diff --git a/manifests/integrations/solr.pp b/manifests/integrations/solr.pp index 5ed65e0f..542b5d33 100644 --- a/manifests/integrations/solr.pp +++ b/manifests/integrations/solr.pp @@ -34,7 +34,9 @@ $java_bin_path = undef, $trust_store_path = undef, $trust_store_password = undef, - $tags = {})inherits datadog_agent::params { + $tags = {}, +) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/solr.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_solr_spec.rb b/spec/classes/datadog_agent_integrations_solr_spec.rb new file mode 100644 index 00000000..0aea0cf5 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_solr_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::solr' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/solr.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).with_content(%r{port: 7199}) } + it { should contain_file(conf_file).without_content(%r{user:}) } + it { should contain_file(conf_file).without_content(%r{password:}) } + it { should contain_file(conf_file).without_content(%r{java_bin_path:}) } + it { should contain_file(conf_file).without_content(%r{trust_store_path:}) } + it { should contain_file(conf_file).without_content(%r{trust_store_password:}) } + end + + context 'with parameters set' do + let(:params) {{ + hostname: 'solr1', + port: 867, + username: 'userfoo', + password: 'passbar', + java_bin_path: '/opt/java/bin', + trust_store_path: '/var/lib/solr/trust_store', + trust_store_password: 'hunter2', + tags: { + 'foo' => 'bar', + 'baz' => 'bat', + } + }} + it { should contain_file(conf_file).with_content(%r{host: solr1}) } + it { should contain_file(conf_file).with_content(%r{port: 867}) } + it { should contain_file(conf_file).with_content(%r{user: userfoo}) } + it { should contain_file(conf_file).with_content(%r{password: passbar}) } + it { should contain_file(conf_file).with_content(%r{java_bin_path: /opt/java/bin}) } + it { should contain_file(conf_file).with_content(%r{trust_store_path: /var/lib/solr/trust_store}) } + it { should contain_file(conf_file).with_content(%r{trust_store_password: hunter2}) } + it { should contain_file(conf_file).with_content(%r{tags:\s+foo: bar\s+baz: bat}) } + end +end From 630e7e862aaebc1a4a5eb99fb217e5eee7a69cee Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Wed, 18 Nov 2015 10:54:55 -0800 Subject: [PATCH 20/22] adds tests for tomcat integration --- manifests/integrations/tomcat.pp | 5 +- .../datadog_agent_integrations_tomcat_spec.rb | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 spec/classes/datadog_agent_integrations_tomcat_spec.rb diff --git a/manifests/integrations/tomcat.pp b/manifests/integrations/tomcat.pp index 57f9482d..fb386873 100644 --- a/manifests/integrations/tomcat.pp +++ b/manifests/integrations/tomcat.pp @@ -34,7 +34,10 @@ $java_bin_path = undef, $trust_store_path = undef, $trust_store_password = undef, - $tags = {}) inherits datadog_agent::params { + $tags = {}, +) inherits datadog_agent::params { + include datadog_agent + file { "${datadog_agent::params::conf_dir}/tomcat.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_tomcat_spec.rb b/spec/classes/datadog_agent_integrations_tomcat_spec.rb new file mode 100644 index 00000000..a463df89 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_tomcat_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::tomcat' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/tomcat.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).with_content(%r{port: 7199}) } + it { should contain_file(conf_file).without_content(%r{user: }) } + it { should contain_file(conf_file).without_content(%r{password: }) } + it { should contain_file(conf_file).without_content(%r{java_bin_path:}) } + it { should contain_file(conf_file).without_content(%r{trust_store_path:}) } + it { should contain_file(conf_file).without_content(%r{trust_store_password}) } + it { should contain_file(conf_file).without_content(%r{tags:}) } + end + + context 'with parameters set' do + let(:params) {{ + hostname: 'tomcat1', + port: 867, + username: 'userfoo', + password: 'passbar', + java_bin_path: '/opt/bin/java', + trust_store_path: '/var/lib/tomcat/trust_store_path', + trust_store_password: 'hunter2', + tags: { + 'foo' => 'bar', + 'baz' => 'bat', + } + }} + it { should contain_file(conf_file).with_content(%r{host: tomcat1}) } + it { should contain_file(conf_file).with_content(%r{port: 867}) } + it { should contain_file(conf_file).with_content(%r{user: userfoo}) } + it { should contain_file(conf_file).with_content(%r{password: passbar}) } + it { should contain_file(conf_file).with_content(%r{java_bin_path: /opt/bin/java}) } + it { should contain_file(conf_file).with_content(%r{trust_store_path: /var/lib/tomcat/trust_store_path}) } + it { should contain_file(conf_file).with_content(%r{trust_store_password: hunter2}) } + it { should contain_file(conf_file).with_content(%r{tags:\s+foo: bar\s+baz: bat}) } + end +end From 24bda3229622198378129a3339d35c6e20021c4f Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Wed, 18 Nov 2015 11:21:50 -0800 Subject: [PATCH 21/22] adds tests for varnish integration --- manifests/integrations/varnish.pp | 1 + ...datadog_agent_integrations_varnish_spec.rb | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_varnish_spec.rb diff --git a/manifests/integrations/varnish.pp b/manifests/integrations/varnish.pp index 4fb43e2c..870c47c3 100644 --- a/manifests/integrations/varnish.pp +++ b/manifests/integrations/varnish.pp @@ -22,6 +22,7 @@ $varnishstat = '/usr/bin/varnishstat', $tags = [], ) inherits datadog_agent::params { + include datadog_agent file { "${datadog_agent::params::conf_dir}/varnish.yaml": ensure => file, diff --git a/spec/classes/datadog_agent_integrations_varnish_spec.rb b/spec/classes/datadog_agent_integrations_varnish_spec.rb new file mode 100644 index 00000000..557d7296 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_varnish_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::varnish' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/varnish.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{varnishstat: /usr/bin/varnishstat}) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + end + + context 'with parameters set' do + let(:params){{ + varnishstat: '/opt/bin/varnishstat', + tags: %w{ foo bar baz }, + }} + + it { should contain_file(conf_file).with_content(%r{varnishstat: /opt/bin/varnishstat}) } + it { should contain_file(conf_file).with_content(%r{tags:\s+- foo\s+- bar\s+- baz}) } + end +end From 08f4ab0082931fba89f78462a403c93c4299e1f1 Mon Sep 17 00:00:00 2001 From: Jeremy Kitchen Date: Wed, 18 Nov 2015 11:34:40 -0800 Subject: [PATCH 22/22] adds tests for zookeeper integration --- manifests/integrations/zk.pp | 1 + .../datadog_agent_integrations_zk_spec.rb | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 spec/classes/datadog_agent_integrations_zk_spec.rb diff --git a/manifests/integrations/zk.pp b/manifests/integrations/zk.pp index 154e9114..b85549b7 100644 --- a/manifests/integrations/zk.pp +++ b/manifests/integrations/zk.pp @@ -30,6 +30,7 @@ class datadog_agent::integrations::zk ( $servers = [{'host' => 'localhost', 'port' => '2181'}] ) inherits datadog_agent::params { + include datadog_agent validate_array($servers) diff --git a/spec/classes/datadog_agent_integrations_zk_spec.rb b/spec/classes/datadog_agent_integrations_zk_spec.rb new file mode 100644 index 00000000..4a971222 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_zk_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::zk' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/zk.yaml" } + + it { should compile.with_all_deps } + it { should contain_file(conf_file).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).with_content(%r{port: 2181}) } + it { should contain_file(conf_file).with_content(%r{timeout: 3}) } + it { should contain_file(conf_file).without_content(%r{tags:}) } + end + + context 'with parameters set' do + let(:params) {{ + servers: [ + { + 'host' => 'zookeeper1', + 'port' => '1234', + 'tags' => %w{foo bar}, + }, + { + 'host' => 'zookeeper2', + 'port' => '4567', + 'tags' => %w{baz bat}, + } + ] + }} + it { should contain_file(conf_file).with_content(%r{host: zookeeper1}) } + it { should contain_file(conf_file).with_content(%r{port: 1234}) } + it { should contain_file(conf_file).with_content(%r{tags:\s+- foo\s+- bar}) } + it { should contain_file(conf_file).with_content(%r{host: zookeeper2}) } + it { should contain_file(conf_file).with_content(%r{port: 4567}) } + it { should contain_file(conf_file).with_content(%r{tags:\s+- baz\s+- bat}) } + it { should contain_file(conf_file).with_content(%r{host: zookeeper1.+host: zookeeper2}m) } + end +end