-
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
Update catalog item for playbooks #14073
Update catalog item for playbooks #14073
Conversation
@miq-bot add_label enhancement providers/ansible_tower cc - @jntullo @gmcculloug |
@syncrou Cannot apply the following label because they are not recognized: enhancement providers/ansible_tower |
@miq-bot add_label enhancement, providers/ansible_tower |
@@ -1,4 +1,12 @@ | |||
class ServiceTemplateAnsiblePlaybook < ServiceTemplateGeneric | |||
def self.job_template_class |
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.
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) |
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 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) |
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 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.
a00f753
to
26badb7
Compare
|
||
# 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? |
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.
EmsRefresh.queue_refresh(manager, nil, true)
|
||
private | ||
|
||
def create_or_update_in_provider_queue(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.
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) |
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.
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) |
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.
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) |
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.
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript
, please update the same for creation.
bb88dad
to
5798fa3
Compare
This pull request is not mergeable. Please rebase and repush. |
1937cca
to
11e5858
Compare
fb50d6e
to
d913343
Compare
This pull request is not mergeable. Please rebase and repush. |
d913343
to
4747286
Compare
4747286
to
10ea2dd
Compare
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) |
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.
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) |
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.
switch to use service_template.send(:create_new_dialog)
10ea2dd
to
6dd6864
Compare
name = options[:name] | ||
description = options[:description] | ||
[:provision, :retirement, :reconfigure].each do |action| | ||
next unless config_info[action] && config_info[action].keys.include?(:playbook_id) |
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 - Would there ever be a case where we would create a new Dialog without updating the JobTemplate
?
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, I think it is possible.
6dd6864
to
0fbc44d
Compare
0fbc44d
to
ecb56b9
Compare
ecb56b9
to
eaa0217
Compare
end | ||
|
||
def update_catalog_item(options, auth_user = nil) | ||
config_info = validate_update_config_info(options) |
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.
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] |
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.
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 |
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 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) |
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 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) |
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.
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,
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 - Per our conversations around this change - I will add the create_in_provider_queue
behavior in a followup PR.
This pull request is not mergeable. Please rebase and repush. |
eaa0217
to
629dfdf
Compare
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
629dfdf
to
40d37bf
Compare
93b2fa6
to
c7d63b7
Compare
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
c7d63b7
to
078c178
Compare
Checked commits syncrou/manageiq@870717e~...078c178 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Tested and verified this is working now. Thanks @syncrou. |
update_catalog_item
methodServiceTemplate#update_catalog_item
to handle updating the resource actions etc.https://www.pivotaltracker.com/story/show/139020599