Skip to content

Commit

Permalink
Merge pull request #17255 from d-m-u/fixing_retire_request_call
Browse files Browse the repository at this point in the history
Fix call to process_tasks to run the right thing
  • Loading branch information
mkanoor authored Apr 17, 2018
2 parents 4cdb9e9 + e1288e8 commit 66ad170
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/models/mixins/process_tasks_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module ProcessTasksMixin
extend ActiveSupport::Concern
include RetirementMixin

module ClassMethods
# Processes tasks received from the UI and queues them
def process_tasks(options)
raise _("No ids given to process_tasks") if options[:ids].blank?
if options[:task] == "refresh_ems" && respond_to?("refresh_ems")
if options[:task] == 'retire_now'
name.constantize.make_retire_request(*options[:ids])
elsif options[:task] == "refresh_ems" && respond_to?("refresh_ems")
refresh_ems(options[:ids])
msg = "'#{options[:task]}' initiated for #{options[:ids].length} #{ui_lookup(:table => base_class.name).pluralize}"
task_audit_event(:success, options, :message => msg)
Expand Down
6 changes: 3 additions & 3 deletions app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module RetirementMixin
end

module ClassMethods
def make_retire_request
options = {:task => task, :userid => current_user, :ids => objs, :src_ids => objs}
(klass.to_s + "RetireRequest").constantize.make_request(@request_id, options, current_user)
def make_retire_request(*src_ids)
options = {:src_ids => src_ids.presence || id}
(name + "RetireRequest").constantize.make_request(nil, options, User.current_user, true)
end

def retire(ids, options = {})
Expand Down
13 changes: 13 additions & 0 deletions spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe "Service Retirement Management" do
let(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") }
before do
@server = EvmSpecHelper.local_miq_server
@service = FactoryGirl.create(:service)
Expand Down Expand Up @@ -63,6 +64,18 @@
expect(@service.retirement_warn).to eq(options[:warn])
end

it "with one src_id" do
User.current_user = user
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => ['yabadabadoo'] }, User.current_user, true)
@service.class.to_s.demodulize.constantize.make_retire_request('yabadabadoo')
end

it "with many src_ids" do
User.current_user = user
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => [1, 2, 3]}, User.current_user, true)
@service.class.to_s.demodulize.constantize.make_retire_request(1, 2, 3)
end

it "#retire date" do
expect(AuditEvent).to receive(:success).once
options = {}
Expand Down
17 changes: 17 additions & 0 deletions spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
describe "VM Retirement Management" do
let(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") }
let(:region) { FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) }

before do
miq_server = EvmSpecHelper.local_miq_server
@zone = miq_server.zone
Expand Down Expand Up @@ -62,6 +65,20 @@
expect(@vm.retirement_warn).to eq(options[:warn])
end

describe "retire request" do
it "with one src_id" do
User.current_user = user
expect(VmRetireRequest).to receive(:make_request).with(nil, {:src_ids => ['yabadabadoo'] }, User.current_user, true)
@vm.class.to_s.demodulize.constantize.make_retire_request('yabadabadoo')
end

it "with many src_ids" do
User.current_user = user
expect(VmRetireRequest).to receive(:make_request).with(nil, {:src_ids => [1, 2, 3]}, User.current_user, true)
@vm.class.to_s.demodulize.constantize.make_retire_request(1, 2, 3)
end
end

it "#retire date" do
expect(AuditEvent).to receive(:success).once
options = {}
Expand Down

0 comments on commit 66ad170

Please sign in to comment.