Skip to content

Commit

Permalink
Don't create retire subtask for ServiceTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Nov 9, 2018
1 parent a6d4569 commit abf744a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def after_request_task_create

def create_retire_subtasks(parent_service, parent_task)
parent_service.service_resources.collect do |svc_rsc|
next unless svc_rsc.resource.try(:retireable?)
next unless svc_rsc.resource.present? && svc_rsc.resource.try(:retireable?)
next if svc_rsc.resource_type == "ServiceTemplate" &&
!self.class.include_service_template?(self,
svc_rsc.resource.id,
parent_service)
# TODO: the next line deals with the filtering for provisioning
# (https://github.com/ManageIQ/manageiq/blob/3921e87915b5a69937b9d4a70bb24ab71b97c165/app/models/service_template/filter.rb#L5)
# which should be extended to retirement as part of later work
Expand Down
19 changes: 19 additions & 0 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,32 @@
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm.id)
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm1.id)
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "Service", :service_id => service_c1.id, :resource_id => service_c1.id)
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id)

@service_retire_task.after_request_task_create
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

it "doesn't creates subtask for ServiceTemplates" do
@service_retire_task = FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] })
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id)

@service_retire_task.after_request_task_create
expect(ServiceRetireTask.count).to eq(1)
expect(ServiceRetireRequest.count).to eq(1)
end

it "doesn't creates subtask for service resources whose resources are nil" do
@service_retire_task = FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] })
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource => nil)

@service_retire_task.after_request_task_create
expect(ServiceRetireTask.count).to eq(1)
expect(ServiceRetireRequest.count).to eq(1)
end
end
end

Expand Down

0 comments on commit abf744a

Please sign in to comment.