diff --git a/app/models/service_retire_task.rb b/app/models/service_retire_task.rb index c9da2b47187..6704d376061 100644 --- a/app/models/service_retire_task.rb +++ b/app/models/service_retire_task.rb @@ -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 diff --git a/spec/models/service_retire_task_spec.rb b/spec/models/service_retire_task_spec.rb index 30a98f2c4b7..0f9cf74d6ad 100644 --- a/spec/models/service_retire_task_spec.rb +++ b/spec/models/service_retire_task_spec.rb @@ -153,6 +153,20 @@ expect(VmRetireTask.count).to eq(0) 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