From c8d8902382cff2be584e9f6bd99c568ba34e7603 Mon Sep 17 00:00:00 2001 From: Remy Mathieu Date: Fri, 17 May 2019 10:55:46 +0200 Subject: [PATCH 1/4] Force Chef version. --- .kitchen.docker.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index 923370119c347..3b0dc6243fb70 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -4,14 +4,23 @@ driver: use_sudo: false platforms: - - name: ubuntu-14.04 # Exclude this OS for now, due to some odd behavior with the NTP check on CircleCI systems. # See https://circleci.com/gh/DataDog/chef-datadog/19 # and http://support.ntp.org/bin/view/Support/KnownOsIssues#Section_9.2.4.2.5.3. # - name: ubuntu-12.04 + + - name: ubuntu-14.04 + driver_config: + require_chef_omnibus: 12.7.2 - name: centos-6.6 + driver_config: + require_chef_omnibus: 12.7.2 - name: centos-7.7 + driver_config: + require_chef_omnibus: 12.7.2 - name: debian-8.11 + driver_config: + require_chef_omnibus: 12.7.2 suites: - name: dd-agent-handler From 1d9f9310343af82a17f70d4e9d6b5af5c60e6117 Mon Sep 17 00:00:00 2001 From: Remy Mathieu Date: Fri, 17 May 2019 11:02:18 +0200 Subject: [PATCH 2/4] Use chef 14 on CircleCI. --- .kitchen.docker.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index 3b0dc6243fb70..eadd3ccb694e0 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -11,16 +11,16 @@ platforms: - name: ubuntu-14.04 driver_config: - require_chef_omnibus: 12.7.2 + require_chef_omnibus: 14.12 - name: centos-6.6 driver_config: - require_chef_omnibus: 12.7.2 + require_chef_omnibus: 14.12 - name: centos-7.7 driver_config: - require_chef_omnibus: 12.7.2 + require_chef_omnibus: 14.12 - name: debian-8.11 driver_config: - require_chef_omnibus: 12.7.2 + require_chef_omnibus: 14.12 suites: - name: dd-agent-handler From 34af82d4c1f9e051baa10f468a83eb3dbfa89426 Mon Sep 17 00:00:00 2001 From: Remy Mathieu Date: Fri, 17 May 2019 11:21:56 +0200 Subject: [PATCH 3/4] Rubocop compliance. --- recipes/dd-handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/dd-handler.rb b/recipes/dd-handler.rb index 80861c21c11b8..1e8335ae88c9a 100644 --- a/recipes/dd-handler.rb +++ b/recipes/dd-handler.rb @@ -26,7 +26,7 @@ end if node['datadog']['chef_handler_version'] && - Gem::Version.new(node['datadog']['chef_handler_version']) < Gem::Version.new('0.10.0') + Gem::Version.new(node['datadog']['chef_handler_version']) < Gem::Version.new('0.10.0') Chef::Log.error('We do not support chef_handler_version < v0.10.0 anymore, please use a more recent version.') return end From 1bd1eaa73f1c606b16cc2ddb99707e0d68e0d069 Mon Sep 17 00:00:00 2001 From: Remy Mathieu Date: Fri, 17 May 2019 13:45:47 +0200 Subject: [PATCH 4/4] Fix Chef spec. --- spec/dd-agent_spec.rb | 110 ++++++++++++++++++++++++++++++++++++++-- spec/shared_examples.rb | 20 ++++++++ 2 files changed, 127 insertions(+), 3 deletions(-) diff --git a/spec/dd-agent_spec.rb b/spec/dd-agent_spec.rb index 92cebca076083..5588c0fec2901 100644 --- a/spec/dd-agent_spec.rb +++ b/spec/dd-agent_spec.rb @@ -232,6 +232,9 @@ def set_env_var(name, value) end end + # Allow a hash for Agent version 6 + # ---------------------- + context 'allows a hash for agent version' do context 'when ubuntu' do cached(:chef_run) do @@ -240,7 +243,7 @@ def set_env_var(name, value) :version => '14.04' ) do |node| node.normal['datadog'] = { - 'agent6' => false, + 'agent6' => true, 'api_key' => 'somethingnotnil', 'agent6_version' => { 'debian' => '1:6.9.0-1', @@ -298,7 +301,7 @@ def set_env_var(name, value) :version => '25' ) do |node| node.normal['datadog'] = { - 'agent6' => false, + 'agent6' => true, 'api_key' => 'somethingnotnil', 'agent6_version' => { 'debian' => '1:6.9.0-1', @@ -321,7 +324,7 @@ def set_env_var(name, value) :version => '6.9' ) do |node| node.normal['datadog'] = { - 'agent6' => false, + 'agent6' => true, 'api_key' => 'somethingnotnil', 'agent6_version' => { 'debian' => '1:6.9.0-1', @@ -338,6 +341,107 @@ def set_env_var(name, value) end end + # Allow a hash for Agent version 5 + # ---------------------- + + context 'allows a hash for agent version v5' do + context 'when ubuntu' do + cached(:chef_run) do + ChefSpec::SoloRunner.new( + :platform => 'ubuntu', + :version => '14.04' + ) do |node| + node.normal['datadog'] = { + 'agent6' => false, + 'api_key' => 'somethingnotnil', + 'agent_version' => { + 'debian' => '1:5.32.2-1', + 'rhel' => '5.32.2-1', + 'windows' => '5.4.0' + }, + } + end.converge described_recipe + end + + it_behaves_like 'debianoids datadog-agent v5' + end + + context 'when windows' do + cached(:chef_run) do + set_env_var('ProgramData', 'C:\ProgramData') + ChefSpec::SoloRunner.new( + :platform => 'windows', + :version => '2012R2', + :file_cache_path => 'C:/chef/cache' + ) do |node| + node.normal['datadog'] = { + 'agent6' => false, + 'api_key' => 'somethingnotnil', + 'agent_version' => { + 'debian' => '1:5.32.2-1', + 'rhel' => '5.32.2-1', + 'windows' => '5.4.0' + }, + } + end.converge described_recipe + end + + temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi') + + it_behaves_like 'windows Datadog Agent v5', :msi + # remote_file source gets converted to an array, so we need to do + # some tricky things to be able to regex against it + # Relevant: http://stackoverflow.com/a/12325983 + # But we should probably assert the full default attribute somewhere... + it 'installs agent 5.4.0' do + expect(chef_run.remote_file(temp_file).source.to_s) + .to match(/ddagent-cli-5.4.0.msi/) + end + end + + context 'when fedora' do + cached(:chef_run) do + ChefSpec::SoloRunner.new( + :platform => 'fedora', + :version => '25' + ) do |node| + node.normal['datadog'] = { + 'agent6' => false, + 'api_key' => 'somethingnotnil', + 'agent6_version' => { + 'debian' => '1:5.32.2-1', + 'rhel' => '5.32.2-1', + 'windows' => '5.4.0' + }, + } + end.converge described_recipe + end + + it_behaves_like 'rhellions datadog-agent v5' + end + + context 'when rhel' do + cached(:chef_run) do + ChefSpec::SoloRunner.new( + :platform => 'redhat', + :version => '6.9' + ) do |node| + node.normal['datadog'] = { + 'agent6' => false, + 'api_key' => 'somethingnotnil', + 'agent_version' => { + 'debian' => '1:5.32.2-1', + 'rhel' => '5.32.2-1', + 'windows' => '5.4.0' + }, + } + end.converge described_recipe + end + + it_behaves_like 'rhellions datadog-agent v5' + end + end + context 'package action' do context 'default :install' do cached(:chef_run) do diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 2e88ff0e574bd..4f82e77841ca9 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -46,10 +46,22 @@ end end +shared_examples_for 'datadog-agent v5' do + it_behaves_like 'common linux resources v5' +end + shared_examples_for 'datadog-agent' do it_behaves_like 'common linux resources' end +shared_examples_for 'debianoids datadog-agent v5' do + it_behaves_like 'datadog-agent v5' + + it 'installs the datadog-agent' do + expect(chef_run).to install_apt_package 'datadog-agent' + end +end + shared_examples_for 'debianoids datadog-agent' do it_behaves_like 'datadog-agent' @@ -58,6 +70,14 @@ end end +shared_examples_for 'rhellions datadog-agent v5' do + it_behaves_like 'datadog-agent v5' + + it 'installs the datadog-agent' do + expect(chef_run).to install_yum_package 'datadog-agent' + end +end + shared_examples_for 'rhellions datadog-agent' do it_behaves_like 'datadog-agent'