Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add call for bundled service children retirement #17317

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u
Can we validate that this code gets executed. According to @tinaafitz a child service would get marked as an blank resource type.

Copy link
Contributor Author

@d-m-u d-m-u May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top level service itself has a blank type and we're not creating task for it to retire in this method so we need this check. The child services do have types, they're type Vm or Service or Whatever.

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