Skip to content

Commit

Permalink
Prefer :dialog_id to :new_dialog_name in config_info
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed May 1, 2017
1 parent 75d8148 commit ee74ab4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
13 changes: 7 additions & 6 deletions app/models/service_template_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def self.create_catalog_item(options, auth_user)
transaction do
create_from_options(options).tap do |service_template|
[:provision, :retirement, :reconfigure].each do |action|
dialog_name = config_info.fetch_path(action, :new_dialog_name)
next unless dialog_name
action_info = enhanced_config[action]
next unless service_template.send(:new_dialog_required?, action_info)

job_template = enhanced_config.fetch_path(action, :configuration_template)
hosts = enhanced_config.fetch_path(action, :hosts)
dialog_name = action_info[:new_dialog_name]
job_template = action_info[:configuration_template]
hosts = action_info[:hosts]

new_dialog = service_template.send(:create_new_dialog, dialog_name, job_template, hosts)
enhanced_config[action][:dialog] = new_dialog
action_info[:dialog] = new_dialog
service_template.options[:config_info][action][:dialog_id] = new_dialog.id
end
service_template.create_resource_actions(enhanced_config)
Expand Down Expand Up @@ -202,7 +203,7 @@ def delete_job_templates(job_templates)
end

def new_dialog_required?(info)
info && info.key?(:new_dialog_name)
info && info.key?(:new_dialog_name) && !info.key?(:dialog_id)
end

def self.new_job_template_required?(info, action, service_template)
Expand Down
9 changes: 4 additions & 5 deletions spec/models/service_template_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,18 @@
expect(service_template.resource_actions.first.dialog.id).to eq new_dialog_record.id
end

it 'uses the existing dialog if :service_dialog_id is passed in' do
it 'uses the existing dialog if :dialog_id is passed in' do
info = catalog_item_options_three.fetch_path(:config_info, :provision)
info.delete(:new_dialog_name)
info[:service_dialog_id] = service_template.dialogs.first.id
info[:dialog_id] = service_template.dialogs.first.id

expect(service_template.dialogs.first.id).to eq info[:service_dialog_id]
expect(service_template.dialogs.first.id).to eq info[:dialog_id]
expect(described_class).to receive(:create_new_dialog).never
expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript).to receive(:update_in_provider_queue).once

service_template.update_catalog_item(catalog_item_options_three, user)
service_template.reload

expect(service_template.dialogs.first.id).to eq info[:service_dialog_id]
expect(service_template.dialogs.first.id).to eq info[:dialog_id]
end
end

Expand Down

0 comments on commit ee74ab4

Please sign in to comment.