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

Adding tenant stuff to service template copy #18990

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
19 changes: 12 additions & 7 deletions app/models/service_template/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)
template.update_attributes(:name => new_name, :display => false)
service_resources.each { |service_resource| resource_copy(service_resource, template) }
resource_action_copy(template)
additional_tenant_copy(template)
picture_copy(template) if picture

direct_custom_buttons.each { |custom_button| custom_button_copy(custom_button, template) }
Expand All @@ -20,9 +21,8 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)

private

def resource_copy(service_resource, template)
resource = service_resource.resource.respond_to?(:service_template_resource_copy) ? service_resource.resource.service_template_resource_copy : service_resource.resource
template.add_resource(resource, service_resource)
def additional_tenant_copy(template)
template.additional_tenants << additional_tenants.dup
end

def custom_button_copy(custom_button, template)
Expand All @@ -33,11 +33,16 @@ def custom_button_set_copy(custom_button_set, template)
custom_button_set.deep_copy(:owner => template)
end

def resource_action_copy(template)
template.resource_actions << resource_actions.collect(&:dup)
end

def picture_copy(template)
template.picture = picture.dup
end

def resource_copy(service_resource, template)
resource = service_resource.resource.respond_to?(:service_template_resource_copy) ? service_resource.resource.service_template_resource_copy : service_resource.resource
template.add_resource(resource, service_resource)
end

def resource_action_copy(template)
template.resource_actions << resource_actions.collect(&:dup)
end
end
24 changes: 18 additions & 6 deletions spec/models/service_template/copy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand Down Expand Up @@ -143,7 +143,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(service_template_ansible_tower.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(service_template_ansible_tower.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -159,7 +159,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(service_template_orchestration.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(service_template_orchestration.service_resources.first.resource).not_to be(nil)
end
end
Expand Down Expand Up @@ -198,7 +198,7 @@
expect(ExtManagementSystem.count).to eq(1)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -212,7 +212,7 @@
expect(OrchestrationTemplate.count).to eq(1)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -228,7 +228,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end
end
Expand Down Expand Up @@ -261,5 +261,17 @@
expect(new_template.resource_actions.pluck(:action)).to match_array(%w[Provision Retire])
end
end

context "additional tenants" do
it "duplicates additional tenants" do
@st1.additional_tenants << [
FactoryBot.create(:tenant),
FactoryBot.create(:tenant, :subdomain => nil)
]
expect(@st1.additional_tenants.count).to eq(2)
new_template = @st1.template_copy
expect(new_template.additional_tenants.count).to eq(2)
end
end
end
end