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

Destroy Ansible Playbook job templates #14461

Merged

Conversation

syncrou
Copy link
Contributor

@syncrou syncrou commented Mar 22, 2017

If an associated configuration_template exists then delete the associated JobTemplate

Otherwise simply delete the ServiceTemplateAnsiblePlaybook

https://www.pivotaltracker.com/story/show/140761595

@syncrou
Copy link
Contributor Author

syncrou commented Mar 22, 2017

@miq-bot add_label enhancement, services, providers/ansible_tower

@miq-bot assign @bzwei


# 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)
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@gmcculloug gmcculloug requested review from bdunne and bzwei March 22, 2017 18:21
@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from ecdd380 to d2bc767 Compare March 22, 2017 18:38
Copy link
Member

@bdunne bdunne left a 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
Copy link
Member

@bdunne bdunne Mar 22, 2017

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

Copy link
Member

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

@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from d2bc767 to 35c9c0a Compare March 22, 2017 19:45
manager = ExtManagementSystem.find(manager_id)

name_map = {
Copy link
Member

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.

@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from 35c9c0a to 88fa1ba Compare March 23, 2017 14:16
'create' => 'Creating',
'update' => 'Updating',
'delete' => 'Deleting'
}.freeze
Copy link
Contributor

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.

Copy link
Contributor Author

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

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()
Copy link
Contributor

Choose a reason for hiding this comment

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

super

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is pre-destroy hook. I don't know whether it is the better way to place the logic there. That's the reason I suggest we research the Rails way to clean up resources not through association.
@Fryguy @kbrock need your inputs.

Copy link
Member

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')
Copy link
Contributor

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.

Copy link
Contributor Author

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

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

Copy link
Contributor Author

@syncrou syncrou Mar 23, 2017

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.

Copy link
Contributor

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.

@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch 2 times, most recently from 56237ec to 14f267f Compare March 23, 2017 17:12
@bzwei
Copy link
Contributor

bzwei commented Mar 23, 2017

@syncrou I am thinking we may want to create delete_catalog_item method, in line with create_catalog_item and update_catalog_item methods that we already have.

In the base class ServiceTemplate the delete_catalog_item simply call its own destroy! method. In ServiceTemplateAnsiblePlaybook#delete_catalog_item we can

  1. raise an error if there is at least one service still links to it;
  2. remove job templates
  3. call super#delete_catalog_item.

But this requires UI and API to call this method rather than the destroy method. I don't know whether it is appropriate.
cc @h-kataria @jntullo

@@ -151,4 +151,17 @@ def update_catalog_item(options, auth_user = nil)
end
super
end

def destroy(auth_user = 'system')
Copy link
Member

@gmcculloug gmcculloug Mar 23, 2017

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(). 😉

@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from 14f267f to d9f850d Compare March 23, 2017 19:55
@jntullo
Copy link

jntullo commented Mar 23, 2017

@bzwei a delete_catalog_item would be an easy fix to make to the API, and wouldn't affect the way it's used or called - not a breaking change.

@bzwei
Copy link
Contributor

bzwei commented Mar 24, 2017

@jntullo @h-kataria We decided that we don't really need to introduce delete_catalog_item method.

@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from d9f850d to 817b149 Compare March 24, 2017 14:30
@syncrou syncrou force-pushed the delete_catalog_item_for_playbooks branch from 817b149 to 731e8dd Compare March 24, 2017 14:49
@miq-bot
Copy link
Member

miq-bot commented Mar 24, 2017

Checked commit syncrou@731e8dd with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. 🏆

@bdunne
Copy link
Member

bdunne commented Mar 24, 2017

Test failures are unrelated.

@gmcculloug gmcculloug merged commit a254593 into ManageIQ:master Mar 25, 2017
@gmcculloug gmcculloug added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 25, 2017
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.

7 participants