Skip to content

Commit

Permalink
Add call for bundled service children retirement
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Apr 19, 2018
1 parent 51f97d4 commit 047a5b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def after_request_task_create
end

def create_retire_subtasks(parent_service)
parent_service.direct_service_children.each { |child| create_retire_subtasks(child) }
parent_service.service_resources.collect do |svc_rsc|
next unless svc_rsc.resource.present? && svc_rsc.resource.respond_to?(:retire_now)
next if svc_rsc.resource.type.blank?
next if svc_rsc.resource_type == "ServiceTemplate" &&
!self.class.include_service_template?(self,
svc_rsc.resource.id,
Expand Down
31 changes: 31 additions & 0 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@
expect(VmRetireTask.count).to eq(1)
end
end

context "bundled service retires all children" do
let(:zone) { FactoryGirl.create(:small_environment) }
let(:vm1) { FactoryGirl.create(:vm_vmware) }
let(:service_c1) { FactoryGirl.create(:service, :service => service) }
let(:service_c2) { FactoryGirl.create(:service, :service => service_c1) }

before do
allow(MiqServer).to receive(:my_server).and_return(zone.miq_servers.first)
service_c1 << vm
service_c2 << vm1
service.save
service_c1.save
service_c2.save
end

it "creates subtask" do
@miq_request = FactoryGirl.create(:service_retire_request, :requester => user)
@miq_request.approve(approver, reason)
@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 => "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_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(ServiceRetireTask.count).to eq(1)
expect(ServiceRetireRequest.count).to eq(1)
end
end
end

describe "deliver_to_automate" do
Expand Down

0 comments on commit 047a5b5

Please sign in to comment.