Skip to content

Commit

Permalink
Changes to catch the retirement requester in automate.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Feb 21, 2018
1 parent 5e05b8d commit 63266f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def retire(ids, options = {})
object = find_by(:id => id)
object.retire(options) if object.respond_to?(:retire)
end
MiqQueue.put(:class_name => 'RetirementManager', :method_name => 'check')
q_options = {:class_name => 'RetirementManager', :method_name => 'check'}
user = User.current_user
q_options.merge!(:user_id => user.id, :group_id => user.current_group.id, :tenant_id => user.current_tenant.id) if user
MiqQueue.put(q_options)
end
end

Expand Down Expand Up @@ -178,6 +181,7 @@ def retired_event_name
end

def raise_retirement_event(event_name, requester = nil)
requester ||= User.current_user.try(:userid)
q_options = retire_queue_options
$log.info("Raising Retirement Event for [#{name}] with queue options: #{q_options.inspect}")
MiqEvent.raise_evm_event(self, event_name, setup_event_hash(requester), q_options)
Expand Down
14 changes: 13 additions & 1 deletion spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
expect(vm.retirement_due?).to be_truthy
end

it "#raise_retirement_event" do
it "#raise_retirement_event without current user" do
event_name = 'foo'
event_hash = {:vm => @vm, :host => @vm.host, :type => "ManageIQ::Providers::Vmware::InfraManager::Vm",
:retirement_initiator => "system"}
Expand All @@ -143,6 +143,18 @@
@vm.raise_retirement_event(event_name)
end

it "#raise_retirement_event with current user" do
User.current_user = FactoryGirl.create(:user_with_group, :userid => 'freddy')
event_name = 'foo'
event_hash = {:vm => @vm, :host => @vm.host, :type => "ManageIQ::Providers::Vmware::InfraManager::Vm",
:retirement_initiator => "user", :userid => 'freddy'}
options = {:zone => @vm.my_zone}

expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash, options).once

@vm.raise_retirement_event(event_name)
end

it "#raise_audit_event" do
event_name = 'foo'
message = 'bar'
Expand Down

0 comments on commit 63266f0

Please sign in to comment.