Skip to content

Commit

Permalink
Issue error log message only if there are invalid src_ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaafitz authored and lfu committed Feb 6, 2020
1 parent 3ed31dc commit c49dd34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/vm_or_template.rb
Expand Up @@ -361,7 +361,7 @@ def self.make_retire_request(*src_ids, requester, initiated_by: 'user')
vms = where(:id => src_ids)

missing_ids = src_ids - vms.pluck(:id)
_log.error("Retirement of [Vm] IDs: [#{missing_ids.join(', ')}] skipped - target(s) does not exist")
_log.error("Retirement of [Vm] IDs: [#{missing_ids.join(', ')}] skipped - target(s) does not exist") if missing_ids.present?

vms.each do |target|
target.check_policy_prevent('request_vm_retire', "retire_request_after_policy_check", requester.userid, :initiated_by => initiated_by)
Expand Down
12 changes: 12 additions & 0 deletions spec/models/vm/retirement_management_spec.rb
Expand Up @@ -156,6 +156,18 @@
Vm.make_retire_request(@vm.id, vm2.id, user)
end

it "with user as initiated_by" do
expect(Vm).not_to receive(:_log)
Vm.make_retire_request(@vm.id, user, :initiated_by => user)
end

it "with user as initiated_by, with unknown vm.id" do
log_stub = instance_double("_log")
expect(Vm).to receive(:_log).and_return(log_stub).at_least(:once)
expect(log_stub).to receive(:error).with("Retirement of [Vm] IDs: [123] skipped - target(s) does not exist")
Vm.make_retire_request(@vm.id, 123, user, :initiated_by => user)
end

it "policy prevents" do
expect(VmRetireRequest).not_to receive(:make_request)

Expand Down

0 comments on commit c49dd34

Please sign in to comment.