From 2a744865bdba132c09706077f64b409d8acbdaf5 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Tue, 28 Aug 2018 10:26:19 -0400 Subject: [PATCH] Test removal of doubled service child retirement call --- app/models/service_retire_task.rb | 9 +++++---- spec/models/service_retire_task_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/service_retire_task.rb b/app/models/service_retire_task.rb index bc0ff6628b3a..e5711cb32599 100644 --- a/app/models/service_retire_task.rb +++ b/app/models/service_retire_task.rb @@ -29,7 +29,7 @@ def after_request_task_create create_retire_subtasks(parent_svc, self) end - def create_retire_subtasks(parent_service, task) + def create_retire_subtasks(parent_service, parent_task) parent_service.service_resources.collect do |svc_rsc| next unless svc_rsc.resource.try(:retireable?) # TODO: the next line deals with the filtering for provisioning @@ -40,7 +40,7 @@ def create_retire_subtasks(parent_service, task) nh['options'] = options.except(:child_tasks) # Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks nh['options'][:dialog] = {} - new_task = create_task(svc_rsc, parent_service, nh) + new_task = create_task(svc_rsc, parent_service, nh, parent_task) create_retire_subtasks(svc_rsc.resource, new_task) if svc_rsc.resource.kind_of?(Service) new_task.after_request_task_create miq_request.miq_request_tasks << new_task @@ -49,15 +49,16 @@ def create_retire_subtasks(parent_service, task) end.compact! end - def create_task(svc_rsc, parent_service, nh) + def create_task(svc_rsc, parent_service, nh, parent_task) new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh) new_task.options.merge!( :src_id => svc_rsc.resource.id, :service_resource_id => svc_rsc.id, :parent_service_id => parent_service.id, - :parent_task_id => id, + :parent_task_id => task.id, ) new_task.source = svc_rsc.resource + parent_task.miq_request_tasks << new_task new_task.request_type = svc_rsc.resource.type.demodulize.downcase + "_retire" new_task.save! new_task diff --git a/spec/models/service_retire_task_spec.rb b/spec/models/service_retire_task_spec.rb index be98a73a28ef..9d980b06665c 100644 --- a/spec/models/service_retire_task_spec.rb +++ b/spec/models/service_retire_task_spec.rb @@ -89,8 +89,8 @@ service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "Service", :service_id => service_c1.id, :resource_id => service_c1.id) @service_retire_task.after_request_task_create - expect(VmRetireTask.count).to eq(4) - expect(VmRetireTask.all.pluck(:message)).to eq(["Automation Starting", "Automation Starting", "Automation Starting", "Automation Starting"]) + expect(VmRetireTask.count).to eq(2) + expect(VmRetireTask.all.pluck(:message)).to eq(["Automation Starting", "Automation Starting"]) expect(ServiceRetireTask.count).to eq(1) expect(ServiceRetireRequest.count).to eq(1) end