Skip to content

Commit

Permalink
feat(super-agent): Included Super agent, super agent logs target
Browse files Browse the repository at this point in the history
  • Loading branch information
NSSPKrishna committed May 20, 2024
1 parent e262bd5 commit 0fb8193
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# logs-integration
# php-agent-installer
# dotnet-agent-installer
# super-agent
# logs-integration-super-agent
default['newrelic_install']['targets'] = []

########
Expand Down
21 changes: 14 additions & 7 deletions resources/newrelic_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 42 additions & 0 deletions spec/unit/resources/newrelic_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 infra' do
expect(subject).to run_execute('newrelic install').with(command: include('super-agent'))
end

it 'run powershell newrelic install command without infra' do
expect(subject).not_to run_powershell_script('newrelic install').with(code: include('infrastructure-agent-installer'))
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 infra' 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
1 change: 1 addition & 0 deletions tmp/rspec_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"3.12.3","examples":[{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:1:1]","description":"raises api key missing error","full_description":"newrelic-install::default when api key is undefined raises api key missing error","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":13,"run_time":0.154436,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:2:1]","description":"raises account key missing error","full_description":"newrelic-install::default when account key is undefined raises account key missing error","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":25,"run_time":0.066804,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:3:1]","description":"raises region missing error","full_description":"newrelic-install::default when region is undefined raises region missing error","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":38,"run_time":0.07367,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:4:1]","description":"raise targets missing error when targets undefined","full_description":"newrelic-install::default when targets is undefined raise targets missing error when targets undefined","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":52,"run_time":0.062116,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:5:1]","description":"raise targets error when have invalid target","full_description":"newrelic-install::default when targets contain invalid value raise targets error when have invalid target","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":67,"run_time":0.069562,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:6:1]","description":"raise infra is required error","full_description":"newrelic-install::default when targets only contains log raise infra is required error","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":82,"run_time":0.068012,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:7:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when targets only contains infra should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":93,"run_time":0.085218,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:7:2]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets only contains infra run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":97,"run_time":0.13034,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:8:1]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets only contains infra, logs and php run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":108,"run_time":0.070162,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:8:2]","description":"run bash newrelic install command with logs","full_description":"newrelic-install::default when targets only contains infra, logs and php run bash newrelic install command with logs","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":112,"run_time":0.080969,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:8:3]","description":"run bash newrelic install command with php","full_description":"newrelic-install::default when targets only contains infra, logs and php run bash newrelic install command with php","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":116,"run_time":0.064224,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:9:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when targets only contains php should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":127,"run_time":0.076154,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:9:2]","description":"run bash newrelic install command without infra","full_description":"newrelic-install::default when targets only contains php run bash newrelic install command without infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":131,"run_time":0.064612,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:9:3]","description":"run bash newrelic install command with php","full_description":"newrelic-install::default when targets only contains php run bash newrelic install command with php","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":135,"run_time":0.07524,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:10:1]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets only contains infra, logs and dotnet run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":146,"run_time":0.074454,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:10:2]","description":"run bash newrelic install command with logs","full_description":"newrelic-install::default when targets only contains infra, logs and dotnet run bash newrelic install command with logs","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":150,"run_time":0.068194,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:10:3]","description":"run bash newrelic install command with dotnet","full_description":"newrelic-install::default when targets only contains infra, logs and dotnet run bash newrelic install command with dotnet","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":154,"run_time":0.131634,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:11:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when targets only contains dotnet should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":165,"run_time":0.070335,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:11:2]","description":"run bash newrelic install command without infra","full_description":"newrelic-install::default when targets only contains dotnet run bash newrelic install command without infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":169,"run_time":0.078002,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:11:3]","description":"run bash newrelic install command with dotnet","full_description":"newrelic-install::default when targets only contains dotnet run bash newrelic install command with dotnet","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":173,"run_time":0.085788,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:12:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when execute on windows should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":185,"run_time":0.042838,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:12:2]","description":"run powershell newrelic install command","full_description":"newrelic-install::default when execute on windows run powershell newrelic install command","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":189,"run_time":0.046636,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:13:1]","description":"run powershell newrelic install command","full_description":"newrelic-install::default when execute on windows and targets only contains infra, logs and dotnet run powershell newrelic install command","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":201,"run_time":0.048759,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:13:2]","description":"run powershell newrelic install command with logs","full_description":"newrelic-install::default when execute on windows and targets only contains infra, logs and dotnet run powershell newrelic install command with logs","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":205,"run_time":0.046504,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:13:3]","description":"run powershell newrelic install command with dotnet","full_description":"newrelic-install::default when execute on windows and targets only contains infra, logs and dotnet run powershell newrelic install command with dotnet","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":209,"run_time":0.04245,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:14:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when execute on windows and targets only contains dotnet should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":221,"run_time":0.051955,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:14:2]","description":"run powershell newrelic install command without infra","full_description":"newrelic-install::default when execute on windows and targets only contains dotnet run powershell newrelic install command without infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":225,"run_time":0.044904,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:14:3]","description":"run powershell newrelic install command with dotnet","full_description":"newrelic-install::default when execute on windows and targets only contains dotnet run powershell newrelic install command with dotnet","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":229,"run_time":0.041348,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:15:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when targets only contains super agent should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":240,"run_time":0.067727,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:15:2]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets only contains super agent run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":244,"run_time":0.076812,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:15:3]","description":"run powershell newrelic install command without infra","full_description":"newrelic-install::default when targets only contains super agent run powershell newrelic install command without infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":248,"run_time":0.066267,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:16:1]","description":"should execute with target infra and skip core","full_description":"newrelic-install::default when targets contains super agent infra agent and logs should execute with target infra and skip core","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":259,"run_time":0.076783,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:16:2]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets contains super agent infra agent and logs run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":263,"run_time":0.066688,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:16:3]","description":"run bash newrelic install command with infra","full_description":"newrelic-install::default when targets contains super agent infra agent and logs run bash newrelic install command with infra","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":267,"run_time":0.076972,"pending_message":null},{"id":"./spec/unit/resources/newrelic_install_spec.rb[1:16:4]","description":"run bash newrelic install command with logs","full_description":"newrelic-install::default when targets contains super agent infra agent and logs run bash newrelic install command with logs","status":"passed","file_path":"./spec/unit/resources/newrelic_install_spec.rb","line_number":271,"run_time":0.066992,"pending_message":null}],"summary":{"duration":2.553038,"example_count":35,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"35 examples, 0 failures"}

0 comments on commit 0fb8193

Please sign in to comment.