-
Notifications
You must be signed in to change notification settings - Fork 898
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
Conversation
@miq-bot add_label enhancement ############################################# @miq-bot assign @gmcculloug |
a3a6c97
to
21685a9
Compare
@tinaafitz something something something something |
f6cf769
to
4bd4315
Compare
@miq-bot add_label services |
185380b
to
cc388b8
Compare
cc388b8
to
107066c
Compare
107066c
to
f4118ff
Compare
There was a problem hiding this 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.
c879c76
to
8ccaa1f
Compare
249fa06
to
e911811
Compare
@bdunne @gmcculloug @tinaafitz sorry to bug you all but this's ready for final review |
e911811
to
251ecfd
Compare
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| |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
251ecfd
to
35e2a4a
Compare
@@ -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? |
There was a problem hiding this comment.
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?
35e2a4a
to
955f49b
Compare
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
validates :name, :presence => true |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -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) } |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #18490
Leftover from ManageIQ#18464
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