diff --git a/Gemfile b/Gemfile index 8e167ae6..6f88ebb7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" group :test do gem "syck" + gem "public_suffix", "~> 2.0.5" gem "safe_yaml", "~> 1.0.4" gem "hiera-eyaml", "~> 2.1.0" gem "listen", "~> 3.0.0" @@ -9,6 +10,7 @@ group :test do gem "puppet-lint" gem "puppet-syntax" gem "puppetlabs_spec_helper" + gem "jwt", "~> 1.5.6" gem "rake" gem "rspec-puppet", '2.3.2' end diff --git a/Rakefile b/Rakefile index 28af9f3c..c0a27e87 100644 --- a/Rakefile +++ b/Rakefile @@ -19,6 +19,7 @@ PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.send('disable_class_parameter_defaults') # http://puppet-lint.com/checks/class_inherits_from_params_class/ PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_variable_scope') exclude_paths = [ "pkg/**/*", diff --git a/lib/puppet/reports/datadog_reports.rb b/lib/puppet/reports/datadog_reports.rb index 0619a65b..569be3cd 100644 --- a/lib/puppet/reports/datadog_reports.rb +++ b/lib/puppet/reports/datadog_reports.rb @@ -9,7 +9,7 @@ Puppet::Reports.register_report(:datadog_reports) do - configfile = "/etc/dd-agent/datadog.yaml" + configfile = "/etc/datadog-agent/datadog-reports.yaml" raise(Puppet::ParseError, "Datadog report config file #{configfile} not readable") unless File.readable?(configfile) config = YAML.load_file(configfile) API_KEY = config[:datadog_api_key] diff --git a/manifests/init.pp b/manifests/init.pp index 26febfe5..bdfe8777 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -102,6 +102,9 @@ # $use_dogstatsd # Enables the dogstatsd server # Boolean. Default: true +# $dogstatsd_socket +# Specifies the socket file to be used by dogstatsd. Must have use_dogstatsd set +# String. Default: empty # $dogstatsd_port # Specifies the port to be used by dogstatsd. Must have use_dogstatsd set # String. Default: empty @@ -139,6 +142,9 @@ # $custom_emitters # Specifies a comma seperated list of non standard emitters to be used # String. Default: empty +# $agent6_log_file +# Specifies the log file location for the agent6 +# String. Default: empty # $collector_log_file # Specifies the log file location for the collector system # String. Default: empty @@ -199,6 +205,7 @@ $manage_repo = true, $hostname_extraction_regex = nil, $dogstatsd_port = 8125, + $dogstatsd_socket = '', $statsd_forward_host = '', $statsd_forward_port = '', $statsd_histogram_percentiles = '0.95', @@ -227,6 +234,7 @@ $dogstatsd_normalize = true, $device_blacklist_re = '', $custom_emitters = '', + $agent6_log_file = '/var/log/datadog/agent.log', $collector_log_file = '', $forwarder_log_file = '', $dogstatsd_log_file = '', @@ -240,7 +248,9 @@ $sd_template_dir = '', $sd_jmx_enable = false, $consul_token = '', + $agent6_enable = $datadog_agent::params::agent6_enable, $conf_dir = $datadog_agent::params::conf_dir, + $conf6_dir = $datadog_agent::params::conf6_dir, $conf_dir_purge = $datadog_agent::params::conf_dir_purge, $service_name = $datadog_agent::params::service_name, $package_name = $datadog_agent::params::package_name, @@ -306,6 +316,7 @@ validate_string($statsd_forward_host) validate_string($device_blacklist_re) validate_string($custom_emitters) + validate_string($agent6_log_file) validate_string($collector_log_file) validate_string($forwarder_log_file) validate_string($dogstatsd_log_file) @@ -320,6 +331,7 @@ validate_bool($sd_jmx_enable) validate_string($consul_token) validate_bool($apm_enabled) + validate_bool($agent6_enable) validate_string($apm_env) if $hiera_tags { @@ -352,16 +364,29 @@ } case $::operatingsystem { - 'Ubuntu','Debian' : { include datadog_agent::ubuntu } + 'Ubuntu','Debian' : { + if !$agent6_enable { + include datadog_agent::ubuntu + } else { + include datadog_agent::ubuntu::agent6 + } + } 'RedHat','CentOS','Fedora','Amazon','Scientific' : { - class { 'datadog_agent::redhat': - manage_repo => $manage_repo, + if !$agent6_enable { + class { 'datadog_agent::redhat': + manage_repo => $manage_repo, + } + } else { + class { 'datadog_agent::redhat::agent6': + manage_repo => $manage_repo, + } } } default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") } } - file { '/etc/dd-agent': + # required by reports even in agent5 scenario + file { '/etc/datadog-agent': ensure => directory, owner => $dd_user, group => $dd_group, @@ -369,57 +394,101 @@ require => Package['datadog-agent'], } - file { $conf_dir: - ensure => directory, - purge => $conf_dir_purge, - recurse => true, - force => $conf_dir_purge, - owner => $dd_user, - group => $dd_group, - notify => Service['datadog-agent'] - } - concat {'/etc/dd-agent/datadog.conf': - owner => $datadog_agent::params::dd_user, - group => $datadog_agent::params::dd_group, - mode => '0640', - notify => Service[$datadog_agent::params::service_name], - require => File['/etc/dd-agent'], - } + if !$agent6_enable { + file { '/etc/dd-agent': + ensure => directory, + owner => $dd_user, + group => $dd_group, + mode => '0755', + require => Package['datadog-agent'], + } - concat::fragment{ 'datadog header': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_header.conf.erb'), - order => '01', - } + file { $conf_dir: + ensure => directory, + purge => $conf_dir_purge, + recurse => true, + force => $conf_dir_purge, + owner => $dd_user, + group => $dd_group, + notify => Service['datadog-agent'] + } - concat::fragment{ 'datadog tags': - target => '/etc/dd-agent/datadog.conf', - content => 'tags: ', - order => '02', - } + concat {'/etc/dd-agent/datadog.conf': + owner => $datadog_agent::params::dd_user, + group => $datadog_agent::params::dd_group, + mode => '0640', + notify => Service[$datadog_agent::params::service_name], + require => File['/etc/dd-agent'], + } - concat::fragment{ 'datadog footer': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_footer.conf.erb'), - order => '05', - } + concat::fragment{ 'datadog header': + target => '/etc/dd-agent/datadog.conf', + content => template('datadog_agent/datadog_header.conf.erb'), + order => '01', + } + + concat::fragment{ 'datadog tags': + target => '/etc/dd-agent/datadog.conf', + content => 'tags: ', + order => '02', + } + + concat::fragment{ 'datadog footer': + target => '/etc/dd-agent/datadog.conf', + content => template('datadog_agent/datadog_footer.conf.erb'), + order => '05', + } + + if ($extra_template != '') { + concat::fragment{ 'datadog extra_template footer': + target => '/etc/dd-agent/datadog.conf', + content => template($extra_template), + order => '06', + } + $apm_footer_order = '07' + } else { + $apm_footer_order = '06' + } - if ($extra_template != '') { - concat::fragment{ 'datadog extra_template footer': + concat::fragment{ 'datadog apm footer': target => '/etc/dd-agent/datadog.conf', - content => template($extra_template), - order => '06', + content => template('datadog_agent/datadog_apm_footer.conf.erb'), + order => $apm_footer_order, } - $apm_footer_order = '07' } else { - $apm_footer_order = '06' - } - concat::fragment{ 'datadog apm footer': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_apm_footer.conf.erb'), - order => $apm_footer_order, + file { $conf6_dir: + ensure => directory, + purge => $conf_dir_purge, + recurse => true, + force => $conf_dir_purge, + owner => $dd_user, + group => $dd_group, + notify => Service['datadog-agent'] + } + + $agent_config = { + 'api_key' => $api_key, + 'dd_url' => $dd_url, + 'cmd_port' => 5001, + 'conf_path' => $datadog_agent::params::conf6_dir, + 'enable_metadata_collection' => $collect_instance_metadata, + 'dogstatsd_port' => $dogstatsd_port, + 'dogstatsd_socket' => $dogstatsd_socket, + 'dogstatsd_non_local_traffic' => $non_local_traffic, + 'log_file' => $agent6_log_file, + 'log_level' => $log_level, + } + + file { '/etc/datadog-agent/datadog.yaml': + owner => 'dd-agent', + group => 'dd-agent', + mode => '0640', + content => template('datadog_agent/datadog6.yaml.erb'), + notify => Service[$datadog_agent::params::service_name], + require => File['/etc/datadog-agent'], + } } diff --git a/manifests/integration.pp b/manifests/integration.pp index 52e130a7..02a6b0b4 100644 --- a/manifests/integration.pp +++ b/manifests/integration.pp @@ -12,7 +12,13 @@ } validate_string($integration) - file { "${datadog_agent::conf_dir}/${integration}.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/${integration}.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/${integration}.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::dd_user, group => $datadog_agent::dd_group, diff --git a/manifests/integrations/apache.pp b/manifests/integrations/apache.pp index 6f25cd69..e306e185 100644 --- a/manifests/integrations/apache.pp +++ b/manifests/integrations/apache.pp @@ -39,7 +39,13 @@ validate_array($tags) validate_bool($disable_ssl_validation) - file { "${datadog_agent::params::conf_dir}/apache.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/apache.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/apache.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/cacti.pp b/manifests/integrations/cacti.pp index b8471d64..34fdc198 100644 --- a/manifests/integrations/cacti.pp +++ b/manifests/integrations/cacti.pp @@ -20,7 +20,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/cacti.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/cacti.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/cacti.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/cassandra.pp b/manifests/integrations/cassandra.pp index d592e734..b1833c2d 100644 --- a/manifests/integrations/cassandra.pp +++ b/manifests/integrations/cassandra.pp @@ -35,7 +35,13 @@ require ::datadog_agent validate_hash($tags) - file { "${datadog_agent::params::conf_dir}/cassandra.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/cassandra.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/cassandra.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/ceph.pp b/manifests/integrations/ceph.pp index c03dc90c..f4c602d2 100644 --- a/manifests/integrations/ceph.pp +++ b/manifests/integrations/ceph.pp @@ -25,7 +25,13 @@ content => "# This file is required for dd ceph \ndd-agent ALL=(ALL) NOPASSWD:/usr/bin/ceph\n" } - file { "${datadog_agent::params::conf_dir}/ceph.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/ceph.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/ceph.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/consul.pp b/manifests/integrations/consul.pp index 29a6e62e..69032023 100644 --- a/manifests/integrations/consul.pp +++ b/manifests/integrations/consul.pp @@ -39,7 +39,13 @@ validate_bool($new_leader_checks) validate_array($service_whitelist) - file { "${datadog_agent::params::conf_dir}/consul.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/consul.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/consul.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/directory.pp b/manifests/integrations/directory.pp index f036c893..bddb08d1 100644 --- a/manifests/integrations/directory.pp +++ b/manifests/integrations/directory.pp @@ -31,7 +31,13 @@ fail('you must specify a directory path within the datadog_agent::integrations::directory class') } - file { "${datadog_agent::params::conf_dir}/directory.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/directory.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/directory.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/disk.pp b/manifests/integrations/disk.pp index b25d3ff5..a5701a4d 100644 --- a/manifests/integrations/disk.pp +++ b/manifests/integrations/disk.pp @@ -47,7 +47,13 @@ validate_re($all_partitions, '^(no|yes)$', "all_partitions should be either 'yes' or 'no'") } - file { "${datadog_agent::params::conf_dir}/disk.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/disk.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/disk.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/dns_check.pp b/manifests/integrations/dns_check.pp index 6e7d1fab..6dd2ddf1 100644 --- a/manifests/integrations/dns_check.pp +++ b/manifests/integrations/dns_check.pp @@ -37,7 +37,13 @@ validate_array($checks) - file { "${datadog_agent::params::conf_dir}/dns_check.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/dns_check.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/dns_check.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/docker_daemon.pp b/manifests/integrations/docker_daemon.pp index bbdc24aa..cf3fee0e 100644 --- a/manifests/integrations/docker_daemon.pp +++ b/manifests/integrations/docker_daemon.pp @@ -33,11 +33,23 @@ notify => Service[$datadog_agent::params::service_name] } - file { "${datadog_agent::params::conf_dir}/docker.yaml": + if $::datadog_agent::agent6_enable { + $legacy_conf = "${datadog_agent::conf6_dir}/docker_daemon.yaml" + } else { + $legacy_conf = "${datadog_agent::conf_dir}/docker.yaml" + } + + file { $legacy_conf: ensure => 'absent' } - file { "${datadog_agent::params::conf_dir}/docker_daemon.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/docker.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/docker_daemon.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/elasticsearch.pp b/manifests/integrations/elasticsearch.pp index 6ad46255..eae8a27e 100644 --- a/manifests/integrations/elasticsearch.pp +++ b/manifests/integrations/elasticsearch.pp @@ -69,7 +69,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/elastic.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/elastic.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/elastic.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/fluentd.pp b/manifests/integrations/fluentd.pp index 8b96a7fe..172fefb6 100644 --- a/manifests/integrations/fluentd.pp +++ b/manifests/integrations/fluentd.pp @@ -25,7 +25,13 @@ validate_array($plugin_ids) - file { "${datadog_agent::params::conf_dir}/fluentd.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/fluentd.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/fluentd.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/generic.pp b/manifests/integrations/generic.pp index 4f1adb2c..1b113356 100644 --- a/manifests/integrations/generic.pp +++ b/manifests/integrations/generic.pp @@ -25,7 +25,13 @@ validate_string($integration_name) validate_string($integration_contents) - file { "${datadog_agent::params::conf_dir}/${integration_name}.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/${integration_name}.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/${integration_name}.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/haproxy.pp b/manifests/integrations/haproxy.pp index 79fe9a19..e7d16e21 100644 --- a/manifests/integrations/haproxy.pp +++ b/manifests/integrations/haproxy.pp @@ -36,8 +36,13 @@ $_instances = $instances } - file { - "${datadog_agent::params::conf_dir}/haproxy.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/haproxy.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/haproxy.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/http_check.pp b/manifests/integrations/http_check.pp index 797b5ba9..3553309e 100644 --- a/manifests/integrations/http_check.pp +++ b/manifests/integrations/http_check.pp @@ -195,7 +195,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/http_check.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/http_check.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/http_check.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/jenkins.pp b/manifests/integrations/jenkins.pp index ea206aca..a7ef1446 100644 --- a/manifests/integrations/jenkins.pp +++ b/manifests/integrations/jenkins.pp @@ -18,7 +18,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/jenkins.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/jenkins.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/jenkins.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/jmx.pp b/manifests/integrations/jmx.pp index 038a7a97..5280d414 100644 --- a/manifests/integrations/jmx.pp +++ b/manifests/integrations/jmx.pp @@ -67,7 +67,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/jmx.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/jmx.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/jmx.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/kong.pp b/manifests/integrations/kong.pp index 623d1b65..0f7e425e 100644 --- a/manifests/integrations/kong.pp +++ b/manifests/integrations/kong.pp @@ -34,7 +34,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/kong.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/kong.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/kong.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/marathon.pp b/manifests/integrations/marathon.pp index 206e3f84..b8c56204 100644 --- a/manifests/integrations/marathon.pp +++ b/manifests/integrations/marathon.pp @@ -18,7 +18,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/marathon.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/marathon.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/marathon.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/memcache.pp b/manifests/integrations/memcache.pp index af740ae1..b764e01f 100644 --- a/manifests/integrations/memcache.pp +++ b/manifests/integrations/memcache.pp @@ -58,7 +58,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/mcache.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/mcache.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/mcache.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/mesos_master.pp b/manifests/integrations/mesos_master.pp index 1aaec699..ccdbe2c5 100644 --- a/manifests/integrations/mesos_master.pp +++ b/manifests/integrations/mesos_master.pp @@ -18,11 +18,23 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/mesos.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/mesos.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/mesos.yaml" + } + + file { $dst: ensure => 'absent' } - file { "${datadog_agent::params::conf_dir}/mesos_master.yaml": + if $::datadog_agent::agent6_enable { + $dst_master = "${datadog_agent::conf6_dir}/mesos_master.yaml" + } else { + $dst_master = "${datadog_agent::conf_dir}/mesos_master.yaml" + } + + file { $dst_master: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/mesos_slave.pp b/manifests/integrations/mesos_slave.pp index 4b1dffaa..6b94f047 100644 --- a/manifests/integrations/mesos_slave.pp +++ b/manifests/integrations/mesos_slave.pp @@ -17,7 +17,13 @@ $url = 'http://localhost:5051' ) inherits datadog_agent::params { - file { "${datadog_agent::params::conf_dir}/mesos_slave.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/mesos_slave.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/mesos_slave.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/mongo.pp b/manifests/integrations/mongo.pp index 47139e9d..f9e7d878 100644 --- a/manifests/integrations/mongo.pp +++ b/manifests/integrations/mongo.pp @@ -63,7 +63,13 @@ validate_array($servers) - file { "${datadog_agent::params::conf_dir}/mongo.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/mongo.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/mongo.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/mysql.pp b/manifests/integrations/mysql.pp index 0b258119..643c2f3f 100644 --- a/manifests/integrations/mysql.pp +++ b/manifests/integrations/mysql.pp @@ -95,7 +95,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/mysql.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/mysql.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/mysql.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/nginx.pp b/manifests/integrations/nginx.pp index 9066da12..a2d7f31c 100644 --- a/manifests/integrations/nginx.pp +++ b/manifests/integrations/nginx.pp @@ -29,7 +29,13 @@ validate_array($instances) - file { "${datadog_agent::params::conf_dir}/nginx.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/nginx.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/nginx.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/ntp.pp b/manifests/integrations/ntp.pp index ce4fa9cf..9e74868d 100644 --- a/manifests/integrations/ntp.pp +++ b/manifests/integrations/ntp.pp @@ -32,7 +32,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/ntp.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/ntp.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/ntp.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/pgbouncer.pp b/manifests/integrations/pgbouncer.pp index d9889df7..dcecbadf 100644 --- a/manifests/integrations/pgbouncer.pp +++ b/manifests/integrations/pgbouncer.pp @@ -34,7 +34,13 @@ validate_array($tags) - file { "${datadog_agent::params::conf_dir}/pgbouncer.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/pgbouncer.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/pgbouncer.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/php_fpm.pp b/manifests/integrations/php_fpm.pp index 3870beea..706a34e6 100644 --- a/manifests/integrations/php_fpm.pp +++ b/manifests/integrations/php_fpm.pp @@ -40,7 +40,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/php_fpm.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/php_fpm.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/php_fpm.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/postfix.pp b/manifests/integrations/postfix.pp index eeeee321..9cd931fb 100644 --- a/manifests/integrations/postfix.pp +++ b/manifests/integrations/postfix.pp @@ -52,7 +52,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/postfix.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/postfix.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/postfix.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/postgres.pp b/manifests/integrations/postgres.pp index 07e679f8..e45f0e7c 100644 --- a/manifests/integrations/postgres.pp +++ b/manifests/integrations/postgres.pp @@ -68,7 +68,13 @@ validate_array($tables) validate_bool($use_psycopg2) - file { "${datadog_agent::params::conf_dir}/postgres.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/postgres.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/postgres.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/process.pp b/manifests/integrations/process.pp index 4cc9b1ca..ae1a9986 100644 --- a/manifests/integrations/process.pp +++ b/manifests/integrations/process.pp @@ -45,7 +45,13 @@ validate_array( $processes ) - file { "${datadog_agent::params::conf_dir}/process.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/process.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/process.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/rabbitmq.pp b/manifests/integrations/rabbitmq.pp index dee4286b..90bdc4db 100644 --- a/manifests/integrations/rabbitmq.pp +++ b/manifests/integrations/rabbitmq.pp @@ -70,7 +70,13 @@ validate_array($vhosts) include datadog_agent - file { "${datadog_agent::params::conf_dir}/rabbitmq.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/rabbitmq.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/rabbitmq.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/redis.pp b/manifests/integrations/redis.pp index a537b277..3d676d8e 100644 --- a/manifests/integrations/redis.pp +++ b/manifests/integrations/redis.pp @@ -54,7 +54,13 @@ validate_array($_ports) - file { "${datadog_agent::params::conf_dir}/redisdb.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/redisdb.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/redisdb.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/riak.pp b/manifests/integrations/riak.pp index d1888dfa..f6dd39f4 100644 --- a/manifests/integrations/riak.pp +++ b/manifests/integrations/riak.pp @@ -27,8 +27,14 @@ validate_string($url) validate_array($tags) + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/riak.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/riak.yaml" + } + file { - "${datadog_agent::params::conf_dir}/riak.yaml": + $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/solr.pp b/manifests/integrations/solr.pp index 542b5d33..da5fdc61 100644 --- a/manifests/integrations/solr.pp +++ b/manifests/integrations/solr.pp @@ -38,7 +38,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/solr.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/solr.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/solr.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/ssh.pp b/manifests/integrations/ssh.pp index 142157dd..ae4600f7 100644 --- a/manifests/integrations/ssh.pp +++ b/manifests/integrations/ssh.pp @@ -37,7 +37,13 @@ ) inherits datadog_agent::params { include ::datadog_agent - file { "${datadog_agent::params::conf_dir}/ssh.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/ssh.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/ssh.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/supervisord.pp b/manifests/integrations/supervisord.pp index 42b205c1..182ea36a 100644 --- a/manifests/integrations/supervisord.pp +++ b/manifests/integrations/supervisord.pp @@ -46,7 +46,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/supervisord.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/supervisord.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/supervisord.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/tcp_check.pp b/manifests/integrations/tcp_check.pp index 4ec4b2aa..b935e6e7 100644 --- a/manifests/integrations/tcp_check.pp +++ b/manifests/integrations/tcp_check.pp @@ -117,7 +117,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/tcp_check.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/tcp_check.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/tcp_check.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/tomcat.pp b/manifests/integrations/tomcat.pp index fb386873..23542b5c 100644 --- a/manifests/integrations/tomcat.pp +++ b/manifests/integrations/tomcat.pp @@ -39,7 +39,13 @@ include datadog_agent - file { "${datadog_agent::params::conf_dir}/tomcat.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/tomcat.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/tomcat.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/twemproxy.pp b/manifests/integrations/twemproxy.pp index f1280c3e..e124b39e 100644 --- a/manifests/integrations/twemproxy.pp +++ b/manifests/integrations/twemproxy.pp @@ -41,7 +41,13 @@ $_instances = $instances } - file { "${datadog_agent::params::conf_dir}/twemproxy.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/twemproxy.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/twemproxy.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/varnish.pp b/manifests/integrations/varnish.pp index 90ac59c0..9e59feb3 100644 --- a/manifests/integrations/varnish.pp +++ b/manifests/integrations/varnish.pp @@ -28,7 +28,13 @@ ) inherits datadog_agent::params { include datadog_agent - file { "${datadog_agent::params::conf_dir}/varnish.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/varnish.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/varnish.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/integrations/zk.pp b/manifests/integrations/zk.pp index 93352a55..6f79709f 100644 --- a/manifests/integrations/zk.pp +++ b/manifests/integrations/zk.pp @@ -34,7 +34,13 @@ validate_array($servers) - file { "${datadog_agent::params::conf_dir}/zk.yaml": + if $::datadog_agent::agent6_enable { + $dst = "${datadog_agent::conf6_dir}/zk.yaml" + } else { + $dst = "${datadog_agent::conf_dir}/zk.yaml" + } + + file { $dst: ensure => file, owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, diff --git a/manifests/params.pp b/manifests/params.pp index a2bc2329..e3a11c95 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,7 +15,9 @@ # Sample Usage: # class datadog_agent::params { + $agent6_enable = false $conf_dir = '/etc/dd-agent/conf.d' + $conf6_dir = '/etc/datadog-agent/conf.d' $dd_user = 'dd-agent' $dd_group = 'root' $package_name = 'datadog-agent' diff --git a/manifests/redhat/agent6.pp b/manifests/redhat/agent6.pp new file mode 100644 index 00000000..d959b8d8 --- /dev/null +++ b/manifests/redhat/agent6.pp @@ -0,0 +1,64 @@ +# Class: datadog_agent::redhat::agent6 +# +# This class contains the DataDog agent installation mechanism for Red Hat derivatives +# + +class datadog_agent::redhat::agent6( + $baseurl = "https://yum.datadoghq.com/beta/${::architecture}/", + $gpgkey = 'https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public', + $manage_repo = true, + $agent_version = 'latest' +) { + + validate_bool($manage_repo) + if $manage_repo { + $public_key_local = '/etc/pki/rpm-gpg/DATADOG_RPM_KEY.public' + + validate_string($baseurl) + + remote_file { 'DATADOG_RPM_KEY.public': + owner => root, + group => root, + mode => '600', + path => $public_key_local, + source => $gpgkey + } + + exec { 'install-gpg-key': + command => "/bin/rpm --import ${public_key_local}", + onlyif => "/usr/bin/gpg --quiet --with-fingerprint -n ${public_key_local} | grep \'A4C0 B90D 7443 CF6E 4E8A A341 F106 8E14 E094 22B3\'", + unless => '/bin/rpm -q gpg-pubkey-e09422b3', + require => Remote_file['DATADOG_RPM_KEY.public'], + } + + yumrepo {'datadog': + enabled => 1, + gpgcheck => 1, + gpgkey => 'https://yum.datadoghq.com/DATADOG_RPM_KEY.public', + descr => 'Datadog, Inc.', + baseurl => $baseurl, + require => Exec['install-gpg-key'], + } + + Package { require => Yumrepo['datadog']} + } + + package { 'datadog-agent-base': + ensure => absent, + before => Package['datadog-agent'], + } + + package { 'datadog-agent': + ensure => $agent_version, + } + + service { 'datadog-agent': + ensure => $::datadog_agent::service_ensure, + enable => $::datadog_agent::service_enable, + hasstatus => false, + pattern => 'dd-agent', + provider => 'redhat', + require => Package['datadog-agent'], + } + +} diff --git a/manifests/reports.pp b/manifests/reports.pp index 375a6c5c..fa691f0a 100644 --- a/manifests/reports.pp +++ b/manifests/reports.pp @@ -39,13 +39,13 @@ } } - file { '/etc/dd-agent/datadog.yaml': + file { '/etc/datadog-agent/datadog-reports.yaml': ensure => file, - content => template('datadog_agent/datadog.yaml.erb'), + content => template('datadog_agent/datadog-reports.yaml.erb'), owner => $puppetmaster_user, group => 'root', mode => '0640', - require => File['/etc/dd-agent'], + require => File['/etc/datadog-agent'], } package{'dogapi': diff --git a/manifests/ubuntu.pp b/manifests/ubuntu.pp index 6a60aef3..ebcca8d8 100644 --- a/manifests/ubuntu.pp +++ b/manifests/ubuntu.pp @@ -30,7 +30,10 @@ ::datadog_agent::ubuntu::install_key { $mykeys: before => File['/etc/apt/sources.list.d/datadog.list'], } + } + file { '/etc/apt/sources.list.d/datadog-beta.list': + ensure => absent, } file { '/etc/apt/sources.list.d/datadog.list': @@ -46,6 +49,7 @@ refreshonly => true, tries => 2, # https://bugs.launchpad.net/launchpad/+bug/1430011 won't get fixed until 16.04 xenial try_sleep => 30, + require => File['/etc/apt/sources.list.d/datadog-beta.list'], } package { 'datadog-agent-base': diff --git a/manifests/ubuntu/agent6.pp b/manifests/ubuntu/agent6.pp new file mode 100644 index 00000000..d7748008 --- /dev/null +++ b/manifests/ubuntu/agent6.pp @@ -0,0 +1,65 @@ +# Class: datadog_agent::ubuntu::agent6 +# +# This class contains the DataDog agent installation mechanism for Debian derivatives +# + +class datadog_agent::ubuntu::agent6( + $apt_key = 'A2923DFF56EDA6E76E55E492D3A80E30382E94DE', + $agent_version = 'latest', + $other_keys = ['935F5A436A5A6E8788F0765B226AE980C7A7DA52'], + $location = 'https://apt.datadoghq.com', + $release = 'beta', + $repos = 'main', +) { + + ensure_packages(['apt-transport-https']) + validate_array($other_keys) + + if !$::datadog_agent::skip_apt_key_trusting { + $mykeys = concat($other_keys, [$apt_key]) + + ::datadog_agent::ubuntu::install_key { $mykeys: + before => File['/etc/apt/sources.list.d/datadog-beta.list'], + } + + } + + file { '/etc/apt/sources.list.d/datadog.list': + ensure => absent, + } + + file { '/etc/apt/sources.list.d/datadog-beta.list': + owner => 'root', + group => 'root', + content => template('datadog_agent/datadog.list.erb'), + notify => Exec['datadog_apt-get_update'], + require => Package['apt-transport-https'], + } + + exec { 'datadog_apt-get_update': + command => '/usr/bin/apt-get update', + refreshonly => true, + tries => 2, # https://bugs.launchpad.net/launchpad/+bug/1430011 won't get fixed until 16.04 xenial + try_sleep => 30, + require => File['/etc/apt/sources.list.d/datadog.list'], + } + + package { 'datadog-agent-base': + ensure => absent, + before => Package['datadog-agent'], + } + + package { 'datadog-agent': + ensure => $agent_version, + require => [File['/etc/apt/sources.list.d/datadog-beta.list'], + Exec['datadog_apt-get_update']], + } + + service { 'datadog-agent': + ensure => $::datadog_agent::service_ensure, + enable => $::datadog_agent::service_enable, + hasstatus => false, + pattern => 'dd-agent', + require => Package['datadog-agent'], + } +} diff --git a/spec/classes/datadog_agent_integrations_apache_spec.rb b/spec/classes/datadog_agent_integrations_apache_spec.rb index c68839da..1b1bc882 100644 --- a/spec/classes/datadog_agent_integrations_apache_spec.rb +++ b/spec/classes/datadog_agent_integrations_apache_spec.rb @@ -1,85 +1,98 @@ 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 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: '', + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:agent6_enable) { enabled } + let(:conf_file) { "#{conf_dir}/apache.yaml" } + + it { should compile.with_all_deps } - skip("doubly undefined behavior") + it { should contain_class('datadog_agent') } + 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 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 end end diff --git a/spec/classes/datadog_agent_integrations_cacti_spec.rb b/spec/classes/datadog_agent_integrations_cacti_spec.rb index 516afa2d..d0456b7a 100644 --- a/spec/classes/datadog_agent_integrations_cacti_spec.rb +++ b/spec/classes/datadog_agent_integrations_cacti_spec.rb @@ -1,30 +1,41 @@ require 'spec_helper' describe 'datadog_agent::integrations::cacti' 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}/cacti.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |agent, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:agent6_enable) { enabled } + let(:conf_file) { "#{conf_dir}/cacti.yaml" } - context 'with default parameters' do - it { should compile } - end + context 'with default parameters' do + it { should compile } + end - context 'with parameters set' do - let(:params) {{ - mysql_host: 'localhost', - mysql_user: 'foo', - mysql_password: 'bar', - rrd_path: 'path', - }} - it { should contain_file(conf_file).with_content(/mysql_host: localhost/) } - it { should contain_file(conf_file).with_content(/mysql_user: foo/) } - it { should contain_file(conf_file).with_content(/mysql_password: bar/) } - it { should contain_file(conf_file).with_content(/rrd_path: path/) } + context 'with parameters set' do + let(:params) {{ + mysql_host: 'localhost', + mysql_user: 'foo', + mysql_password: 'bar', + rrd_path: 'path', + }} + it { should contain_file(conf_file).with_content(/mysql_host: localhost/) } + it { should contain_file(conf_file).with_content(/mysql_user: foo/) } + it { should contain_file(conf_file).with_content(/mysql_password: bar/) } + it { should contain_file(conf_file).with_content(/rrd_path: path/) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_cassandra_spec.rb b/spec/classes/datadog_agent_integrations_cassandra_spec.rb index 23be9779..58f03df5 100644 --- a/spec/classes/datadog_agent_integrations_cassandra_spec.rb +++ b/spec/classes/datadog_agent_integrations_cassandra_spec.rb @@ -1,69 +1,81 @@ require 'spec_helper' describe 'datadog_agent::integrations::cassandra' 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}/cassandra.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/cassandra.yaml" } - context 'with password set' do - let(:params) {{ - user: 'datadog', - password: 'foobar', - }} + it { should compile.with_all_deps } + it { should contain_class('datadog_agent') } - 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 password set' do + let(:params) {{ + user: 'datadog', + password: 'foobar', + }} - it { should contain_file(conf_file).with_content(%r{password: foobar}) } - it { should contain_file(conf_file).without_content(%r{tags: }) } + 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 defaults' do - it { should contain_file(conf_file).with_content(%r{host: localhost}) } - it { should contain_file(conf_file).with_content(%r{user: datadog}) } - end + it { should contain_file(conf_file).with_content(%r{password: foobar}) } + it { should contain_file(conf_file).without_content(%r{tags: }) } - context 'with parameters set' do - let(:params) {{ - password: 'foobar', - host: 'cassandra1', - user: 'baz', - }} + context 'with defaults' do + it { should contain_file(conf_file).with_content(%r{host: localhost}) } + it { should contain_file(conf_file).with_content(%r{user: datadog}) } + end - it { should contain_file(conf_file).with_content(%r{password: foobar}) } - it { should contain_file(conf_file).with_content(%r{host: cassandra1}) } - it { should contain_file(conf_file).with_content(%r{user: baz}) } - end + context 'with parameters set' do + let(:params) {{ + password: 'foobar', + host: 'cassandra1', + user: 'baz', + }} - context 'with tags parameter hash' do - let(:params) {{ - password: 'foobar', - tags: { - 'foo'=> 'bar', - 'baz'=> 'ama', - } - }} - it { should contain_file(conf_file).with_content(/tags:\s+foo: bar\s+baz: ama\s*?[^-]/m) } - end + it { should contain_file(conf_file).with_content(%r{password: foobar}) } + it { should contain_file(conf_file).with_content(%r{host: cassandra1}) } + it { should contain_file(conf_file).with_content(%r{user: baz}) } + end - context 'tags not hash' do - let(:params) {{ - password: 'foobar', - tags: 'aoeu', - }} + context 'with tags parameter hash' do + let(:params) {{ + password: 'foobar', + tags: { + 'foo'=> 'bar', + 'baz'=> 'ama', + } + }} + it { should contain_file(conf_file).with_content(/tags:\s+foo: bar\s+baz: ama\s*?[^-]/m) } + end + + context 'tags not hash' do + let(:params) {{ + password: 'foobar', + tags: 'aoeu', + }} - it { should_not compile } + it { should_not compile } + end + end end end end diff --git a/spec/classes/datadog_agent_integrations_ceph_spec.rb b/spec/classes/datadog_agent_integrations_ceph_spec.rb index 66b6207d..04b8dbc5 100644 --- a/spec/classes/datadog_agent_integrations_ceph_spec.rb +++ b/spec/classes/datadog_agent_integrations_ceph_spec.rb @@ -1,51 +1,60 @@ require 'spec_helper' describe 'datadog_agent::integrations::ceph' 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}/ceph.yaml" } - let(:sudo_conf_file) { '/etc/sudoers.d/datadog_ceph' } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/ceph.yaml" } + let(:sudo_conf_file) { '/etc/sudoers.d/datadog_ceph' } - 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 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(/tags:\s+- name:ceph_cluster\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/bin\/ceph\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } - it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(/tags:\s+- name:ceph_cluster\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/bin\/ceph\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } + it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } + end - context 'with specified tag' do - let(:params) {{ - tags: ['name:my_ceph_cluster'], - }} - it { should contain_file(conf_file).with_content(/tags:\s+- name:my_ceph_cluster\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/bin\/ceph\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } - it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } - end + context 'with specified tag' do + let(:params) {{ + tags: ['name:my_ceph_cluster'], + }} + it { should contain_file(conf_file).with_content(/tags:\s+- name:my_ceph_cluster\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/bin\/ceph\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } + it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } + end - context 'with specified ceph_cmd' do - let(:params) {{ - ceph_cmd: '/usr/local/myceph', - }} - it { should contain_file(conf_file).with_content(/tags:\s+- name:ceph_cluster\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/local\/myceph\s*?[^-]/m) } - it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } - it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } + context 'with specified ceph_cmd' do + let(:params) {{ + ceph_cmd: '/usr/local/myceph', + }} + it { should contain_file(conf_file).with_content(/tags:\s+- name:ceph_cluster\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*ceph_cmd:\s*\/usr\/local\/myceph\s*?[^-]/m) } + it { should contain_file(conf_file).with_content(/^\s*use_sudo:\sTrue$/) } + it { should contain_file(sudo_conf_file).with_content(/^dd-agent\sALL=.*NOPASSWD:\/usr\/bin\/ceph$/) } + end + end end - end diff --git a/spec/classes/datadog_agent_integrations_consul_spec.rb b/spec/classes/datadog_agent_integrations_consul_spec.rb index d88041ca..32747e97 100644 --- a/spec/classes/datadog_agent_integrations_consul_spec.rb +++ b/spec/classes/datadog_agent_integrations_consul_spec.rb @@ -1,23 +1,32 @@ require 'spec_helper' describe 'datadog_agent::integrations::consul' 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}/consul.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 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/consul.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}]") } + end + end end diff --git a/spec/classes/datadog_agent_integrations_disk_spec.rb b/spec/classes/datadog_agent_integrations_disk_spec.rb index efdc2a33..9c3ceeaf 100644 --- a/spec/classes/datadog_agent_integrations_disk_spec.rb +++ b/spec/classes/datadog_agent_integrations_disk_spec.rb @@ -1,46 +1,54 @@ require 'spec_helper' describe 'datadog_agent::integrations::disk' 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}/disk.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/disk.yaml" } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file(conf_file).with_content( - %r{\s+use_mount:\s+no$} - ).with( - owner: dd_user, - group: dd_group, - mode: '0600', - )} - it { is_expected.to contain_file(conf_file).that_requires("Package[#{dd_package}]") } - it { is_expected.to contain_file(conf_file).that_notifies("Service[#{dd_service}]") } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(conf_file).with_content( + %r{\s+use_mount:\s+no$} + ).with( + owner: dd_user, + group: dd_group, + mode: '0600', + )} + it { is_expected.to contain_file(conf_file).that_requires("Package[#{dd_package}]") } + it { is_expected.to contain_file(conf_file).that_notifies("Service[#{dd_service}]") } - context 'compile errors for incorrect values' do - let(:params) {{ use_mount: 'heaps' }} - it do - expect { is_expected.to compile }.to raise_error(/error\s+during\s+compilation/) - end - end + context 'compile errors for incorrect values' do + let(:params) {{ use_mount: 'heaps' }} + it do + expect { is_expected.to compile }.to raise_error(/error\s+during\s+compilation/) + end + end - context 'we handle strings and arrays the same' do - let(:params) {{ - use_mount: 'yes', - excluded_filesystems: [ 'tmpfs', 'dev' ], - excluded_disks: '/dev/sda1', - excluded_disk_re: '/dev/sdb.*', - excluded_mountpoint_re: '/mnt/other.*', - all_partitions: 'yes', - tag_by_filesystem: 'no' - }} - let(:yaml_conf) { - <<-HEREDOC + context 'we handle strings and arrays the same' do + let(:params) {{ + use_mount: 'yes', + excluded_filesystems: [ 'tmpfs', 'dev' ], + excluded_disks: '/dev/sda1', + excluded_disk_re: '/dev/sdb.*', + excluded_mountpoint_re: '/mnt/other.*', + all_partitions: 'yes', + tag_by_filesystem: 'no' + }} + let(:yaml_conf) { + <<-HEREDOC init_config: instances: @@ -55,8 +63,9 @@ all_partitions: yes tag_by_filesystem: no HEREDOC - } - it { is_expected.to contain_file(conf_file).with_content(yaml_conf) } + } + it { is_expected.to contain_file(conf_file).with_content(yaml_conf) } + end + end end - end diff --git a/spec/classes/datadog_agent_integrations_dns_check_spec.rb b/spec/classes/datadog_agent_integrations_dns_check_spec.rb index ca2a941a..e4ab08e1 100644 --- a/spec/classes/datadog_agent_integrations_dns_check_spec.rb +++ b/spec/classes/datadog_agent_integrations_dns_check_spec.rb @@ -1,52 +1,62 @@ require 'spec_helper' describe 'datadog_agent::integrations::dns_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}/dns_check.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/dns_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 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{hostname: google.com}) } - it { should contain_file(conf_file).with_content(%r{nameserver: 8.8.8.8}) } - it { should contain_file(conf_file).with_content(%r{timeout: 5}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{hostname: google.com}) } + it { should contain_file(conf_file).with_content(%r{nameserver: 8.8.8.8}) } + it { should contain_file(conf_file).with_content(%r{timeout: 5}) } + end - context 'with parameters set' do - let(:params) {{ - checks: [ - { - 'hostname' => 'example.com', - 'nameserver' => '1.2.3.4', - 'timeout' => 5, - }, - { - 'hostname' => 'localdomain.com', - 'nameserver' => '4.3.2.1', - 'timeout' => 3, - } - ] - }} + context 'with parameters set' do + let(:params) {{ + checks: [ + { + 'hostname' => 'example.com', + 'nameserver' => '1.2.3.4', + 'timeout' => 5, + }, + { + 'hostname' => 'localdomain.com', + 'nameserver' => '4.3.2.1', + 'timeout' => 3, + } + ] + }} - it { should contain_file(conf_file).with_content(%r{hostname: example.com}) } - it { should contain_file(conf_file).with_content(%r{nameserver: 1.2.3.4}) } - it { should contain_file(conf_file).with_content(%r{timeout: 5}) } - it { should contain_file(conf_file).with_content(%r{hostname: localdomain.com}) } - it { should contain_file(conf_file).with_content(%r{nameserver: 4.3.2.1}) } - it { should contain_file(conf_file).with_content(%r{timeout: 3}) } + it { should contain_file(conf_file).with_content(%r{hostname: example.com}) } + it { should contain_file(conf_file).with_content(%r{nameserver: 1.2.3.4}) } + it { should contain_file(conf_file).with_content(%r{timeout: 5}) } + it { should contain_file(conf_file).with_content(%r{hostname: localdomain.com}) } + it { should contain_file(conf_file).with_content(%r{nameserver: 4.3.2.1}) } + it { should contain_file(conf_file).with_content(%r{timeout: 3}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_docker_daemon_spec.rb b/spec/classes/datadog_agent_integrations_docker_daemon_spec.rb index 4d713e1b..0d885d1d 100644 --- a/spec/classes/datadog_agent_integrations_docker_daemon_spec.rb +++ b/spec/classes/datadog_agent_integrations_docker_daemon_spec.rb @@ -1,70 +1,83 @@ require 'spec_helper' describe 'datadog_agent::integrations::docker_daemon' 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_daemon.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + if !enabled + let(:conf_file) { "#{conf_dir}/docker_daemon.yaml" } + else + let(:conf_file) { "#{conf_dir}/docker.yaml" } + end - 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}]") } + 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}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: unix://var/run/docker.sock}) } + end - context 'with parameters set' do - let(:params) {{ - url: 'unix://foo/bar/baz.sock', - }} - it { should contain_file(conf_file).with_content(%r{url: unix://foo/bar/baz.sock}) } - end + context 'with parameters set' do + let(:params) {{ + url: 'unix://foo/bar/baz.sock', + }} + it { should contain_file(conf_file).with_content(%r{url: unix://foo/bar/baz.sock}) } + 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 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 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' ] - }} + 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 + 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: [''], - }} + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} - skip("undefined behavior") - end + skip("undefined behavior") + end - context 'single value empty string' do - let(:params) {{ - tags: '', - }} + context 'single value empty string' do + let(:params) {{ + tags: '', + }} - skip("doubly undefined behavior") + skip("doubly undefined behavior") + end + end end end - end diff --git a/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb index 1cd7c0d2..b573e260 100644 --- a/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb +++ b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb @@ -1,113 +1,123 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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 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}]") } + 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}) } - it { should contain_file(conf_file).with_content(%r{ cluster_stats: false}) } - it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) } - it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } - it { should_not contain_file(conf_file).with_content(%r{ username}) } - it { should_not contain_file(conf_file).with_content(%r{ password}) } - it { should_not contain_file(conf_file).with_content(%r{ ssl_verify}) } - it { should_not contain_file(conf_file).with_content(%r{ ssl_cert}) } - it { should_not contain_file(conf_file).with_content(%r{ ssl_key}) } - it { should_not contain_file(conf_file).with_content(%r{ tags:}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{ - url: http://localhost:9200}) } + it { should contain_file(conf_file).with_content(%r{ cluster_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } + it { should_not contain_file(conf_file).with_content(%r{ username}) } + it { should_not contain_file(conf_file).with_content(%r{ password}) } + it { should_not contain_file(conf_file).with_content(%r{ ssl_verify}) } + it { should_not contain_file(conf_file).with_content(%r{ ssl_cert}) } + it { should_not contain_file(conf_file).with_content(%r{ ssl_key}) } + it { should_not contain_file(conf_file).with_content(%r{ tags:}) } + end - context 'with parameters set' do - let(:params) {{ - password: 'password', - pending_task_stats: false, - url: 'https://foo:4242', - username: 'username', - ssl_cert: '/etc/ssl/certs/client.pem', - ssl_key: '/etc/ssl/private/client.key', - tags: ['tag1:key1'], - }} - it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) } - it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) } - it { should contain_file(conf_file).with_content(%r{ username: username}) } - it { should contain_file(conf_file).with_content(%r{ password: password}) } - it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) } - it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } - it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } - end + context 'with parameters set' do + let(:params) {{ + password: 'password', + pending_task_stats: false, + url: 'https://foo:4242', + username: 'username', + ssl_cert: '/etc/ssl/certs/client.pem', + ssl_key: '/etc/ssl/private/client.key', + tags: ['tag1:key1'], + }} + it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ username: username}) } + it { should contain_file(conf_file).with_content(%r{ password: password}) } + it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) } + it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } + it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } + end - context 'with multiple instances set' do - let(:params) { - { - instances: [ - { - 'cluster_stats' => true, - 'password' => 'password', - 'pending_task_stats' => false, - 'pshard_stats' => false, - 'url' => 'https://foo:4242', - 'username' => 'username', - 'ssl_verify' => true, - 'ssl_cert' => '/etc/ssl/certs/client.pem', - 'ssl_key' => '/etc/ssl/private/client.key', - 'tags' => ['tag1:key1'], - }, + context 'with multiple instances set' do + let(:params) { { - 'cluster_stats' => true, - 'password' => 'password_2', - 'pending_task_stats' => true, - 'pshard_stats' => false, - 'url' => 'https://bar:2424', - 'username' => 'username_2', - 'ssl_verify' => false, - 'ssl_cert' => '/etc/ssl/certs/client.pem', - 'ssl_key' => '/etc/ssl/private/client.key', - 'tags' => ['tag2:key2'], + instances: [ + { + 'cluster_stats' => true, + 'password' => 'password', + 'pending_task_stats' => false, + 'pshard_stats' => false, + 'url' => 'https://foo:4242', + 'username' => 'username', + 'ssl_verify' => true, + 'ssl_cert' => '/etc/ssl/certs/client.pem', + 'ssl_key' => '/etc/ssl/private/client.key', + 'tags' => ['tag1:key1'], + }, + { + 'cluster_stats' => true, + 'password' => 'password_2', + 'pending_task_stats' => true, + 'pshard_stats' => false, + 'url' => 'https://bar:2424', + 'username' => 'username_2', + 'ssl_verify' => false, + 'ssl_cert' => '/etc/ssl/certs/client.pem', + 'ssl_key' => '/etc/ssl/private/client.key', + 'tags' => ['tag2:key2'], + } + ] } - ] - } - } - it { should contain_file(conf_file).with_content(%r{instances:}) } - it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) } - it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } - it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) } - it { should contain_file(conf_file).with_content(%r{ username: username}) } - it { should contain_file(conf_file).with_content(%r{ password: password}) } - it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } - it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) } - it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } - it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } - it { should contain_file(conf_file).with_content(%r{ - url: https://bar:2424}) } - it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } - it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) } - it { should contain_file(conf_file).with_content(%r{ username: username_2}) } - it { should contain_file(conf_file).with_content(%r{ password: password_2}) } - it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } - it { should contain_file(conf_file).with_content(%r{ ssl_verify: false}) } - it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } - it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag2:key2}) } + } + it { should contain_file(conf_file).with_content(%r{instances:}) } + it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) } + it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ username: username}) } + it { should contain_file(conf_file).with_content(%r{ password: password}) } + it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) } + it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } + it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } + it { should contain_file(conf_file).with_content(%r{ - url: https://bar:2424}) } + it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ username: username_2}) } + it { should contain_file(conf_file).with_content(%r{ password: password_2}) } + it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_verify: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } + it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag2:key2}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_fluentd_spec.rb b/spec/classes/datadog_agent_integrations_fluentd_spec.rb index 2680a59e..894e0b19 100644 --- a/spec/classes/datadog_agent_integrations_fluentd_spec.rb +++ b/spec/classes/datadog_agent_integrations_fluentd_spec.rb @@ -1,52 +1,62 @@ require 'spec_helper' describe 'datadog_agent::integrations::fluentd' 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}/fluentd.yaml" } - - context 'with default parameters' do - it { should compile } - end - - context 'with monitor_agent_url set' do - let(:params) {{ - monitor_agent_url: '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{monitor_agent_url: foobar}) } - it { should contain_file(conf_file).without_content(%r{tags: }) } - - context 'with plugin_ids parameter array' do - let(:params) {{ - monitor_agent_url: 'foobar', - plugin_ids: %w{ foo bar baz }, - }} - it { should contain_file(conf_file).with_content(/plugin_ids:[^-]+- foo\s+- bar\s+- baz\s*?[^-]/m) } - end - - context 'plugin_ids not array' do - let(:params) {{ - monitor_agent_url: 'foobar', - plugin_ids: 'aoeu', + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', }} - - it { should_not compile } + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/fluentd.yaml" } + + context 'with default parameters' do + it { should compile } + end + + context 'with monitor_agent_url set' do + let(:params) {{ + monitor_agent_url: '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{monitor_agent_url: foobar}) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + + context 'with plugin_ids parameter array' do + let(:params) {{ + monitor_agent_url: 'foobar', + plugin_ids: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(/plugin_ids:[^-]+- foo\s+- bar\s+- baz\s*?[^-]/m) } + end + + context 'plugin_ids not array' do + let(:params) {{ + monitor_agent_url: 'foobar', + plugin_ids: 'aoeu', + }} + + it { should_not compile } + end + end end end end diff --git a/spec/classes/datadog_agent_integrations_haproxy_spec.rb b/spec/classes/datadog_agent_integrations_haproxy_spec.rb index eb082ef0..4a9ea4ac 100644 --- a/spec/classes/datadog_agent_integrations_haproxy_spec.rb +++ b/spec/classes/datadog_agent_integrations_haproxy_spec.rb @@ -1,101 +1,111 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + ipaddress: '1.2.3.4', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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 creds set incorrectly' do - let(:params) {{ - 'invalid' => 'is this real life', - }} + 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 - skip 'functionality not yet implemented' do - it { should contain_file(conf_file).without_content(/invalid: is this real life/) } - end - end - - context 'with options set' do - let(:params) {{ - options: { - 'optionk' => 'optionv', - }, - }} - it { should contain_file(conf_file).with_content(%r{optionk: optionv}) } - end - - context 'with instances set' do - let(:params) {{ - instances: [ - { - 'url' => 'http://foo.bar:8421', - 'creds' => { + context 'with creds set correctly' do + let(:params) {{ + creds: { 'username' => 'foo', 'password' => 'bar', }, - 'options' => { - 'optionk1' => 'optionv1', - }, - }, - { - 'url' => 'http://shoe.baz:1248', - 'creds' => { - 'username' => 'shoe', - 'password' => 'baz', - }, - 'options' => { - 'optionk2' => 'optionv2', + }} + 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 + + context 'with options set' do + let(:params) {{ + options: { + 'optionk' => 'optionv', }, - }, - ] - }} - it { should contain_file(conf_file).with_content(%r{url: http://foo.bar:8421}) } - it { should contain_file(conf_file).with_content(%r{username: foo}) } - it { should contain_file(conf_file).with_content(%r{password: bar}) } - it { should contain_file(conf_file).with_content(%r{optionk1: optionv1}) } - it { should contain_file(conf_file).with_content(%r{url: http://shoe.baz:1248}) } - it { should contain_file(conf_file).with_content(%r{username: shoe}) } - it { should contain_file(conf_file).with_content(%r{password: baz}) } - it { should contain_file(conf_file).with_content(%r{optionk2: optionv2}) } + }} + it { should contain_file(conf_file).with_content(%r{optionk: optionv}) } + end + + context 'with instances set' do + let(:params) {{ + instances: [ + { + 'url' => 'http://foo.bar:8421', + 'creds' => { + 'username' => 'foo', + 'password' => 'bar', + }, + 'options' => { + 'optionk1' => 'optionv1', + }, + }, + { + 'url' => 'http://shoe.baz:1248', + 'creds' => { + 'username' => 'shoe', + 'password' => 'baz', + }, + 'options' => { + 'optionk2' => 'optionv2', + }, + }, + ] + }} + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar:8421}) } + it { should contain_file(conf_file).with_content(%r{username: foo}) } + it { should contain_file(conf_file).with_content(%r{password: bar}) } + it { should contain_file(conf_file).with_content(%r{optionk1: optionv1}) } + it { should contain_file(conf_file).with_content(%r{url: http://shoe.baz:1248}) } + it { should contain_file(conf_file).with_content(%r{username: shoe}) } + it { should contain_file(conf_file).with_content(%r{password: baz}) } + it { should contain_file(conf_file).with_content(%r{optionk2: optionv2}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_http_check_spec.rb b/spec/classes/datadog_agent_integrations_http_check_spec.rb index d1a60ff9..bd206efb 100644 --- a/spec/classes/datadog_agent_integrations_http_check_spec.rb +++ b/spec/classes/datadog_agent_integrations_http_check_spec.rb @@ -1,170 +1,180 @@ 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}]") } - - context 'with default parameters' do - it { should contain_file(conf_file).without_content(%r{name: }) } - it { should contain_file(conf_file).without_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).without_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{content_match: }) } - it { should contain_file(conf_file).without_content(%r{include_content: true}) } - it { should contain_file(conf_file).without_content(%r{collect_response_time: true}) } - it { should contain_file(conf_file).without_content(%r{http_response_status_code: }) } - it { should contain_file(conf_file).without_content(%r{disable_ssl_validation: false}) } - it { should contain_file(conf_file).without_content(%r{skip_event: }) } - it { should contain_file(conf_file).without_content(%r{no_proxy: }) } - it { should contain_file(conf_file).without_content(%r{check_certificate_expiration: }) } - it { should contain_file(conf_file).without_content(%r{days_warning: }) } - it { should contain_file(conf_file).without_content(%r{days_critical: }) } - 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) {{ - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - username: 'foouser', - password: 'barpassword', - timeout: 123, - threshold: 456, - window: 789, - content_match: 'foomatch', - include_content: true, - collect_response_time: false, - disable_ssl_validation: true, - skip_event: true, - http_response_status_code: '503', - no_proxy: true, - check_certificate_expiration: true, - days_warning: 14, - days_critical: 7, - }} - - it { should contain_file(conf_file).with_content(%r{name: foo.bar.baz}) } - 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{content_match: foomatch}) } - 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}) } - it { should contain_file(conf_file).with_content(%r{skip_event: true}) } - it { should contain_file(conf_file).with_content(%r{http_response_status_code: 503}) } - it { should contain_file(conf_file).with_content(%r{no_proxy: true}) } - it { should contain_file(conf_file).with_content(%r{check_certificate_expiration: true}) } - it { should contain_file(conf_file).with_content(%r{days_warning: 14}) } - it { should contain_file(conf_file).with_content(%r{days_critical: 7}) } - end - - context 'with headers parameter array' do - let(:params) {{ - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - 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) {{ - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - 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: '', + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', }} - - skip("doubly undefined behavior") - end - end - - - context 'with tags parameter array' do - let(:params) {{ - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - 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) {{ - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - 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 - - 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}) } + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + + context 'with default parameters' do + it { should contain_file(conf_file).without_content(%r{name: }) } + it { should contain_file(conf_file).without_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).without_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{content_match: }) } + it { should contain_file(conf_file).without_content(%r{include_content: true}) } + it { should contain_file(conf_file).without_content(%r{collect_response_time: true}) } + it { should contain_file(conf_file).without_content(%r{http_response_status_code: }) } + it { should contain_file(conf_file).without_content(%r{disable_ssl_validation: false}) } + it { should contain_file(conf_file).without_content(%r{skip_event: }) } + it { should contain_file(conf_file).without_content(%r{no_proxy: }) } + it { should contain_file(conf_file).without_content(%r{check_certificate_expiration: }) } + it { should contain_file(conf_file).without_content(%r{days_warning: }) } + it { should contain_file(conf_file).without_content(%r{days_critical: }) } + 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) {{ + sitename: 'foo.bar.baz', + url: 'http://foo.bar.baz:4096', + username: 'foouser', + password: 'barpassword', + timeout: 123, + threshold: 456, + window: 789, + content_match: 'foomatch', + include_content: true, + collect_response_time: false, + disable_ssl_validation: true, + skip_event: true, + http_response_status_code: '503', + no_proxy: true, + check_certificate_expiration: true, + days_warning: 14, + days_critical: 7, + }} + + it { should contain_file(conf_file).with_content(%r{name: foo.bar.baz}) } + 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{content_match: foomatch}) } + 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}) } + it { should contain_file(conf_file).with_content(%r{skip_event: true}) } + it { should contain_file(conf_file).with_content(%r{http_response_status_code: 503}) } + it { should contain_file(conf_file).with_content(%r{no_proxy: true}) } + it { should contain_file(conf_file).with_content(%r{check_certificate_expiration: true}) } + it { should contain_file(conf_file).with_content(%r{days_warning: 14}) } + it { should contain_file(conf_file).with_content(%r{days_critical: 7}) } + end + + context 'with headers parameter array' do + let(:params) {{ + sitename: 'foo.bar.baz', + url: 'http://foo.bar.baz:4096', + 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) {{ + sitename: 'foo.bar.baz', + url: 'http://foo.bar.baz:4096', + 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) {{ + sitename: 'foo.bar.baz', + url: 'http://foo.bar.baz:4096', + 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) {{ + sitename: 'foo.bar.baz', + url: 'http://foo.bar.baz:4096', + 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 + + 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 end end diff --git a/spec/classes/datadog_agent_integrations_jenkins_spec.rb b/spec/classes/datadog_agent_integrations_jenkins_spec.rb index 2d504368..49de7570 100644 --- a/spec/classes/datadog_agent_integrations_jenkins_spec.rb +++ b/spec/classes/datadog_agent_integrations_jenkins_spec.rb @@ -1,34 +1,43 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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}) } + 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 end - end diff --git a/spec/classes/datadog_agent_integrations_jmx_spec.rb b/spec/classes/datadog_agent_integrations_jmx_spec.rb index 19c55712..4f4e81ef 100644 --- a/spec/classes/datadog_agent_integrations_jmx_spec.rb +++ b/spec/classes/datadog_agent_integrations_jmx_spec.rb @@ -1,81 +1,91 @@ require 'spec_helper' describe 'datadog_agent::integrations::jmx' 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}/jmx.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/jmx.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 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{init_config: \{\}}) } - it { should contain_file(conf_file).with_content(%r{instances: \[\]}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{init_config: \{\}}) } + it { should contain_file(conf_file).with_content(%r{instances: \[\]}) } + end - context 'with parameters set' do - let(:params) do - { - 'init_config' => { - 'custom_jar_paths' => [ - '/path/to/custom/jarfile.jar', - '/path/to/another/custom/jarfile2.jar' - ] - }, - 'instances' => [{ - 'host' => 'jmx1', - 'port' => '867', - 'user' => 'userfoo', - 'password' => 'passbar', - 'jmx_url' => 'service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath', - 'tools_jar_path' => '/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar', - 'java_options' => '-Xmx200m -Xms50m', - 'java_bin_path' => '/usr/java/jdk1.7.0_101/bin/java', - 'trust_store_path' => '/var/lib/jmx/trust_store_path', - 'trust_store_password' => 'hunter2', - 'tags' => { - 'foo' => 'bar', - 'baz' => 'bat' - }, - 'conf' => [{ - 'include' => { - 'domain' => 'my_domain' - } - }] - }] - } - end - it { should contain_file(conf_file).with_content(%r{- ["']?/path/to/custom/jarfile.jar["']?}) } - it { should contain_file(conf_file).with_content(%r{- ["']?/path/to/another/custom/jarfile2.jar["']?}) } - it { should contain_file(conf_file).with_content(%r{host: jmx1}) } + context 'with parameters set' do + let(:params) do + { + 'init_config' => { + 'custom_jar_paths' => [ + '/path/to/custom/jarfile.jar', + '/path/to/another/custom/jarfile2.jar' + ] + }, + 'instances' => [{ + 'host' => 'jmx1', + 'port' => '867', + 'user' => 'userfoo', + 'password' => 'passbar', + 'jmx_url' => 'service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath', + 'tools_jar_path' => '/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar', + 'java_options' => '-Xmx200m -Xms50m', + 'java_bin_path' => '/usr/java/jdk1.7.0_101/bin/java', + 'trust_store_path' => '/var/lib/jmx/trust_store_path', + 'trust_store_password' => 'hunter2', + 'tags' => { + 'foo' => 'bar', + 'baz' => 'bat' + }, + 'conf' => [{ + 'include' => { + 'domain' => 'my_domain' + } + }] + }] + } + end + it { should contain_file(conf_file).with_content(%r{- ["']?/path/to/custom/jarfile.jar["']?}) } + it { should contain_file(conf_file).with_content(%r{- ["']?/path/to/another/custom/jarfile2.jar["']?}) } + it { should contain_file(conf_file).with_content(%r{host: jmx1}) } - # Stringification of integers. - # Puppet treats everything as a string, and then there seems to be - # quoting differences between YAML export deps for Puppet 3.x and Puppet 4.x. - # YAML defaults to string representation, but supports other types, so ends - # up quoting integers from Puppet to explicitly mark out they're strings. - it { should contain_file(conf_file).with_content(%r{port: ["']?867["']?}) } + # Stringification of integers. + # Puppet treats everything as a string, and then there seems to be + # quoting differences between YAML export deps for Puppet 3.x and Puppet 4.x. + # YAML defaults to string representation, but supports other types, so ends + # up quoting integers from Puppet to explicitly mark out they're strings. + it { should contain_file(conf_file).with_content(%r{port: ["']?867["']?}) } - it { should contain_file(conf_file).with_content(%r{jmx_url: ["']?service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath["']?}) } - 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: ["']?/usr/java/jdk1.7.0_101/bin/java["']?}) } - it { should contain_file(conf_file).with_content(%r{java_options: ["']?-Xmx200m -Xms50m["']?}) } - it { should contain_file(conf_file).with_content(%r{trust_store_path: ["']?/var/lib/jmx/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}) } - it { should contain_file(conf_file).with_content(%r{domain: my_domain}) } + it { should contain_file(conf_file).with_content(%r{jmx_url: ["']?service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath["']?}) } + 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: ["']?/usr/java/jdk1.7.0_101/bin/java["']?}) } + it { should contain_file(conf_file).with_content(%r{java_options: ["']?-Xmx200m -Xms50m["']?}) } + it { should contain_file(conf_file).with_content(%r{trust_store_path: ["']?/var/lib/jmx/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}) } + it { should contain_file(conf_file).with_content(%r{domain: my_domain}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_kong_spec.rb b/spec/classes/datadog_agent_integrations_kong_spec.rb index 06201087..415952d7 100644 --- a/spec/classes/datadog_agent_integrations_kong_spec.rb +++ b/spec/classes/datadog_agent_integrations_kong_spec.rb @@ -1,40 +1,50 @@ require 'spec_helper' describe 'datadog_agent::integrations::kong' 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}/kong.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/kong.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}]") } + 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{kong_status_url: http://localhost:8001/status/}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{kong_status_url: http://localhost:8001/status/}) } + end - context 'with params set' do - let(:params) {{ - instances: [ - { - 'status_url' => 'http://foo.bar:8080/status/', - 'tags' => ['baz'] - } - ] - }} + context 'with params set' do + let(:params) {{ + instances: [ + { + 'status_url' => 'http://foo.bar:8080/status/', + 'tags' => ['baz'] + } + ] + }} - it { should contain_file(conf_file).with_content(%r{tags:\n.*- baz}) } - it { should contain_file(conf_file).with_content(%r{kong_status_url: http://foo.bar:8080/status/}) } + it { should contain_file(conf_file).with_content(%r{tags:\n.*- baz}) } + it { should contain_file(conf_file).with_content(%r{kong_status_url: http://foo.bar:8080/status/}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_marathon_spec.rb b/spec/classes/datadog_agent_integrations_marathon_spec.rb index 045d3b50..cc283e41 100644 --- a/spec/classes/datadog_agent_integrations_marathon_spec.rb +++ b/spec/classes/datadog_agent_integrations_marathon_spec.rb @@ -1,37 +1,47 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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', - }} + 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_memcache_spec.rb b/spec/classes/datadog_agent_integrations_memcache_spec.rb index bf42b5a8..71dcbda8 100644 --- a/spec/classes/datadog_agent_integrations_memcache_spec.rb +++ b/spec/classes/datadog_agent_integrations_memcache_spec.rb @@ -1,121 +1,131 @@ require 'spec_helper' describe 'datadog_agent::integrations::memcache' 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}/mcache.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/mcache.yaml" } - it { should compile.with_all_deps } - it { should contain_file(conf_file).with( - owner: dd_user, - group: dd_group, - mode: '0600', - )} + 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).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: localhost}) } - it { should contain_file(conf_file).without_content(/tags:/) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: localhost}) } + it { should contain_file(conf_file).without_content(/tags:/) } + end - context 'with parameters set' do - let(:params) {{ - url: 'foobar', - port: '11212', - items: 'true', - slabs: 'true', - tags: %w{foo bar baz}, - }} - it { should contain_file(conf_file).with_content(%r{url: foobar}) } - it { should contain_file(conf_file).with_content(/port: 11212/) } - it { should contain_file(conf_file).with_content(/items: true/) } - it { should contain_file(conf_file).with_content(/slabs: true/) } - end + context 'with parameters set' do + let(:params) {{ + url: 'foobar', + port: '11212', + items: 'true', + slabs: 'true', + tags: %w{foo bar baz}, + }} + it { should contain_file(conf_file).with_content(%r{url: foobar}) } + it { should contain_file(conf_file).with_content(/port: 11212/) } + it { should contain_file(conf_file).with_content(/items: true/) } + it { should contain_file(conf_file).with_content(/slabs: true/) } + end - context 'with tags parameter single value' do - let(:params) {{ - tags: 'foo', - }} - it { should_not compile } + 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 + 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 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 '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: [''], - }} + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} - skip("undefined behavior") - end + skip("undefined behavior") + end - context 'single value empty string' do - let(:params) {{ - tags: '', - }} + context 'single value empty string' do + let(:params) {{ + tags: '', + }} - skip("doubly undefined behavior") - end - end + skip("doubly undefined behavior") + end + end - context 'with multiple instances set' do - let(:params) { - { - instances: [ - { - 'url' => 'localhost', - 'port' => '11211', - 'items' => true, - 'slabs' => true, - 'tags' => ['tag1:value1'], - }, + context 'with multiple instances set' do + let(:params) { { - 'url' => 'foo.bar', - 'port' => '11212', - 'items' => false, - 'slabs' => false, - 'tags' => ['tag2:value2'], + instances: [ + { + 'url' => 'localhost', + 'port' => '11211', + 'items' => true, + 'slabs' => true, + 'tags' => ['tag1:value1'], + }, + { + 'url' => 'foo.bar', + 'port' => '11212', + 'items' => false, + 'slabs' => false, + 'tags' => ['tag2:value2'], + } + ] } - ] - } - } - it { should contain_file(conf_file).with_content(%r{instances:}) } - it { should contain_file(conf_file).with_content(%r{ - url: localhost}) } - it { should contain_file(conf_file).with_content(%r{ port: 11211}) } - it { should contain_file(conf_file).with_content(%r{ items: true}) } - it { should contain_file(conf_file).with_content(%r{ slabs: true}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag1:value1}) } - it { should contain_file(conf_file).with_content(%r{ - url: foo.bar}) } - it { should contain_file(conf_file).with_content(%r{ port: 11212}) } - it { should contain_file(conf_file).with_content(%r{ items: false}) } - it { should contain_file(conf_file).with_content(%r{ slabs: false}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag2:value2}) } + } + it { should contain_file(conf_file).with_content(%r{instances:}) } + it { should contain_file(conf_file).with_content(%r{ - url: localhost}) } + it { should contain_file(conf_file).with_content(%r{ port: 11211}) } + it { should contain_file(conf_file).with_content(%r{ items: true}) } + it { should contain_file(conf_file).with_content(%r{ slabs: true}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag1:value1}) } + it { should contain_file(conf_file).with_content(%r{ - url: foo.bar}) } + it { should contain_file(conf_file).with_content(%r{ port: 11212}) } + it { should contain_file(conf_file).with_content(%r{ items: false}) } + it { should contain_file(conf_file).with_content(%r{ slabs: false}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag2:value2}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_mesos_master_spec.rb b/spec/classes/datadog_agent_integrations_mesos_master_spec.rb index 8578137a..bfb73b6e 100644 --- a/spec/classes/datadog_agent_integrations_mesos_master_spec.rb +++ b/spec/classes/datadog_agent_integrations_mesos_master_spec.rb @@ -1,36 +1,46 @@ require 'spec_helper' describe 'datadog_agent::integrations::mesos_master' 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_master.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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_master.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}]") } + 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: 10}) } - it { should contain_file(conf_file).with_content(%r{url: http://localhost:5050}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{default_timeout: 10}) } + 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_mongo_spec.rb b/spec/classes/datadog_agent_integrations_mongo_spec.rb index 1fbf187b..6fe7109c 100644 --- a/spec/classes/datadog_agent_integrations_mongo_spec.rb +++ b/spec/classes/datadog_agent_integrations_mongo_spec.rb @@ -1,139 +1,149 @@ 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 'with custom collections one mongos' do - let(:params) {{ - servers: [ - { - 'host' => '127.0.0.1', - 'port' => '12345', - 'tags' => %w{ foo bar baz }, - 'collections' => %w{ collection_1 collection_2 }, - }, - { - 'host' => '127.0.0.2', - 'port' => '45678', - 'tags' => %w{baz bat}, - 'collections' => %w{ collection_1 collection_2 }, - } - ] - }} - - it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) } - it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678/\s+tags:\s+- baz\s+- bat\s+collections:\s+- collection_1\s+- collection_2}) } - - end - - context 'with custom collections multiple mongo' do - let(:params) {{ - servers: [ - { - 'host' => '127.0.0.1', - 'port' => '12345', - 'tags' => %w{ foo bar baz }, - 'collections' => %w{ collection_1 collection_2 }, - } - ] - }} - - it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) } - end - - context 'with additional metrics' do - let(:params) {{ - servers: [ - { - 'host' => '127.0.0.1', - 'port' => '12345', - 'tags' => %w{ foo bar baz }, - 'additional_metrics' => %w{ top }, - } - ] - }} - - it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+additional_metrics:\s+- top}) } - 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 } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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 'with custom collections one mongos' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '12345', + 'tags' => %w{ foo bar baz }, + 'collections' => %w{ collection_1 collection_2 }, + }, + { + 'host' => '127.0.0.2', + 'port' => '45678', + 'tags' => %w{baz bat}, + 'collections' => %w{ collection_1 collection_2 }, + } + ] + }} + + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) } + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678/\s+tags:\s+- baz\s+- bat\s+collections:\s+- collection_1\s+- collection_2}) } + + end + + context 'with custom collections multiple mongo' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '12345', + 'tags' => %w{ foo bar baz }, + 'collections' => %w{ collection_1 collection_2 }, + } + ] + }} + + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) } + end + + context 'with additional metrics' do + let(:params) {{ + servers: [ + { + 'host' => '127.0.0.1', + 'port' => '12345', + 'tags' => %w{ foo bar baz }, + 'additional_metrics' => %w{ top }, + } + ] + }} + + it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+additional_metrics:\s+- top}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_mysql_spec.rb b/spec/classes/datadog_agent_integrations_mysql_spec.rb index ece7ded5..ef7db2f3 100644 --- a/spec/classes/datadog_agent_integrations_mysql_spec.rb +++ b/spec/classes/datadog_agent_integrations_mysql_spec.rb @@ -1,78 +1,88 @@ 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 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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 default parameters' do + it { should_not compile } + end - context 'with password set' do - let(:params) {{ - password: 'foobar', - }} + 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 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: }) } + 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 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', - }} + 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 + 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 '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', - }} + context 'tags not array' do + let(:params) {{ + password: 'foobar', + tags: 'aoeu', + }} - it { should_not compile } + it { should_not compile } + end + end end end end diff --git a/spec/classes/datadog_agent_integrations_nginx_spec.rb b/spec/classes/datadog_agent_integrations_nginx_spec.rb index 99cdd1f4..78bf747f 100644 --- a/spec/classes/datadog_agent_integrations_nginx_spec.rb +++ b/spec/classes/datadog_agent_integrations_nginx_spec.rb @@ -1,40 +1,50 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 '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} - } - ] - }} + 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) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_ntp_spec.rb b/spec/classes/datadog_agent_integrations_ntp_spec.rb index f6cfa537..7f4fe90b 100644 --- a/spec/classes/datadog_agent_integrations_ntp_spec.rb +++ b/spec/classes/datadog_agent_integrations_ntp_spec.rb @@ -1,35 +1,43 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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/) } + context 'with parameters set' do + let(:params) {{ + offset_threshold: 42, + }} + it { should contain_file(conf_file).with_content(/offset_threshold: 42/) } + end + end end - - end diff --git a/spec/classes/datadog_agent_integrations_php_fpm_spec.rb b/spec/classes/datadog_agent_integrations_php_fpm_spec.rb index 27c37a83..f6c797e5 100644 --- a/spec/classes/datadog_agent_integrations_php_fpm_spec.rb +++ b/spec/classes/datadog_agent_integrations_php_fpm_spec.rb @@ -1,66 +1,76 @@ require 'spec_helper' describe 'datadog_agent::integrations::php_fpm' 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}/php_fpm.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/php_fpm.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 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(/status_url: http:\/\/localhost\/status/) } - it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/ping/) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/status/) } + it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/ping/) } + end - context 'with parameters set' do - let(:params) {{ - status_url: 'http://localhost/fpm_status', - ping_url: 'http://localhost/fpm_ping', - }} - it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) } - it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) } - end + context 'with parameters set' do + let(:params) {{ + status_url: 'http://localhost/fpm_status', + ping_url: 'http://localhost/fpm_ping', + }} + it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) } + it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) } + end - context 'with http_host set' do - let(:params) {{ - status_url: 'http://localhost/fpm_status', - ping_url: 'http://localhost/fpm_ping', - http_host: 'php_fpm_server', - }} - it { should contain_file(conf_file).with_content(/http_host: php_fpm_server/) } - it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) } - it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) } - end + context 'with http_host set' do + let(:params) {{ + status_url: 'http://localhost/fpm_status', + ping_url: 'http://localhost/fpm_ping', + http_host: 'php_fpm_server', + }} + it { should contain_file(conf_file).with_content(/http_host: php_fpm_server/) } + it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) } + it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) } + end - context 'with instances set' do - let(:params) {{ - instances: [ - { - 'status_url' => 'http://localhost/a/fpm_status', - 'ping_url' => 'http://localhost/a/fpm_ping', - }, - { - 'status_url' => 'http://localhost/b/fpm_status', - 'ping_url' => 'http://localhost/b/fpm_ping', - }, - ] - }} - it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/a\/fpm_status/) } - it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/a\/fpm_ping/) } - it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/b\/fpm_status/) } - it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/b\/fpm_ping/) } + context 'with instances set' do + let(:params) {{ + instances: [ + { + 'status_url' => 'http://localhost/a/fpm_status', + 'ping_url' => 'http://localhost/a/fpm_ping', + }, + { + 'status_url' => 'http://localhost/b/fpm_status', + 'ping_url' => 'http://localhost/b/fpm_ping', + }, + ] + }} + it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/a\/fpm_status/) } + it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/a\/fpm_ping/) } + it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/b\/fpm_status/) } + it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/b\/fpm_ping/) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_postfix_spec.rb b/spec/classes/datadog_agent_integrations_postfix_spec.rb index a1c54a37..a9f955d7 100644 --- a/spec/classes/datadog_agent_integrations_postfix_spec.rb +++ b/spec/classes/datadog_agent_integrations_postfix_spec.rb @@ -1,75 +1,85 @@ require 'spec_helper' describe 'datadog_agent::integrations::postfix' 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}/postfix.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/postfix.yaml" } - it { should compile.with_all_deps } - it { should contain_file(conf_file).with( - owner: dd_user, - group: dd_group, - mode: '0600', - )} + 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).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{ - directory: /var/spool/postfix}) } - it { should contain_file(conf_file).with_content(%r{ queues:}) } - it { should contain_file(conf_file).with_content(%r{ - active}) } - it { should contain_file(conf_file).with_content(%r{ - deferred}) } - it { should contain_file(conf_file).with_content(%r{ - incoming}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/postfix}) } + it { should contain_file(conf_file).with_content(%r{ queues:}) } + it { should contain_file(conf_file).with_content(%r{ - active}) } + it { should contain_file(conf_file).with_content(%r{ - deferred}) } + it { should contain_file(conf_file).with_content(%r{ - incoming}) } + end - context 'with parameters set' do - let(:params) {{ - directory: '/var/spool/foobaz', - queues: ['foobar'], - tags: ['tag1:value1'], - }} - it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/foobaz}) } - it { should contain_file(conf_file).with_content(%r{ queues:}) } - it { should contain_file(conf_file).with_content(%r{ - foobar}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag1:value1}) } - end + context 'with parameters set' do + let(:params) {{ + directory: '/var/spool/foobaz', + queues: ['foobar'], + tags: ['tag1:value1'], + }} + it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/foobaz}) } + it { should contain_file(conf_file).with_content(%r{ queues:}) } + it { should contain_file(conf_file).with_content(%r{ - foobar}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag1:value1}) } + end - context 'with multiple instances set' do - let(:params) { - { - instances: [ - { - 'directory' => '/var/spool/postfix-2', - 'queues' => 'active', - 'tags' => ['tag2:value2'], - }, + context 'with multiple instances set' do + let(:params) { { - 'directory' => '/var/spool/postfix-3', - 'queues' => 'incoming', - 'tags' => ['tag3:value3'], - }, - - ] - } - } - it { should contain_file(conf_file).with_content(%r{instances:}) } - it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/postfix-2}) } - it { should contain_file(conf_file).with_content(%r{ queues:}) } - it { should contain_file(conf_file).with_content(%r{ - active}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag2:value2}) } - it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/postfix-3}) } - it { should contain_file(conf_file).with_content(%r{ queues:}) } - it { should contain_file(conf_file).with_content(%r{ - incoming}) } - it { should contain_file(conf_file).with_content(%r{ tags:}) } - it { should contain_file(conf_file).with_content(%r{ - tag3:value3}) } + instances: [ + { + 'directory' => '/var/spool/postfix-2', + 'queues' => 'active', + 'tags' => ['tag2:value2'], + }, + { + 'directory' => '/var/spool/postfix-3', + 'queues' => 'incoming', + 'tags' => ['tag3:value3'], + }, + + ] + } + } + it { should contain_file(conf_file).with_content(%r{instances:}) } + it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/postfix-2}) } + it { should contain_file(conf_file).with_content(%r{ queues:}) } + it { should contain_file(conf_file).with_content(%r{ - active}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag2:value2}) } + it { should contain_file(conf_file).with_content(%r{ - directory: /var/spool/postfix-3}) } + it { should contain_file(conf_file).with_content(%r{ queues:}) } + it { should contain_file(conf_file).with_content(%r{ - incoming}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag3:value3}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_postgres_spec.rb b/spec/classes/datadog_agent_integrations_postgres_spec.rb index abf44c72..34696c07 100644 --- a/spec/classes/datadog_agent_integrations_postgres_spec.rb +++ b/spec/classes/datadog_agent_integrations_postgres_spec.rb @@ -1,117 +1,126 @@ 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{^\s*use_psycopg2: }) } - it { should contain_file(conf_file).without_content(%r{tags: })} - it { should contain_file(conf_file).without_content(%r{^[^#]*relations: }) } - end - - context 'with use_psycopg2 enabled' do - let(:params) {{ - use_psycopg2: true, - password: 'abc123', + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', }} - it { should contain_file(conf_file).with_content(%r{use_psycopg2: true}) } - end + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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 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}) } + context 'with default parameters' do + it { should_not compile } + end - context 'with custom metric query missing %s' do + context 'with password set' do let(:params) {{ - host: 'postgres1', - dbname: 'cats', - port: 4142, - username: 'monitoring', password: 'abc123', - custom_metrics: { - 'query_is_missing_%s' => { - 'query' => 'select * from fuzz', - 'metrics' => { }, - } - } }} - it do - expect { - is_expected.to compile - }.to raise_error(/custom_metrics require %s for metric substitution/) + + 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{^\s*use_psycopg2: }) } + it { should contain_file(conf_file).without_content(%r{tags: })} + it { should contain_file(conf_file).without_content(%r{^[^#]*relations: }) } end - end - context 'with custom metric query' do - let(:params) {{ - host: 'postgres1', - dbname: 'cats', - port: 4142, - username: 'monitoring', - password: 'abc123', - custom_metrics: { - 'foo_gooo_bar_query' => { - 'query' => 'select foo, %s from bar', - 'metrics' => { - "gooo" => ["custom_metric.tag.gooo", "GAUGE"] - }, - 'descriptors' => [["foo", "custom_metric.tag.foo"]] - } - } - }} - it { is_expected.to compile } - it { should contain_file(conf_file).with_content(%r{^[^#]*custom_metrics:}) } - it { should contain_file(conf_file).with_content(%r{\s+query:\s*['"]?select foo, %s from bar['"]?}) } - it { should contain_file(conf_file).with_content(%r{\s+metrics:}) } - it { should contain_file(conf_file).with_content(%r{\s+"gooo":\s+\[custom_metric.tag.gooo, GAUGE\]}) } - it { should contain_file(conf_file).with_content(%r{\s+query.*\n\s+relation:\s*false}) } - it { should contain_file(conf_file).with_content(%r{\s+descriptors.*\n\s+-\s+\[foo, custom_metric.tag.foo\]}) } + context 'with use_psycopg2 enabled' do + let(:params) {{ + use_psycopg2: true, + password: 'abc123', + }} + it { should contain_file(conf_file).with_content(%r{use_psycopg2: true}) } + 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}) } + + context 'with custom metric query missing %s' do + let(:params) {{ + host: 'postgres1', + dbname: 'cats', + port: 4142, + username: 'monitoring', + password: 'abc123', + custom_metrics: { + 'query_is_missing_%s' => { + 'query' => 'select * from fuzz', + 'metrics' => { }, + } + } + }} + it do + expect { + is_expected.to compile + }.to raise_error(/custom_metrics require %s for metric substitution/) + end + end + + context 'with custom metric query' do + let(:params) {{ + host: 'postgres1', + dbname: 'cats', + port: 4142, + username: 'monitoring', + password: 'abc123', + custom_metrics: { + 'foo_gooo_bar_query' => { + 'query' => 'select foo, %s from bar', + 'metrics' => { + "gooo" => ["custom_metric.tag.gooo", "GAUGE"] + }, + 'descriptors' => [["foo", "custom_metric.tag.foo"]] + } + } + }} + it { is_expected.to compile } + it { should contain_file(conf_file).with_content(%r{^[^#]*custom_metrics:}) } + it { should contain_file(conf_file).with_content(%r{\s+query:\s*['"]?select foo, %s from bar['"]?}) } + it { should contain_file(conf_file).with_content(%r{\s+metrics:}) } + it { should contain_file(conf_file).with_content(%r{\s+"gooo":\s+\[custom_metric.tag.gooo, GAUGE\]}) } + it { should contain_file(conf_file).with_content(%r{\s+query.*\n\s+relation:\s*false}) } + it { should contain_file(conf_file).with_content(%r{\s+descriptors.*\n\s+-\s+\[foo, custom_metric.tag.foo\]}) } + end + end end end end - end diff --git a/spec/classes/datadog_agent_integrations_process_spec.rb b/spec/classes/datadog_agent_integrations_process_spec.rb index 89412c42..b3af2e04 100644 --- a/spec/classes/datadog_agent_integrations_process_spec.rb +++ b/spec/classes/datadog_agent_integrations_process_spec.rb @@ -1,41 +1,51 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb b/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb index a011cf12..a44b590c 100644 --- a/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb +++ b/spec/classes/datadog_agent_integrations_rabbitmq_spec.rb @@ -1,60 +1,70 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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).with_content(%r{rabbitmq_user: guest}) } - it { should contain_file(conf_file).with_content(%r{rabbitmq_pass: guest}) } - it { should contain_file(conf_file).with_content(%r{ssl_verify: true}) } - it { should contain_file(conf_file).with_content(%r{tag_families: false}) } - it { should contain_file(conf_file).without_content(%r{nodes:}) } - it { should contain_file(conf_file).without_content(%r{nodes_regexes:}) } - it { should contain_file(conf_file).without_content(%r{queues:}) } - it { should contain_file(conf_file).without_content(%r{queues_regexes:}) } - it { should contain_file(conf_file).without_content(%r{vhosts:}) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{rabbitmq_api_url:}) } + it { should contain_file(conf_file).with_content(%r{rabbitmq_user: guest}) } + it { should contain_file(conf_file).with_content(%r{rabbitmq_pass: guest}) } + it { should contain_file(conf_file).with_content(%r{ssl_verify: true}) } + it { should contain_file(conf_file).with_content(%r{tag_families: false}) } + it { should contain_file(conf_file).without_content(%r{nodes:}) } + it { should contain_file(conf_file).without_content(%r{nodes_regexes:}) } + it { should contain_file(conf_file).without_content(%r{queues:}) } + it { should contain_file(conf_file).without_content(%r{queues_regexes:}) } + 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', - ssl_verify: false, - tag_families: true, - nodes: %w{ node1 node2 node3 }, - nodes_regexes: %w{ ^regex1 regex2$ regex3* }, - queues: %w{ queue1 queue2 queue3 }, - queues_regexes: %w{ ^regex4 regex5$ regex6* }, - 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{ssl_verify: false}) } - it { should contain_file(conf_file).with_content(%r{tag_families: true}) } - it { should contain_file(conf_file).with_content(%r{nodes:\s+- node1\s+- node2\s+- node3}) } - it { should contain_file(conf_file).with_content(%r{nodes_regexes:\s+- \^regex1\s+- regex2\$\s+- regex3\*}) } - 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{queues_regexes:\s+- \^regex4\s+- regex5\$\s+- regex6\*}) } - it { should contain_file(conf_file).with_content(%r{vhosts:\s+- vhost1\s+- vhost2\s+- vhost3}) } + context 'with parameters set' do + let(:params) {{ + url: 'http://rabbit1:15672/', + username: 'foo', + password: 'bar', + ssl_verify: false, + tag_families: true, + nodes: %w{ node1 node2 node3 }, + nodes_regexes: %w{ ^regex1 regex2$ regex3* }, + queues: %w{ queue1 queue2 queue3 }, + queues_regexes: %w{ ^regex4 regex5$ regex6* }, + 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{ssl_verify: false}) } + it { should contain_file(conf_file).with_content(%r{tag_families: true}) } + it { should contain_file(conf_file).with_content(%r{nodes:\s+- node1\s+- node2\s+- node3}) } + it { should contain_file(conf_file).with_content(%r{nodes_regexes:\s+- \^regex1\s+- regex2\$\s+- regex3\*}) } + 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{queues_regexes:\s+- \^regex4\s+- regex5\$\s+- regex6\*}) } + it { should contain_file(conf_file).with_content(%r{vhosts:\s+- vhost1\s+- vhost2\s+- vhost3}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_redis_spec.rb b/spec/classes/datadog_agent_integrations_redis_spec.rb index e15d9017..509bf454 100644 --- a/spec/classes/datadog_agent_integrations_redis_spec.rb +++ b/spec/classes/datadog_agent_integrations_redis_spec.rb @@ -1,55 +1,64 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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}) } - it { should contain_file(conf_file).with_content(%r{command_stats: false}) } - end + 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}) } + it { should contain_file(conf_file).with_content(%r{command_stats: false}) } + 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, - command_stats: true, - }} - 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}) } - it { should contain_file(conf_file).with_content(%r{command_stats: true}) } + 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, + command_stats: true, + }} + 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}) } + it { should contain_file(conf_file).with_content(%r{command_stats: true}) } + end + end end - end diff --git a/spec/classes/datadog_agent_integrations_riak_spec.rb b/spec/classes/datadog_agent_integrations_riak_spec.rb index aa1f835c..c4a4b2be 100644 --- a/spec/classes/datadog_agent_integrations_riak_spec.rb +++ b/spec/classes/datadog_agent_integrations_riak_spec.rb @@ -1,76 +1,86 @@ require 'spec_helper' describe 'datadog_agent::integrations::riak' 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}/riak.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/riak.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}]") } + 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:8098/stats}) } - it { should contain_file(conf_file).without_content(%r{tags: }) } - end + context 'with default parameters' do + it { should contain_file(conf_file).with_content(%r{url: http://localhost:8098/stats}) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + end - context 'with parameters set' do - let(:params) {{ - url: 'http://foo.bar.baz:8098/stats', - tags: %w{ foo bar baz }, - }} - it { should contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:8098/stats}) } - it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } - end - context 'with tags parameter single value' do - let(:params) {{ - tags: 'foo', - }} - it { should_not compile } + context 'with parameters set' do + let(:params) {{ + url: 'http://foo.bar.baz:8098/stats', + tags: %w{ foo bar baz }, + }} + it { should contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:8098/stats}) } + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } + 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 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 + 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 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: [''], - }} + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} - skip("undefined behavior") - end + skip("undefined behavior") + end - context 'single value empty string' do - let(:params) {{ - tags: '', - }} + context 'single value empty string' do + let(:params) {{ + tags: '', + }} - skip("doubly undefined behavior") + skip("doubly undefined behavior") + end + end end end end diff --git a/spec/classes/datadog_agent_integrations_solr_spec.rb b/spec/classes/datadog_agent_integrations_solr_spec.rb index 0aea0cf5..0682ff44 100644 --- a/spec/classes/datadog_agent_integrations_solr_spec.rb +++ b/spec/classes/datadog_agent_integrations_solr_spec.rb @@ -1,56 +1,66 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_ssh_spec.rb b/spec/classes/datadog_agent_integrations_ssh_spec.rb index 1a1bdc82..9818b158 100644 --- a/spec/classes/datadog_agent_integrations_ssh_spec.rb +++ b/spec/classes/datadog_agent_integrations_ssh_spec.rb @@ -1,32 +1,42 @@ require 'spec_helper' describe 'datadog_agent::integrations::ssh' 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}/ssh.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/ssh.yaml" } - context 'with default parameters' do - it { should compile } - end + context 'with default parameters' do + it { should compile } + end - context 'with parameters set' do - let(:params) {{ - host: 'localhost', - port: 222, - username: 'foo', - password: 'bar', - sftp_check: false, - }} - it { should contain_file(conf_file).with_content(/host: localhost/) } - it { should contain_file(conf_file).with_content(/port: 222/) } - it { should contain_file(conf_file).with_content(/username: foo/) } - it { should contain_file(conf_file).with_content(/password: bar/) } - it { should contain_file(conf_file).without_content(/private_key_file:/) } + context 'with parameters set' do + let(:params) {{ + host: 'localhost', + port: 222, + username: 'foo', + password: 'bar', + sftp_check: false, + }} + it { should contain_file(conf_file).with_content(/host: localhost/) } + it { should contain_file(conf_file).with_content(/port: 222/) } + it { should contain_file(conf_file).with_content(/username: foo/) } + it { should contain_file(conf_file).with_content(/password: bar/) } + it { should contain_file(conf_file).without_content(/private_key_file:/) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_tcp_check_spec.rb b/spec/classes/datadog_agent_integrations_tcp_check_spec.rb index aadb6245..d28c8fff 100644 --- a/spec/classes/datadog_agent_integrations_tcp_check_spec.rb +++ b/spec/classes/datadog_agent_integrations_tcp_check_spec.rb @@ -1,96 +1,105 @@ require 'spec_helper' describe 'datadog_agent::integrations::tcp_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}/tcp_check.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/tcp_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 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: }) } - it { should contain_file(conf_file).without_content(%r{host: }) } - it { should contain_file(conf_file).without_content(%r{port: }) } - it { should contain_file(conf_file).without_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{collect_response_time: }) } - it { should contain_file(conf_file).without_content(%r{skip_event: }) } - it { should contain_file(conf_file).without_content(%r{tags: }) } - end + context 'with default parameters' do + it { should contain_file(conf_file).without_content(%r{name: }) } + it { should contain_file(conf_file).without_content(%r{host: }) } + it { should contain_file(conf_file).without_content(%r{port: }) } + it { should contain_file(conf_file).without_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{collect_response_time: }) } + it { should contain_file(conf_file).without_content(%r{skip_event: }) } + it { should contain_file(conf_file).without_content(%r{tags: }) } + end - context 'with parameters set' do - let(:params) {{ - check_name: 'foo.bar.baz', - host: 'foo.bar.baz', - port: '80', - timeout: 123, - threshold: 456, - window: 789, - collect_response_time: true, - skip_event: true, - }} + context 'with parameters set' do + let(:params) {{ + check_name: 'foo.bar.baz', + host: 'foo.bar.baz', + port: '80', + timeout: 123, + threshold: 456, + window: 789, + collect_response_time: true, + skip_event: true, + }} - it { should contain_file(conf_file).with_content(%r{name: foo.bar.baz}) } - it { should contain_file(conf_file).with_content(%r{host: foo.bar.baz}) } - it { should contain_file(conf_file).with_content(%r{port: 80}) } - 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{collect_response_time: true}) } - it { should contain_file(conf_file).with_content(%r{skip_event: true}) } - end + it { should contain_file(conf_file).with_content(%r{name: foo.bar.baz}) } + it { should contain_file(conf_file).with_content(%r{host: foo.bar.baz}) } + it { should contain_file(conf_file).with_content(%r{port: 80}) } + 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{collect_response_time: true}) } + it { should contain_file(conf_file).with_content(%r{skip_event: true}) } + end - context 'with tags parameter array' do - let(:params) {{ - check_name: 'foo.bar.baz', - host: 'foo.bar.baz', - port: '80', - tags: [ '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 array' do + let(:params) {{ + check_name: 'foo.bar.baz', + host: 'foo.bar.baz', + port: '80', + tags: [ '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) {{ - check_name: 'foo.bar.baz', - host: 'foo.bar.baz', - port: '80', - tags: [ 'foo', '', 'baz' ] - }} + context 'with tags parameter empty values' do + context 'mixed in with other tags' do + let(:params) {{ + check_name: 'foo.bar.baz', + host: 'foo.bar.baz', + port: '80', + tags: [ 'foo', '', 'baz' ] + }} - it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } - end + 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: [''], - }} + context 'single element array of an empty string' do + let(:params) {{ + tags: [''], + }} - skip("undefined behavior") - end + skip("undefined behavior") + end - context 'single value empty string' do - let(:params) {{ - tags: '', - }} + context 'single value empty string' do + let(:params) {{ + tags: '', + }} - skip("doubly undefined behavior") + skip("doubly undefined behavior") + end + end end end - end diff --git a/spec/classes/datadog_agent_integrations_tomcat_spec.rb b/spec/classes/datadog_agent_integrations_tomcat_spec.rb index a463df89..3a93a9b4 100644 --- a/spec/classes/datadog_agent_integrations_tomcat_spec.rb +++ b/spec/classes/datadog_agent_integrations_tomcat_spec.rb @@ -1,57 +1,67 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_twemproxy_spec.rb b/spec/classes/datadog_agent_integrations_twemproxy_spec.rb index bb7b58fe..437e7d6e 100644 --- a/spec/classes/datadog_agent_integrations_twemproxy_spec.rb +++ b/spec/classes/datadog_agent_integrations_twemproxy_spec.rb @@ -1,46 +1,56 @@ require 'spec_helper' describe 'datadog_agent::integrations::twemproxy' 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}/twemproxy.yaml" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/twemproxy.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 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: 22222}) } - end + 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: 22222}) } + end - context 'with parameters set' do - let(:params) {{ - instances: [ - { - 'host' => 'twemproxy1', - 'port' => '1234', - }, - { - 'host' => 'twemproxy2', - 'port' => '4567', - } - ] - }} - it { should contain_file(conf_file).with_content(%r{host: twemproxy1}) } - it { should contain_file(conf_file).with_content(%r{port: 1234}) } - it { should contain_file(conf_file).with_content(%r{host: twemproxy2}) } - it { should contain_file(conf_file).with_content(%r{port: 4567}) } + context 'with parameters set' do + let(:params) {{ + instances: [ + { + 'host' => 'twemproxy1', + 'port' => '1234', + }, + { + 'host' => 'twemproxy2', + 'port' => '4567', + } + ] + }} + it { should contain_file(conf_file).with_content(%r{host: twemproxy1}) } + it { should contain_file(conf_file).with_content(%r{port: 1234}) } + it { should contain_file(conf_file).with_content(%r{host: twemproxy2}) } + it { should contain_file(conf_file).with_content(%r{port: 4567}) } + end + end end end diff --git a/spec/classes/datadog_agent_integrations_varnish_spec.rb b/spec/classes/datadog_agent_integrations_varnish_spec.rb index 557d7296..54579db1 100644 --- a/spec/classes/datadog_agent_integrations_varnish_spec.rb +++ b/spec/classes/datadog_agent_integrations_varnish_spec.rb @@ -1,38 +1,48 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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 }, - }} + 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}) } + 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 end end diff --git a/spec/classes/datadog_agent_integrations_zk_spec.rb b/spec/classes/datadog_agent_integrations_zk_spec.rb index 4a971222..0218a4fa 100644 --- a/spec/classes/datadog_agent_integrations_zk_spec.rb +++ b/spec/classes/datadog_agent_integrations_zk_spec.rb @@ -1,53 +1,63 @@ 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" } + context 'supported agents - v5 and v6' do + agents = { '5' => false, '6' => true } + agents.each do |_, enabled| + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + if !enabled + let(:conf_dir) { '/etc/dd-agent/conf.d' } + else + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + end + 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}]") } + 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 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) } + 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 end end diff --git a/spec/classes/datadog_agent_redhat_spec.rb b/spec/classes/datadog_agent_redhat_spec.rb index a5093789..318646fd 100644 --- a/spec/classes/datadog_agent_redhat_spec.rb +++ b/spec/classes/datadog_agent_redhat_spec.rb @@ -28,6 +28,52 @@ end + # it should install the packages + it do + should contain_package('datadog-agent-base')\ + .with_ensure('absent')\ + .that_comes_before('Package[datadog-agent]') + end + it do + should contain_package('datadog-agent')\ + .with_ensure('latest') + end + + # it should be able to start the service and enable the service by default + it do + should contain_service('datadog-agent')\ + .that_requires('Package[datadog-agent]') + end +end + +describe 'datadog_agent::redhat::agent6' do + let(:facts) do + { + osfamily: 'redhat', + operatingsystem: 'Fedora', + architecture: 'x86_64' + } + end + + # it should install the mirror + context 'with manage_repo => true' do + let(:params){ {:manage_repo => true} } + it do + should contain_yumrepo('datadog') + .with_enabled(1)\ + .with_gpgcheck(1)\ + .with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY.public')\ + .with_baseurl('https://yum.datadoghq.com/beta/x86_64/') + end + end + context 'with manage_repo => false' do + let(:params){ {:manage_repo => false} } + it do + should_not contain_yumrepo('datadog') + end + end + + # it should install the packages it do should contain_package('datadog-agent-base')\ diff --git a/spec/classes/datadog_agent_reports_spec.rb b/spec/classes/datadog_agent_reports_spec.rb index 8933687a..374b1f3a 100644 --- a/spec/classes/datadog_agent_reports_spec.rb +++ b/spec/classes/datadog_agent_reports_spec.rb @@ -46,7 +46,7 @@ end it do - should contain_file('/etc/dd-agent/datadog.yaml')\ + should contain_file('/etc/datadog-agent/datadog-reports.yaml')\ .with_owner('puppet')\ .with_group('root') end @@ -90,7 +90,7 @@ end it do - should contain_file('/etc/dd-agent/datadog.yaml')\ + should contain_file('/etc/datadog-agent/datadog-reports.yaml')\ .with_owner('puppet')\ .with_group('root') end diff --git a/spec/classes/datadog_agent_spec.rb b/spec/classes/datadog_agent_spec.rb index 8c0e5780..1aeece66 100644 --- a/spec/classes/datadog_agent_spec.rb +++ b/spec/classes/datadog_agent_spec.rb @@ -38,6 +38,7 @@ it { should contain_class('datadog_agent::params') } end + it { should contain_file('/etc/datadog-agent') } it { should contain_file('/etc/dd-agent') } it { should contain_concat('/etc/dd-agent/datadog.conf') } it { should contain_file('/etc/dd-agent/conf.d').with_ensure('directory') } @@ -619,6 +620,64 @@ it { should contain_class('datadog_agent::redhat') } end end + + describe "datadog_agent 6 class common actions on #{operatingsystem}" do + let(:params) { { puppet_run_reports: true, puppet_gem_provider: 'gem', agent6_enable: true } } + let(:facts) do + { + operatingsystem: operatingsystem, + osfamily: DEBIAN_OS.include?(operatingsystem) ? 'debian' : 'redhat' + } + end + + it { should compile.with_all_deps } + + it { should contain_class('datadog_agent') } + + describe 'datadog_agent imports the default params' do + it { should contain_class('datadog_agent::params') } + end + + it { should contain_file('/etc/datadog-agent') } + it { should_not contain_file('/etc/dd-agent') } + it { should_not contain_concat('/etc/dd-agent/datadog.conf') } + it { should contain_file('/etc/datadog-agent/datadog.yaml') } + it { should_not contain_file('/etc/dd-agent/conf.d').with_ensure('directory') } + it { should contain_file('/etc/datadog-agent/conf.d').with_ensure('directory') } + + it { should contain_class('datadog_agent::reports') } + + describe 'agent6 parameter check' do + context 'with defaults' do + context 'for basic beta settings' do + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^api_key: your_API_key\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^conf_path: \"{0,1}\/etc\/datadog-agent\/conf.d\"{0,1}\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^cmd_port: \"{0,1}5001\"{0,1}\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^dd_url: \"{0,1}https:\/\/app.datadoghq.com\"{0,1}\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^enable_metadata_collection: true\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^dogstatsd_port: \"{0,1}8125\"{0,1}\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^log_file: \"{0,1}\/var\/log\/datadog\/agent.log\"{0,1}\n/, + )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^log_level: info\n/, + )} + end + end + end + end end end diff --git a/spec/classes/datadog_agent_ubuntu_spec.rb b/spec/classes/datadog_agent_ubuntu_spec.rb index c31852b5..0bf53269 100644 --- a/spec/classes/datadog_agent_ubuntu_spec.rb +++ b/spec/classes/datadog_agent_ubuntu_spec.rb @@ -9,6 +9,8 @@ end it do + contain_file('/etc/apt/sources.list.d/datadog-beta.list') + .with_ensure('absent') contain_file('/etc/apt/sources.list.d/datadog.list')\ .with_content(%r{deb\s+https://apt.datadoghq.com/\s+stable\s+main}) end @@ -18,29 +20,77 @@ it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') } it do should contain_file('/etc/apt/sources.list.d/datadog.list')\ - .that_notifies('Exec[datadog_apt-get_update]') + .that_notifies('exec[datadog_apt-get_update]') end it { should contain_exec('datadog_apt-get_update') } # it should install the packages it do should contain_package('apt-transport-https')\ - .that_comes_before('File[/etc/apt/sources.list.d/datadog.list]') + .that_comes_before('file[/etc/apt/sources.list.d/datadog.list]') end it do should contain_package('datadog-agent-base')\ .with_ensure('absent')\ - .that_comes_before('Package[datadog-agent]') + .that_comes_before('package[datadog-agent]') end it do should contain_package('datadog-agent')\ - .that_requires('File[/etc/apt/sources.list.d/datadog.list]')\ - .that_requires('Exec[datadog_apt-get_update]') + .that_requires('file[/etc/apt/sources.list.d/datadog.list]')\ + .that_requires('exec[datadog_apt-get_update]') end # it should be able to start the service and enable the service by default it do should contain_service('datadog-agent')\ - .that_requires('Package[datadog-agent]') + .that_requires('package[datadog-agent]') + end +end + +describe 'datadog_agent::ubuntu::agent6' do + let(:facts) do + { + osfamily: 'debian', + operatingsystem: 'Ubuntu' + } + end + + it do + contain_file('/etc/apt/sources.list.d/datadog.list') + .with_ensure('absent') + contain_file('/etc/apt/sources.list.d/datadog-beta.list')\ + .with_content(%r{deb\s+https://apt.datadoghq.com/\s+beta\s+main}) + end + + # it should install the mirror + it { should contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') } + it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') } + + it do + should contain_file('/etc/apt/sources.list.d/datadog-beta.list')\ + .that_notifies('exec[datadog_apt-get_update]') + end + it { should contain_exec('datadog_apt-get_update') } + + # it should install the packages + it do + should contain_package('apt-transport-https')\ + .that_comes_before('file[/etc/apt/sources.list.d/datadog-beta.list]') + end + it do + should contain_package('datadog-agent-base')\ + .with_ensure('absent')\ + .that_comes_before('package[datadog-agent]') + end + it do + should contain_package('datadog-agent')\ + .that_requires('file[/etc/apt/sources.list.d/datadog-beta.list]')\ + .that_requires('exec[datadog_apt-get_update]') + end + + # it should be able to start the service and enable the service by default + it do + should contain_service('datadog-agent')\ + .that_requires('package[datadog-agent]') end end diff --git a/templates/datadog.yaml.erb b/templates/datadog-reports.yaml.erb similarity index 100% rename from templates/datadog.yaml.erb rename to templates/datadog-reports.yaml.erb diff --git a/templates/datadog6.yaml.erb b/templates/datadog6.yaml.erb new file mode 100644 index 00000000..836b5266 --- /dev/null +++ b/templates/datadog6.yaml.erb @@ -0,0 +1,29 @@ +<% +require 'yaml' + +if RUBY_VERSION < "1.9" +# Hack to avoid ruby 1.8 always reordering the hashes and +# changing this template resource at every run +# See https://github.com/DataDog/puppet-datadog-agent/issues/43 +# Taken from http://www.dzone.com/snippets/generating-yaml-hashes-sorted +class Hash + # Replacing the to_yaml function so it'll serialize hashes sorted (by their keys) + # + # Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb + def to_yaml( opts = {} ) + YAML::quick_emit( object_id, opts ) do |out| + out.map( taguri, to_yaml_style ) do |map| + sort.each do |k, v| # <-- here's my addition (the 'sort') + map.add( k, v ) + end + end + end + end +end +end +%> +# +# MANAGED BY PUPPET +# +--- +<%= @agent_config.to_yaml.gsub(/^\s{2}/, '') %>