diff --git a/test/kitchen/test/integration/common/rspec_datadog/spec_helper.rb b/test/kitchen/test/integration/common/rspec_datadog/spec_helper.rb index d8dfbdfdd93e8..b45eb78aa4094 100644 --- a/test/kitchen/test/integration/common/rspec_datadog/spec_helper.rb +++ b/test/kitchen/test/integration/common/rspec_datadog/spec_helper.rb @@ -288,7 +288,6 @@ def windows_service_status(service) raise "windows_service_status is only for windows" unless os == :windows # Language-independent way of getting the service status res = `powershell -command \"try { (get-service #{service} -ErrorAction Stop).Status } catch { write-host NOTINSTALLED }\"` - puts res return (res).upcase.strip end diff --git a/test/kitchen/test/integration/win-agent-with-cws-option/rspec_datadog/win-agent-with-cws-option_spec.rb b/test/kitchen/test/integration/win-agent-with-cws-option/rspec_datadog/win-agent-with-cws-option_spec.rb index 63871305a75fd..26ea800519b83 100644 --- a/test/kitchen/test/integration/win-agent-with-cws-option/rspec_datadog/win-agent-with-cws-option_spec.rb +++ b/test/kitchen/test/integration/win-agent-with-cws-option/rspec_datadog/win-agent-with-cws-option_spec.rb @@ -3,16 +3,8 @@ shared_examples_for 'a Windows Agent with CWS driver disabled' do - # We retrieve the value defined in kitchen.yml because there is no simple way - # to set env variables on the target machine or via parameters in Kitchen/Busser - # See https://github.com/test-kitchen/test-kitchen/issues/662 for reference - let(:expect_cws_installed) { - parse_dna().fetch('dd-agent-rspec').fetch('cws_included') - } - - it 'has the service disabled' do - - if expect_cws_installed + if expect_windows_cws? + it 'has the service disabled' do expect(is_windows_service_disabled("ddprocmon")).to be_truthy end end @@ -23,51 +15,50 @@ expect(is_windows_service_installed("datadog-system-probe")).to be_truthy end - # We retrieve the value defined in kitchen.yml because there is no simple way - # to set env variables on the target machine or via parameters in Kitchen/Busser - # See https://github.com/test-kitchen/test-kitchen/issues/662 for reference - - # the `let` has to be inside an it block. - let(:expect_cws_installed) { - parse_dna().fetch('dd-agent-rspec').fetch('cws_included') - } - - it 'has properly installed driver files' do - if expect_cws_installed + if expect_windows_cws? + it 'has required services installed' do expect(is_windows_service_installed("datadog-security-agent")).to be_truthy expect(is_windows_service_installed("ddprocmon")).to be_truthy - + end + it 'has driver files' do program_files = safe_program_files expect(File).to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.cat") expect(File).to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.sys") expect(File).to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.inf") - else + end + + it 'does not have the driver running on install' do + ## verify that the driver is not started yet + expect(is_service_running?("ddprocmon")).to be_falsey + end + else + ## if windows CWS is not expected, do the reverse check (that services aren't installed, files + ## not present, etc.) Once CWS is released, remove this part of the test. + it 'does not have cws services installed' do expect(is_windows_service_installed("datadog-security-agent")).to be_falsey expect(is_windows_service_installed("ddprocmon")).to be_falsey - + end + it 'does not have driver files' do program_files = safe_program_files expect(File).not_to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.cat") expect(File).not_to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.sys") expect(File).not_to exist("#{program_files}\\DataDog\\Datadog Agent\\bin\\agent\\ddprocmon.inf") - end end - it 'does not have the driver running on install' do - ## verify that the driver is not started yet - expect(is_service_running?("ddprocmon")).to be_falsey - end + + end shared_examples_for 'a Windows Agent with CWS running' do - # We retrieve the value defined in kitchen.yml because there is no simple way - # to set env variables on the target machine or via parameters in Kitchen/Busser - # See https://github.com/test-kitchen/test-kitchen/issues/662 for reference - let(:expect_cws_installed) { - parse_dna().fetch('dd-agent-rspec').fetch('cws_included') - } - it 'can start security agent' do - if expect_cws_installed + if expect_windows_cws? + it 'has cws services not started by default' do + expect(is_service_running?("datadog-system-probe")).to be_falsey + expect(is_service_running?("datadog-security-agent")).to be_falsey + end + + it 'can start security agent' do + sa_conf_path = "" sp_conf_path = "" if os != :windows @@ -102,8 +93,6 @@ spconfYaml["runtime_security_config"]["enabled"] = true File.write(sp_conf_path, spconfYaml.to_yaml) - expect(is_service_running?("datadog-system-probe")).to be_falsey - expect(is_service_running?("datadog-security-agent")).to be_falsey stop "datadog-agent" start "datadog-agent" @@ -111,15 +100,22 @@ expect(is_service_running?("datadogagent")).to be_truthy expect(is_service_running?("datadog-system-probe")).to be_truthy expect(is_service_running?("datadog-security-agent")).to be_truthy - - + end + it 'can gracefully shut down security agent' do stop "datadog-agent" + ## these tests return false for any state other than running. So "shutting down" + ## will erroneously pass here expect(is_service_running?("datadogagent")).to be_falsey expect(is_service_running?("datadog-system-probe")).to be_falsey expect(is_service_running?("datadog-security-agent")).to be_falsey + + ## so also check that the process is actually gone + expect(security_agent_running?).to be_falsey + expect(system_probe_running?).to be_falsey + end - end + end ## endif expect CWS, no tests at all if not expected. end