Skip to content

Commit

Permalink
Add check for nil group to system_context_requester
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Sep 18, 2019
1 parent 73856f7 commit c05d12c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def system_context_requester
$log.info("System context defaulting to admin user because owner of #{name} (#{self.class}) not set or owner no longer found in database.")
return User.super_admin
end
if evm_owner.current_group.nil?
$log.info("#{name} has evm_owner but the user has no group.")
return User.super_admin
end
$log.info("Setting retirement requester of #{name} to #{evm_owner_id}.")
evm_owner
end
Expand Down
20 changes: 20 additions & 0 deletions spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@
end
end


context "with user lacking group" do
let(:user1) { FactoryBot.create(:user) }
let(:vm_with_owner_no_group) { FactoryBot.create(:vm, :evm_owner => user1, :host => FactoryBot.create(:host)) }

it "uses user as requester" do
vm_with_owner_no_group.update(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil)

expect(vm_with_owner.retirement_last_warn).to be_nil
allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'success', MiqAeEngine::MiqAeWorkspaceRuntime.new])
vm_with_owner_no_group.retirement_check
status, message, result = MiqQueue.first.deliver
MiqQueue.first.delivered(status, message, result)

expect(vm_with_owner_no_group.retirement_last_warn).not_to be_nil
# the next test is only nil because we're not creating a true super admin in these specs
expect(vm_with_owner_no_group.retirement_requester).to eq(nil)
end
end

context "without user" do
before do
user.destroy
Expand Down

0 comments on commit c05d12c

Please sign in to comment.