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 method to copy service templates #18464

Merged
merged 1 commit into from
Feb 26, 2019

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Feb 18, 2019

Copying service templates is an RFE that I wound up with. We determined (see linked issue) that only some of the parts and pieces need to be copied, so only resources that are miq_provision_request_templates get new guids, everything else gets linked back to the existing resource.

The next part of this is determining what to do with custom buttons, ansible things, and custom button sets, as well as how this works for service bundles as GM pointed out in comments here.

Issue is here: #18450

Depends on

#18474

@d-m-u
Copy link
Contributor Author

d-m-u commented Feb 18, 2019

@miq-bot add_label enhancement

#############################################
🎆 🎋 FINALLY I GET TO WRITE THAT ONE 🎆 🎋
#############################################

@miq-bot assign @gmcculloug
@miq-bot add_reviewer @bdunne

@d-m-u
Copy link
Contributor Author

d-m-u commented Feb 18, 2019

@tinaafitz something something something something

@d-m-u d-m-u force-pushed the copying_service_templates branch 6 times, most recently from f6cf769 to 4bd4315 Compare February 18, 2019 20:05
@d-m-u
Copy link
Contributor Author

d-m-u commented Feb 18, 2019

@miq-bot add_label services

@d-m-u d-m-u force-pushed the copying_service_templates branch 3 times, most recently from 185380b to cc388b8 Compare February 18, 2019 20:49
@miq-bot miq-bot requested a review from bdunne February 19, 2019 01:23
@d-m-u d-m-u changed the title Add method to copy service templates [WIP] Add method to copy service templates Feb 19, 2019
@miq-bot miq-bot added the wip label Feb 19, 2019
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

Few comments. Still not totally clear on what the comment "doing the copy in two transactions" means. Maybe we can discuss when we are in the office tomorrow.

app/models/configuration_script_base.rb Outdated Show resolved Hide resolved
app/models/miq_provision_request_template.rb Show resolved Hide resolved
app/models/service_template/copy.rb Outdated Show resolved Hide resolved
@d-m-u d-m-u force-pushed the copying_service_templates branch 4 times, most recently from c879c76 to 8ccaa1f Compare February 21, 2019 13:08
@d-m-u d-m-u force-pushed the copying_service_templates branch 2 times, most recently from 249fa06 to e911811 Compare February 25, 2019 17:19
@d-m-u
Copy link
Contributor Author

d-m-u commented Feb 25, 2019

@bdunne @gmcculloug @tinaafitz sorry to bug you all but this's ready for final review

def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)
if template_valid? && type != 'ServiceTemplateAnsiblePlaybook'
ActiveRecord::Base.transaction do
dup.tap do |template|
Copy link
Member

Choose a reason for hiding this comment

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

I had a concern about some attributes being duped, but @d-m-u assures me, it's been thoroughly considered and shouldn't be a problem.

Copy link
Member

Choose a reason for hiding this comment

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

Same here, she was very reassuring. 😄 Plus I looked into the doc for dup which helped. 👍

Copy link
Member

Choose a reason for hiding this comment

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

Was thinking more about this and wondering if we should override the dup method and have it also the guid value to nil. This really seems like the pattern we want.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

@gmcculloug I agree, that sounds like it belongs in the UuidMixin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdunne but you can just override initialize_copy like this's doing now, can this please get merged as first step to fix bug and if necessary i redo it later?

Copy link
Member

Choose a reason for hiding this comment

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

@bdunne I like the idea of moving to the mixin for guid (in a separate PR), but does that limit using this pattern if additional fields need to be cleared on other models?

Copy link
Member

Choose a reason for hiding this comment

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

@bdunne I like the idea of moving to the mixin for guid (in a separate PR), but does that limit using this pattern if additional fields need to be cleared on other models?

I think it would just work. initialize_copy in the uuid mixin to set the guid and call super should only affect types that include UuidMixin. Either way, for another PR.

@@ -24,7 +24,13 @@ def self.create_catalog_item(options, _auth_user = nil)

def remove_invalid_resource
# remove the resource from both memory and table
service_resources.to_a.delete_if { |r| r.destroy unless r.reload.resource.present? }
service_resources.to_a.delete_if do |r|
if r.persisted?
Copy link
Contributor

Choose a reason for hiding this comment

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

can be simplified to

  r.reload if r.persisted?
  r.destroy if r.resource.blank?

@miq-bot
Copy link
Member

miq-bot commented Feb 26, 2019

Checked commit d-m-u@955f49b with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. ⭐

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

:shipit:


validates :name, :presence => true
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a migration to fix any existing records that don't have a name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an excellent question.

Copy link
Member

Choose a reason for hiding this comment

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

I've heard naming is hard. Good eyes @bdunne 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a limit though, only one data migration per team person per year, my quota is filled.

Copy link
Member

Choose a reason for hiding this comment

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

There's a limit though, only one data migration per team person per year, my quota is filled.

But now you know the pattern 😄

Copy link
Member

Choose a reason for hiding this comment

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

@d-m-u and miss out on all the fun in writing the spec for the data migration?

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

👍

@bdunne bdunne merged commit 67d4a6c into ManageIQ:master Feb 26, 2019
@bdunne bdunne added this to the Sprint 106 Ending Mar 4, 2019 milestone Feb 26, 2019
@bdunne bdunne assigned bdunne and unassigned gmcculloug Feb 26, 2019
@@ -435,6 +437,10 @@ def provision_workflow(user, dialog_options = nil, request_options = {})
end
end

def dup
super.tap { |obj| obj.update_attributes(:guid => nil) }
Copy link
Member

Choose a reason for hiding this comment

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

@d-m-u Sorry, I saw this after the fact... Shouldn't this be super.tap { |obj| obj.guid = nil } instead? dup doesn't normally write to the database, but this will because of the call to update_attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in #18490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants