-
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
Modified destroying an Ansible Service Template #14586
Conversation
@miq-bot add_label services, enhancement @miq-bot assign @gmcculloug -cc @bzwei |
@@ -156,11 +156,17 @@ def update_catalog_item(options, auth_user = nil) | |||
|
|||
def destroy | |||
auth_user = User.current_userid || 'system' | |||
raise 'Attached retirement configurations do not allow the service template to be deleted.' if retirement_defined? |
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.
better use before_destroy
statement than raise an error here.
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.
@bzwei - In the case where I would need to return an error - do we append the message to an errors
hash? - Not sure the pattern we use in our app for that callback.
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.
You can look at OrchestrationTemplate
as an example.
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.
Suggest changing the text to something like:
raise 'Destroy aborted. Active Services require retirement resources associated with this instance.' if ...
resource_actions.where.not(:configuration_template_id => nil).each do |resource_action| | ||
job_template = resource_action.configuration_template | ||
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript | ||
.delete_in_provider_queue(job_template.manager.id, { :manager_ref => job_template.manager_ref }, auth_user) | ||
end | ||
super | ||
end | ||
|
||
def retirement_defined? | ||
retirement_template = resource_actions.where("action = 'Retirement' AND configuration_template_id IS NOT NULL").present? |
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.
resource_actions.where(:action => 'Retirement').where.not(:configuration_template => nil).exists?
variable retirement_template
is then misleading; suggest something like retirement_jt_exist
resource_actions.where.not(:configuration_template_id => nil).each do |resource_action| | ||
job_template = resource_action.configuration_template | ||
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript | ||
.delete_in_provider_queue(job_template.manager.id, { :manager_ref => job_template.manager_ref }, auth_user) | ||
end | ||
super | ||
end | ||
|
||
def retirement_defined? |
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.
Need comments on the purpose of this method.
This public method may be called by UI. Consider a better 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.
@bzwei - I was debating on making it private
- but thought it may have public use. Should it just be made private?
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.
Need a public method and a private one. The private one is used by before_destroy
which may throw an error.
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.
@bzwei - looks like I missed this request - I'll get this change in.
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.
The new method names do not seem accurate to me. retirement_defined?
does not indicate that we are looking for active services and undefined_retirement?
makes me thing the retirement methods are un-defining the retirement methods or something.
Maybe:
retirement_resources_in_use?
check_retirement_on_destroy
1391180
to
ae8b200
Compare
|
||
private | ||
|
||
def check_for_retirement_potential |
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.
Two minor suggestions:
- The word "for" is not needed.
check_retirement_potential
. - Rename the other method `retirement_potential?' instead of swapping the order.
# 2. At least one service instance where :retired is set to false. | ||
# | ||
def potential_retirement? | ||
retirement_jt_exists = resource_actions.where("action = 'Retirement' AND configuration_template_id IS NOT NULL").present? |
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.
@syncrou you missed the previous comment. The better way can be resource_actions.where(:action => 'Retirement').where.not(:configuration_template => nil).exists?
We no longer will destroy a service template if there is a retirement configuration that has not been retired https://www.pivotaltracker.com/story/show/142646939
ae8b200
to
492c00b
Compare
Checked commit syncrou@492c00b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@gmcculloug should this PR have fine/yes? |
Modified destroying an Ansible Service Template (cherry picked from commit 4ea0b83)
Fine backport details:
|
We no longer will destroy a service template if there is a retirement configuration
that has not been retired
https://www.pivotaltracker.com/story/show/142646939