Skip to content

Commit

Permalink
Create multiple requests for multiple service retirement
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jul 11, 2019
1 parent 04ea90f commit c9b73d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/models/miq_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ class MiqRetireTask < MiqRequestTask

def self.get_description(req_obj)
name = if req_obj.source.nil?
if req_obj.options[:src_ids].length == 1
m = model_being_retired.find_by(:id => req_obj.options[:src_ids].first)
m.nil? ? "" : m.name
else
"Multiple " + model_being_retired.to_s.pluralize
end
m = model_being_retired.find_by(:id => req_obj.options[:src_ids].first)
m.nil? ? "" : m.name
else
req_obj.source.name
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/mixins/process_tasks_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module ClassMethods
def process_tasks(options)
raise _("No ids given to process_tasks") if options[:ids].blank?
if options[:task] == 'retire_now'
name.constantize.make_retire_request(*options[:ids], User.current_user)
options[:ids].each do |id|
$log.info("Creating retire request for id #{id} with #{User.current_user}")
name.constantize.make_retire_request(id, User.current_user)
end
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}"
Expand Down
11 changes: 11 additions & 0 deletions spec/models/mixins/process_tasks_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def test_method
end
end

context "with multiple ids" do
let(:service1) { FactoryBot.create(:service) }
let(:service2) { FactoryBot.create(:service) }
let(:service3) { FactoryBot.create(:service) }
it "creates multiple requests" do
User.current_user = FactoryBot.create(:user)
Service.process_tasks(:task => "retire_now", :ids => [service1.id, service2.id, service3.id], :userid => User.current_user.userid)
expect(MiqRequest.count).to eq(3)
end
end

it "queues a message for the specified task" do
EvmSpecHelper.create_guid_miq_server_zone
test_class.process_tasks(:task => "test_method", :ids => [5], :userid => "admin")
Expand Down

0 comments on commit c9b73d7

Please sign in to comment.