Add separate test case for system-probe spec
MODIFY
recipes/system-probe.rb
recipes/system-probe.rb
@@ -24,13 +24,22 @@ sysprobe_agent_start = node['datadog']['system_probe']['enabled'] ? :start : :st
# Configures system-probe agent
system_probe_config_file = ::File.join(node['datadog']['agent6_config_dir'], 'system-probe.yaml')
template system_probe_config_file do
+ extra_config = {}
+ if node['datadog']['extra_config'] && node['datadog']['extra_config']['system_probe']
+ node['datadog']['extra_config']['system_probe'].each do |k, v|
+ next if v.nil?
+ extra_config[k] = v
+ end
+ end
+
source 'system_probe.yaml.erb'
variables(
enabled: node['datadog']['system_probe']['enabled'],
sysprobe_socket: node['datadog']['system_probe']['sysprobe_socket'],
debug_port: node['datadog']['system_probe']['debug_port'],
bpf_debug: node['datadog']['system_probe']['bpf_debug'],
- enable_conntrack: node['datadog']['system_probe']['enable_conntrack']
+ enable_conntrack: node['datadog']['system_probe']['enable_conntrack'],
+ extra_config: extra_config
)
owner 'dd-agent'
group 'root'

MODIFY
spec/dd-agent_spec.rb
spec/dd-agent_spec.rb
@@ -1103,45 +1103,6 @@ describe 'datadog::dd-agent' do
end
end
- context 'system-probe with extra_config params set' do
- cached(:chef_run) do
- ChefSpec::SoloRunner.new(
- platform: 'ubuntu',
- version: '14.04'
- ) do |node|
- node.name 'chef-nodename'
- node.normal['datadog'] = {
- 'api_key' => 'somethingnotnil',
- 'agent6' => true,
- 'system_probe_config' => {
- 'max_conns_per_message' => '1000'
- }
- }
- end.converge described_recipe
- end
-
- it 'is created' do
- expect(chef_run).to create_template('/etc/datadog-agent/system-probe.yaml')
- end
-
- it 'contains expected YAML configuration' do
- expected_yaml = <<-EOF
- system_probe_config:
- enabled: true
- sysprobe_socket: "/opt/datadog-agent/run/sysprobe.sock"
- debug_port: 7654
- bpf_debug: true
- enable_conntrack: false
- max_conns_per_message: 500
- EOF
-
- expect(chef_run).to(render_file('/etc/datadog-agent/system-probe.yaml').with_content { |content|
- expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
- })
- end
- end
- end
-
describe 'agent version set' do
context 'on windows' do
cached(:chef_run) do

ADD
spec/system-probe_spec.rb
+require 'spec_helper'
+
+describe 'datadog::system-probe' do
+ context 'with configuration' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ platform: 'ubuntu',
+ version: '16.04'
+ ) do |node|
+ node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
+ node.normal['datadog'] = {
+ 'api_key' => 'somethingnotnil',
+ 'agent6' => true,
+ 'system_probe' => {
+ 'debug_port' => 123,
+ 'bpf_debug' => true,
+ 'sysprobe_socket' => '/test/ing.sock'
+ }
+ }
+ end.converge described_recipe
+ end
+
+ it 'is created' do
+ expect(chef_run).to create_template('/etc/datadog-agent/system-probe.yaml')
+ end
+
+ it 'contains expected YAML configuration' do
+ expected_yaml = <<-EOF
+ system_probe_config:
+ bpf_debug: true
+ debug_port: 123
+ enable_conntrack: false
+ enabled: false
+ sysprobe_socket: "/test/ing.sock"
+ EOF
+
+ expect(chef_run).to(render_file('/etc/datadog-agent/system-probe.yaml').with_content { |content|
+ expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
+ })
+ end
+ end
+
+ context 'with extra_config params set' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ platform: 'ubuntu',
+ version: '16.04'
+ ) do |node|
+ node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
+ node.normal['datadog'] = {
+ 'api_key' => 'somethingnotnil',
+ 'agent6' => true,
+ 'extra_config' => {
+ 'system_probe' => {
+ 'max_tracked_connections' => 1000
+ }
+ }
+ }
+ end.converge described_recipe
+ end
+
+ it 'is created' do
+ expect(chef_run).to create_template('/etc/datadog-agent/system-probe.yaml')
+ end
+
+ it 'contains expected YAML configuration' do
+ expected_yaml = <<-EOF
+ system_probe_config:
+ bpf_debug: false
+ debug_port: 0
+ enable_conntrack: false
+ enabled: false
+ sysprobe_socket: "/opt/datadog-agent/run/sysprobe.sock"
+ max_tracked_connections: 1000
+ EOF
+
+ expect(chef_run).to(render_file('/etc/datadog-agent/system-probe.yaml').with_content { |content|
+ expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
+ })
+ end
+ end
+end
\ No newline at end of file

MODIFY
templates/default/system_probe.yaml.erb
templates/default/system_probe.yaml.erb
<%
## Populate system_probe_config ##
system_probe_config = {
- system_probe_config: {
+ system_probe_config: @extra_config.merge({
enabled: node['datadog']['system_probe']["enabled"],
sysprobe_socket: node['datadog']['system_probe']['sysprobe_socket'],
debug_port: node['datadog']['system_probe']['debug_port'],
bpf_debug: node['datadog']['system_probe']['bpf_debug'],
enable_conntrack: node['datadog']['system_probe']['enable_conntrack'],
+ })
}
-}
-
-# Take into account options defined under ['extra_config']['system_probe_config']
-system_probe_config = @extra_config['system_probe_config'].merge(system_probe_config) unless @extra_config['system_probe_config'].nil?
-%>
# Generated by Chef, local modifications will be overwritten

Add separate test case for system-probe spec