Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for nil group to system_context_requester #19309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("System context defaulting to admin user because owner of #{name} (#{self.class}) was found but lacks a group.")
return User.super_admin
end
$log.info("Setting retirement requester of #{name} to #{evm_owner_id}.")
evm_owner
end
Expand Down
19 changes: 19 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,25 @@
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