From 6cf167c8bdf5541262a099d875757c7eae4a1619 Mon Sep 17 00:00:00 2001 From: NSSPKrishna Date: Sat, 18 May 2024 13:51:17 +0530 Subject: [PATCH] feat(super-agent): Included Super agent, super agent logs target --- attributes/default.rb | 2 + resources/newrelic_install.rb | 21 ++++++---- spec/unit/resources/newrelic_install_spec.rb | 42 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index e624539..6eaccf6 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -24,6 +24,8 @@ # logs-integration # php-agent-installer # dotnet-agent-installer +# super-agent +# logs-integration-super-agent default['newrelic_install']['targets'] = [] ######## diff --git a/resources/newrelic_install.rb b/resources/newrelic_install.rb index 0403a55..5c09a34 100644 --- a/resources/newrelic_install.rb +++ b/resources/newrelic_install.rb @@ -65,18 +65,25 @@ def check_license end def check_targets - allowedTargets = Set['infrastructure-agent-installer', 'logs-integration', 'php-agent-installer', 'dotnet-agent-installer'] - allowedTargetsString = 'infrastructure-agent-installer, logs-integration, php-agent-installer, dotnet-agent-installer' - incomingTargets = new_resource.targets.to_set + allowed_targets = Set.new(%w( + infrastructure-agent-installer + logs-integration + php-agent-installer + dotnet-agent-installer + super-agent + logs-integration-super-agent + )) + allowed_targets_string = allowed_targets.join(', ') + incoming_targets = new_resource.targets.to_set - if incomingTargets.nil? || incomingTargets.empty? + if incoming_targets.nil? || incoming_targets.empty? raise ArgumentError, 'Targets must contain at least one installation target' end - raise ArgumentError, "Targets must only contains valid value(#{allowedTargetsString})" unless incomingTargets.subset?(allowedTargets) + raise ArgumentError, "Targets must only contains valid value(#{allowed_targets_string})" unless incoming_targets.subset?(allowed_targets) - if incomingTargets.include?('logs-integration') - raise ArgumentError, 'Targets must include infrastructure-agent-installer if log is included' unless incomingTargets.include?('infrastructure-agent-installer') + if incoming_targets.include?('logs-integration') + raise ArgumentError, 'Targets must include infrastructure-agent-installer if log is included' unless incoming_targets.include?('infrastructure-agent-installer') end end diff --git a/spec/unit/resources/newrelic_install_spec.rb b/spec/unit/resources/newrelic_install_spec.rb index da77e4f..fd45be9 100644 --- a/spec/unit/resources/newrelic_install_spec.rb +++ b/spec/unit/resources/newrelic_install_spec.rb @@ -230,4 +230,46 @@ expect(subject).to run_powershell_script('newrelic install').with(code: include('-n dotnet-agent-installer')) end end + + context 'when targets only contains super agent' do + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = ['super-agent'] + + it 'should execute with target infra and skip core' do + expect(subject).to run_execute('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) + end + + it 'run bash newrelic install command with super-agent' do + expect(subject).to run_execute('newrelic install').with(command: include('super-agent')) + end + + it 'run powershell newrelic install command without super-agent' do + expect(subject).not_to run_powershell_script('newrelic install').with(code: include('super-agent')) + end + end + + context 'when targets contains super agent infra agent and logs' do + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = %w(super-agent infrastructure-agent-installer logs-integration) + + it 'should execute with target infra and skip core' do + expect(subject).to run_execute('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) + end + + it 'run bash newrelic install command with super-agent' do + expect(subject).to run_execute('newrelic install').with(command: include('super-agent')) + end + + it 'run bash newrelic install command with infra' do + expect(subject).to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) + end + + it 'run bash newrelic install command with logs' do + expect(subject).to run_execute('newrelic install').with(command: include('logs-integration')) + end + end end