-
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
Destroy Ansible Playbook job templates #14461
Destroy Ansible Playbook job templates #14461
Conversation
@miq-bot add_label enhancement, services, providers/ansible_tower |
|
||
# Get the record in our database | ||
# TODO: This needs to be targeted refresh so it doesn't take too long | ||
EmsRefresh.queue_refresh(manager, nil, 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.
Does this need to by synchronous? Can we just queue the refresh and not wait around for it?
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.
yes, delete can be asynchronous. Even the update_in_provider refresh can be async.
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'll get the change in. Interestingly enough - since it isn't waiting for a task id the UI treats it like an asynchronous call - but I didn't realize the true
argument was still hanging around.
ecdd380
to
d2bc767
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.
I'm not a fan of the line continuations, but the content looks good to me, so I won't hold up the PR for it. 👍
end | ||
end | ||
|
||
def prebuild_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 could be:
def prebuild_service_template
ret = {:provision => {:configuration_template => job_template}}
expect(described_class).to receive(:create_job_templates).and_return(ret).at_least(:once)
described_class.create_catalog_item(catalog_item_options_two, user).tap do |service_template|
expect(service_template).to receive(:job_template).and_return(job_template).at_least(:once)
end
end
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.
FTFY ;) return is a keyword
d2bc767
to
35c9c0a
Compare
manager = ExtManagementSystem.find(manager_id) | ||
|
||
name_map = { |
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.
Minor, but this should probably be a frozen constant.
35c9c0a
to
88fa1ba
Compare
'create' => 'Creating', | ||
'update' => 'Updating', | ||
'delete' => 'Deleting' | ||
}.freeze |
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.
Make it a private constant.
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 was changed as requested.
end | ||
|
||
private | ||
|
||
def create_or_update_in_provider_queue(action, manager_id, params, auth_user) | ||
def create_update_or_delete_in_provider_queue(action, manager_id, params, 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.
maybe name it act_in_provider_queue
or operate_in_provider_queue
?
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript | ||
.delete_in_provider_queue(playbook.manager.id, { :manager_ref => manager_ref }, auth_user) | ||
end | ||
super() |
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.
super
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.
Depending on what happens to destroy
- I wasn't able to simply call super
if the current method accepted arguments, had to pass nothing via ()
- Unless you're aware of a better way to handle it.
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 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.
Just calling super
will forward the auth_user
arg.
Calling super()
will forward no args.
ActiveRecord::Base#destroy
doesn't expect any args.
@@ -151,4 +151,17 @@ def update_catalog_item(options, auth_user = nil) | |||
end | |||
super | |||
end | |||
|
|||
def destroy(auth_user = 'system') |
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.
destroy
and destroy!
are AR methods. Should we override it/them this way? Can we add an argument?. Let's do some research on a Rails way to clean resources at destroying.
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 we can set an accessor for auth_user
- but that sounds like a custom pattern. Not sure how to allow for passing in any user - unless we store the user used to create the catalog_item in the options
hash? - Definitely open to ideas.
|
||
def destroy(auth_user = 'system') | ||
config_info = options[:config_info] | ||
[:provision, :retirement, :reconfigure].each do |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.
This is not the right way to clean job templates. We should iterate resource_actions and get the job template from resource_action.configuration_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.
@bzwei - Currently all CRUD instance methods are following this pattern. I would rather adjust the instance CRUD methods in one single way via resource_action.configuration_template
via a followup PR.
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.
For create and update, config_info
is a passed-in option. Here for delete there is no config_info
passed in. We don't need to follow a pattern. I would rather implement it correctly here because it is the PR all about.
56237ec
to
14f267f
Compare
@syncrou I am thinking we may want to create In the base class
But this requires UI and API to call this method rather than the destroy method. I don't know whether it is appropriate. |
@@ -151,4 +151,17 @@ def update_catalog_item(options, auth_user = nil) | |||
end | |||
super | |||
end | |||
|
|||
def destroy(auth_user = 'system') |
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 I would suggest that we determine the auth_user
property this way instead of expecting the user to tell us:
def destroy
auth_user = User.current_userid || 'system'
This keeps the method signature unchanged and gets the one thing we all want; using super
instead of super()
. 😉
14f267f
to
d9f850d
Compare
@bzwei a |
@jntullo @h-kataria We decided that we don't really need to introduce |
d9f850d
to
817b149
Compare
817b149
to
731e8dd
Compare
Checked commit syncrou@731e8dd with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Test failures are unrelated. |
If an associated
configuration_template
exists then delete the associatedJobTemplate
Otherwise simply delete the
ServiceTemplateAnsiblePlaybook
https://www.pivotaltracker.com/story/show/140761595