Skip to content

Commit

Permalink
Merge pull request #19820 from lfu/ivanchuk_tinaafitz-fix_retirement_…
Browse files Browse the repository at this point in the history
…message

[IVANCHUK] Fix VM Retirement Error Message
  • Loading branch information
simaishi committed Feb 21, 2020
2 parents e90d4f9 + c49dd34 commit d464b2b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d464b2b

Please sign in to comment.