Skip to content

Commit

Permalink
Merge pull request #18908 from d-m-u/creating_tasks_for_multiple_serv…
Browse files Browse the repository at this point in the history
…ice_retirement

Create retire subtasks for multiple services

(cherry picked from commit 95e77c6)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1723833
  • Loading branch information
bdunne authored and simaishi committed Jul 2, 2019
1 parent 88e11eb commit 2da6c67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def task_active

def after_request_task_create
update_attributes(:description => get_description)
parent_svc = Service.find_by(:id => options[:src_ids])
if create_subtasks?(parent_svc)
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>")
create_retire_subtasks(parent_svc, self)
Service.where(:id => options[:src_ids]).each do |parent_svc|
if create_subtasks?(parent_svc)
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>")
create_retire_subtasks(parent_svc, self)
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
expect(VmRetireTask.count).to eq(1)
expect(ServiceRetireTask.count).to eq(1)
end

context "multiple service retirement" do
it "creates multiple retire subtasks" do
s1 = FactoryBot.create(:service)
s2 = FactoryBot.create(:service)
s1.add_resource!(FactoryBot.create(:vm_openstack))
s2.add_resource!(FactoryBot.create(:vm_openstack))

service_retire_task1 = FactoryBot.create(:service_retire_task, :source => s1, :miq_request => miq_request, :options => {:src_ids => [s1.id, s2.id] })
service_retire_task1.after_request_task_create

expect(VmRetireTask.count).to eq(2)
end
end
end

context "bundled service retires all children" do
Expand Down

0 comments on commit 2da6c67

Please sign in to comment.