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

Modified destroying an Ansible Service Template #14586

Merged
merged 1 commit into from
Mar 31, 2017

Conversation

syncrou
Copy link
Contributor

@syncrou syncrou commented Mar 30, 2017

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

@syncrou
Copy link
Contributor Author

syncrou commented Mar 30, 2017

@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?
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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?
Copy link
Contributor

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?
Copy link
Contributor

@bzwei bzwei Mar 30, 2017

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.

Copy link
Contributor Author

@syncrou syncrou Mar 30, 2017

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@syncrou syncrou force-pushed the raise_error_on_delete branch 2 times, most recently from 1391180 to ae8b200 Compare March 31, 2017 15:38

private

def check_for_retirement_potential
Copy link
Member

Choose a reason for hiding this comment

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

Two minor suggestions:

  1. The word "for" is not needed. check_retirement_potential.
  2. 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?
Copy link
Contributor

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
@miq-bot
Copy link
Member

miq-bot commented Mar 31, 2017

Checked commit syncrou@492c00b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 👍

@gmcculloug gmcculloug merged commit 4ea0b83 into ManageIQ:master Mar 31, 2017
@gmcculloug gmcculloug added this to the Sprint 58 Ending Apr 10, 2017 milestone Mar 31, 2017
@bzwei
Copy link
Contributor

bzwei commented Mar 31, 2017

@gmcculloug should this PR have fine/yes?

@syncrou syncrou deleted the raise_error_on_delete branch March 31, 2017 17:51
simaishi pushed a commit that referenced this pull request Mar 31, 2017
Modified destroying an Ansible Service Template
(cherry picked from commit 4ea0b83)
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 5a491f06d3fe3eedc67a34e1c550cd81b30b6501
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Fri Mar 31 13:18:23 2017 -0400

    Merge pull request #14586 from syncrou/raise_error_on_delete
    
    Modified destroying an Ansible Service Template
    (cherry picked from commit 4ea0b83e10934f8cf8f0ca0ad86b03eebd1d9b7a)

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.

5 participants