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

Update catalog item for playbooks #14073

Merged
merged 7 commits into from
Mar 16, 2017

Conversation

syncrou
Copy link
Contributor

@syncrou syncrou commented Feb 24, 2017

  1. Created the update_catalog_item method
  2. Queues a job to update the existing job template and run a refresh (async)
  3. Calls ServiceTemplate#update_catalog_item to handle updating the resource actions etc.
  4. If a new dialog name is passed in a new dialog is created.
  5. If the id of the existing dialog is passed in, no changes are made to that dialog

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

@syncrou
Copy link
Contributor Author

syncrou commented Feb 24, 2017

@miq-bot add_label enhancement providers/ansible_tower

@miq-bot assign @bzwei

cc - @jntullo @gmcculloug

@miq-bot
Copy link
Member

miq-bot commented Feb 24, 2017

@syncrou Cannot apply the following label because they are not recognized: enhancement providers/ansible_tower

@syncrou
Copy link
Contributor Author

syncrou commented Feb 24, 2017

@miq-bot add_label enhancement, providers/ansible_tower

@@ -1,4 +1,12 @@
class ServiceTemplateAnsiblePlaybook < ServiceTemplateGeneric
def self.job_template_class
Copy link
Contributor

Choose a reason for hiding this comment

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

should use a private constant

@@ -74,15 +72,15 @@ def self.create_job_templates(service_name, description, config_info, auth_user)
def self.create_job_template(name, description, info, auth_user)
tower, params = build_parameter_list(name, description, info)

task_id = ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript.create_in_provider_queue(tower.id, params, auth_user)
task_id = job_template_class.create_in_provider_queue(tower.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.

I think before the change the readability is better although the line looks longer.

@@ -33,6 +33,37 @@ def create_in_provider_queue(manager_id, params, auth_user = nil)

MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def update_in_provider(manager_id, params)
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 definitely combine update and create methods into one common method, same to the queue version.

The public methods you can still have create and update separated, but they redirect to a common private method.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from a00f753 to 26badb7 Compare March 1, 2017 17:14

# 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) if manager.authentication_status_ok?
Copy link
Contributor

Choose a reason for hiding this comment

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

EmsRefresh.queue_refresh(manager, nil, true)


private

def create_or_update_in_provider_queue(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.

def create_or_update_in_provider_queue(action, manager_id, params, auth_user)

end

def update_in_provider_queue(manager_id, params, auth_user = nil)
create_or_update_in_provider_queue(manager_id, params, auth_user)
Copy link
Contributor

@bzwei bzwei Mar 1, 2017

Choose a reason for hiding this comment

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

create_or_update_in_provider_queue('update', manager_id, params, auth_user)

def create_in_provider_queue(manager_id, params, auth_user = nil)
create_or_update_in_provider_queue(manager_id, params, auth_user)
Copy link
Contributor

@bzwei bzwei Mar 1, 2017

Choose a reason for hiding this comment

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

create_or_update_in_provider_queue('create', manager_id, params, auth_user)


params[:manager_ref] = job_template(action).manager_ref

ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript.update_in_provider_queue(tower.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.

ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript, please update the same for creation.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from bb88dad to 5798fa3 Compare March 1, 2017 21:48
@miq-bot
Copy link
Member

miq-bot commented Mar 3, 2017

This pull request is not mergeable. Please rebase and repush.

@bzwei bzwei force-pushed the update_catalog_item_for_playbooks branch 2 times, most recently from 1937cca to 11e5858 Compare March 3, 2017 19:51
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch 2 times, most recently from fb50d6e to d913343 Compare March 10, 2017 14:57
@miq-bot
Copy link
Member

miq-bot commented Mar 10, 2017

This pull request is not mergeable. Please rebase and repush.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from d913343 to 4747286 Compare March 10, 2017 20:01
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from 4747286 to 10ea2dd Compare March 13, 2017 21:20
config_info[action][:dialog] =
Dialog::AnsiblePlaybookService.new.create_dialog(config_info[:new_dialog_name], job_template)
end
def self.create_new_dialog(dialog_name, job_template)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can make this a private instance method

@@ -44,6 +41,7 @@ def self.create_catalog_item(options, auth_user)
next unless dialog_name

job_template = enhanced_config.fetch_path(action, :configuration_template)

new_dialog = Dialog::AnsiblePlaybookServiceDialog.create_dialog(dialog_name, job_template)
Copy link
Contributor

Choose a reason for hiding this comment

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

switch to use service_template.send(:create_new_dialog)

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from 10ea2dd to 6dd6864 Compare March 14, 2017 20:11
name = options[:name]
description = options[:description]
[:provision, :retirement, :reconfigure].each do |action|
next unless config_info[action] && config_info[action].keys.include?(:playbook_id)
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 - Would there ever be a case where we would create a new Dialog without updating the JobTemplate?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I think it is possible.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from 6dd6864 to 0fbc44d Compare March 14, 2017 20:53
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from 0fbc44d to ecb56b9 Compare March 14, 2017 20:58
@bzwei
Copy link
Contributor

bzwei commented Mar 14, 2017

@syncrou please take a look at #14328. It may have impact on how you update a catalog item too. Sorry for keeping you constantly update this PR because other PRs are merged.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from ecb56b9 to eaa0217 Compare March 14, 2017 21:15
@syncrou
Copy link
Contributor Author

syncrou commented Mar 14, 2017

@bzwei - Nothing obvious is jumping out at me for #14328

My current changes (looking for a :playbook_id key) should handle the updated validation.

Thanks for the heads up.

end

def update_catalog_item(options, auth_user = nil)
config_info = validate_update_config_info(options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Base's validate_update_config_info is not sufficient, we need to override it like this

def validate_update_config_info(options)`
  opts = super
  self.class.send(:validate_config_info, opts)
end

[:provision, :retirement, :reconfigure].each do |action|
next unless config_info[action]
info = config_info[action]
self.class.send(:create_new_dialog, info[:new_dialog_name], job_template(action)) if info[:new_dialog_name]
Copy link
Contributor

Choose a reason for hiding this comment

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

create_new_dialog is now instance method that you can directly call.
Also just like create_catalog_item, we need to update options[:config_info][action][:dialog_id] to the newly created dialog id.

)
expect(service_template.dialogs.first.name).to eq catalog_item_options_three
.fetch_path(:config_info, :provision, :new_dialog_name)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add expect(service_template.resource_actions.first) to contain newly created/updated job template.

describe '#update_catalog_item' do
it 'updates and returns the modified catalog item' do
service_template = prebuild_service_template
expect(described_class).to receive(:create_new_dialog)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if you don't return a new dialog here how can you assert the dialog name in line 178.

next unless info.keys.include?(:playbook_id)
tower, params = self.class.send(:build_parameter_list, name, description, info)
params[:manager_ref] = job_template(action).manager_ref
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript.update_in_provider_queue(tower.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.

We need to handle the case for example initially there was no playbook assigned to retirement, but through the update now a new playbook is given. We will also need to update the job template in the corresponding resource action,

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 - Per our conversations around this change - I will add the create_in_provider_queue behavior in a followup PR.

@miq-bot
Copy link
Member

miq-bot commented Mar 15, 2017

This pull request is not mergeable. Please rebase and repush.

@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from eaa0217 to 629dfdf Compare March 15, 2017 19:22
1. created the update_catalog_item method
2. Queues a job to update the existing job template and run a refresh (async)
3. Calls ServiceTemplate#update_catalog_item to handle updating the resource actions etc.
4. If a new dialog name is passed in a new dialog is created.
5. If the id of the existing dialog is passed in, no changes are made to that dialog

https://www.pivotaltracker.com/story/show/139020599
create_in_provider_queue now handles both the create and update queuing

https://www.pivotaltracker.com/story/show/139020599
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from 629dfdf to 40d37bf Compare March 15, 2017 19:37
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch 2 times, most recently from 93b2fa6 to c7d63b7 Compare March 15, 2017 20:05
There are cases where the :retirement key of the config
will not include a playbook_id

In these cases we need to skip creation of a job template as a
playbook id is a requirement

https://www.pivotaltracker.com/story/show/139020599
@syncrou syncrou force-pushed the update_catalog_item_for_playbooks branch from c7d63b7 to 078c178 Compare March 15, 2017 23:58
@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

Checked commits syncrou/manageiq@870717e~...078c178 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. ⭐

@gmcculloug
Copy link
Member

Tested and verified this is working now. Thanks @syncrou.

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

5 participants