-
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
Create or delete a catalog item on update #14830
Create or delete a catalog item on update #14830
Conversation
When updating an existing AnsiblePlaybook catalog item - add the ability to add a new retirement playbook if one didn't previously exist before Testing notes: Create new Ansible Playbook Catalog item without a retirement playbook Edit the above Catalog Item and add a retirement playbook. https://www.pivotaltracker.com/story/show/141868401 https://bugzilla.redhat.com/show_bug.cgi?id=1438839
When updating an existing AnsiblePlaybook catalog item - add the ability to add a new retirement playbook if one didn't previously exist before Also, allow deleting of an existing job_template if the update does not pass in a playbok id https://www.pivotaltracker.com/story/show/141868401 https://www.pivotaltracker.com/story/show/141265431 https://bugzilla.redhat.com/show_bug.cgi?id=1438839
@miq-bot add_label bug, providers/ansible_tower, services cc - @gmcculloug |
2c79ac1
to
693af1a
Compare
end | ||
end | ||
end | ||
|
||
def update_catalog_item(options, auth_user = nil) | ||
config_info = validate_update_config_info(options) | ||
name = options[: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.
name = options[:name] || name
same for description
|
||
new_dialog = create_new_dialog(info[:new_dialog_name], job_template(action), info[:hosts]) if info[:new_dialog_name] | ||
config_info[action][:dialog_id] = new_dialog.id if new_dialog | ||
new_dialogs(config_info) |
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.
- Method names: I prefer to use verbs for method names, except nouns for getters.
- Adjust the order:
update_job_templates
,create_job_templates
,create_dialogs
- Let's reuse the class method
create_job_templates
, likeself.class.create_job_templates(name, description, config_info, auth_user, self)
def create_job_template(service_name, description, config_info, auth_user) | ||
[:provision, :retirement, :reconfigure].each_with_object({}) do |action, hash| | ||
next unless new_job_template_required(config_info[action], action) | ||
hash[action] = { :configuration_template => self.class.send(:create_job_template, "miq_#{service_name}_#{action}", description, config_info[action], auth_user), |
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.
extract "miq_#{service_name}_#{action}"
into a method
info && job_template(action).nil? && info.key?(:playbook_id) | ||
end | ||
|
||
def create_job_template(service_name, description, config_info, auth_user) |
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.
no need
@@ -71,12 +71,17 @@ def create_new_dialog(dialog_name, job_template, hosts) | |||
|
|||
def self.create_job_templates(service_name, description, config_info, auth_user) | |||
[:provision, :retirement, :reconfigure].each_with_object({}) do |action, hash| | |||
next unless config_info[action] && config_info[action].key?(:playbook_id) | |||
next unless new_job_template_required(config_info[action]) |
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.
next unless new_job_template_required?(config_info[action], action, service_template)
def job_template_modifications(name, description, config_info, auth_user) | ||
[:provision, :retirement, :reconfigure].each do |action| | ||
info = config_info[action] | ||
if info && info.key?(:playbook_id) && !info.key?(:create_only) |
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.
if job_template(action)
no need to add :create_only
, but this method needs to be called before creating new job templates.
hash[action] = { :configuration_template => create_job_template("miq_#{service_name}_#{action}", description, config_info[action], auth_user) } | ||
end | ||
end | ||
private_class_method :create_job_templates | ||
|
||
def self.new_job_template_required(info) |
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.
def self.new_job_template_required?(info, action, service_template)
info && info.key?(:playbook_id) && service_template.job_template(action).nil?
end
@@ -71,12 +71,17 @@ def create_new_dialog(dialog_name, job_template, hosts) | |||
|
|||
def self.create_job_templates(service_name, description, config_info, auth_user) |
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.
def self.create_job_templates(service_name, description, config_info, auth_user, service_template = nil)
@@ -190,4 +217,20 @@ def delete_job_templates(job_templates) | |||
.delete_in_provider_queue(job_template.manager.id, { :manager_ref => job_template.manager_ref }, auth_user) | |||
end | |||
end | |||
|
|||
def new_dialog_required(info) |
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.
add ? to the method name
info && info.key?(:new_dialog_name) | ||
end | ||
|
||
def new_job_template_required(info, action) |
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.
no need.
@bzwei - I believe I have addressed your feedback. cc - @gmcculloug |
name = options[:name] | ||
description = options[:description] | ||
def job_template(action) | ||
resource = resource_actions.find_by(:action => action.to_s.capitalize) |
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 we do
resource_actions.find_by(:action => action.to_s.capitalize).try(:configuration_template)
?
def update_job_templates(name, description, config_info, auth_user) | ||
[:provision, :retirement, :reconfigure].each do |action| | ||
info = config_info[action] | ||
next unless info |
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.
Since job_template
may not exist, we should never call job_template!
. We do not need to update a job template if it does not exist. Therefore the logic should be like this
next unless info # no intention to change anything for this action
job_template = job_template(action)
next unless job_template # job_template does not exist
if info.key?(:playbook_id) # job_template exists, and playbook is given, try an update
# update
else # job_template exists but no more playbook, try a delete
# delete
end
@@ -134,26 +144,55 @@ def validate_update_config_info(options) | |||
self.class.send(:validate_config_info, opts) | |||
end | |||
|
|||
def job_template(action) | |||
def job_template!(action) |
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 you double check existing code where job_template
was called? Do they need to change to job_template!
?
end | ||
end | ||
private_class_method :create_job_templates | ||
|
||
def self.new_job_template_required(info, action, service_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.
self.new_job_template_required?
Can you move this method down next to instance method new_dialog_required?
f1ccb7b
to
bb63d49
Compare
end | ||
end | ||
private_class_method :create_job_templates | ||
|
||
def self.new_job_template_required(info, action, service_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.
this method is no longer needed.
|
||
new_dialog = create_new_dialog(info[:new_dialog_name], job_template(action), info[:hosts]) if info[:new_dialog_name] | ||
config_info[action][:dialog_id] = new_dialog.id if new_dialog | ||
def new_job_templates(config_info, name, description, auth_user) |
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.
new_job_templates
is no longer needed
Allow the around destroy callback to also prepend to the front of the callback chain
bb63d49
to
f44a845
Compare
Change all methods not specifically needed by the UI into private methods Alphabetize all methods under private
58bdd07
to
f7e80bf
Compare
Checked commits syncrou/manageiq@4bcb4bd~...f7e80bf with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@miq-bot add_label blocker |
…catalog_item_on_update Create or delete a catalog item on update (cherry picked from commit 258dd18) https://bugzilla.redhat.com/show_bug.cgi?id=1445894 https://bugzilla.redhat.com/show_bug.cgi?id=1445942
Fine backport details:
|
When updating an existing AnsiblePlaybook catalog item - add the ability to add a new retirement playbook if one didn't previously exist before: Case A
Also, allow deleting of an existing job_template if the update does not pass in a
:playbook_id
:Case B
Further more: If you create a new catalog item, delete it, and then create a new one with the same name as the old one you will no longer receive an error: Case C
Testing notes:
Case A
Case B
Case C
https://www.pivotaltracker.com/story/show/141868401
https://www.pivotaltracker.com/story/show/141265431
https://bugzilla.redhat.com/show_bug.cgi?id=1438839
https://bugzilla.redhat.com/show_bug.cgi?id=1442006