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

Link service resources of bundled service correctly #18251

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
4 changes: 3 additions & 1 deletion app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def create_service(service_task, parent_svc = nil)

nh['initiator'] = service_task.options[:initiator] if service_task.options[:initiator]

Service.create(nh) do |svc|
service = Service.create(nh) do |svc|
svc.service_template = self
set_ownership(svc, service_task.get_user)

Expand All @@ -208,7 +208,9 @@ def create_service(service_task, parent_svc = nil)
%w(id created_at updated_at service_template_id).each { |key| nh.delete(key) }
svc.add_resource(sr.resource, nh) unless sr.resource.nil?
end
end

service.tap do |svc|
if parent_svc
service_resource = ServiceResource.find_by(:id => service_task.options[:service_resource_id])
parent_svc.add_resource!(svc, service_resource)
Expand Down
42 changes: 32 additions & 10 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,41 @@
expect(sub_svc).to include(@svc_d)
end

it "should add_resource! only if a parent_svc exists" do
sub_svc = instance_double("service_task", :options => {:dialog => {}}, :get_user => service_user)
parent_svc = instance_double("service_task", :options => {:dialog => {}})
expect(parent_svc).to receive(:add_resource!).once
describe "#create_service" do
let(:service_task) do
FactoryGirl.create(:service_template_provision_task,
:miq_request => service_template_request,
:options => {:service_resource_id => service_resource.id})
end
let(:service_template_request) { FactoryGirl.create(:service_template_provision_request, :requester => user) }
let(:service_resource) do
FactoryGirl.create(:service_resource,
:resource_type => 'MiqRequest',
:resource_id => service_template_request.id)
end
let(:user) { FactoryGirl.create(:user) }
let(:parent_service) { FactoryGirl.create(:service) }

@svc_a.create_service(sub_svc, parent_svc)
end
it "create service sets parent service resource resource id" do
@svc_a.create_service(service_task, parent_service)
parent_service.reload
expect(parent_service.service_resources.first.resource).to eq(parent_service.children.first)
end

it "should not call add_resource! if no parent_svc exists" do
sub_svc = instance_double("service_task", :options => {:dialog => {}}, :get_user => service_user)
expect(sub_svc).to receive(:add_resource!).never
it "should add_resource! only if a parent_svc exists" do
sub_svc = instance_double("service_task", :options => {:dialog => {}}, :get_user => service_user)
parent_svc = instance_double("service_task", :options => {:dialog => {}}, :service_resources => instance_double('service_resource'))
expect(parent_svc).to receive(:add_resource!).once

@svc_a.create_service(sub_svc)
@svc_a.create_service(sub_svc, parent_svc)
end

it "should not call add_resource! if no parent_svc exists" do
sub_svc = instance_double("service_task", :options => {:dialog => {}}, :get_user => service_user)
expect(sub_svc).to receive(:add_resource!).never

@svc_a.create_service(sub_svc)
end
end

it "should pass display attribute to created top level service" do
Expand Down