Skip to content

Commit

Permalink
Add extra_vars for ServiceAnsibleTower.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Oct 4, 2018
1 parent 8700f1d commit 4358c88
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/service_ansible_tower.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ServiceAnsibleTower < Service
include ApiAnsibleMixin
include ServiceConfigurationMixin
include ServiceOrchestrationOptionsMixin

Expand All @@ -9,6 +10,12 @@ class ServiceAnsibleTower < Service

def launch_job
job_class = "#{job_template.class.parent.name}::#{job_template.class.stack_type}".constantize
job_options.deep_merge!(
:extra_vars => {
'manageiq' => service_manageiq_env,
'manageiq_connection' => manageiq_connection_env(evm_owner)
}
)
@job = job_class.create_job(job_template, job_options)
add_resource(@job)
@job
Expand Down Expand Up @@ -62,4 +69,15 @@ def extra_vars_from_dialog(dialog_options)
end
end
end

def service_manageiq_env
{
'service' => href_slug
}.merge(manageiq_env(evm_owner, miq_group))
.merge(request_options_extra_vars)
end

def request_options_extra_vars
miq_request_task.options.fetch_path(:request_options, :manageiq_extra_vars) || {}
end
end
15 changes: 15 additions & 0 deletions spec/models/service_ansible_tower_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,26 @@
end

describe '#launch_job' do
let(:control_extras) { {'a' => 'A', 'b' => 'B', 'c' => 'C'} }
before do
FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number)
miq_request_task = FactoryGirl.create(:miq_request_task)
miq_request_task.update_attributes(:options => {:request_options => {:manageiq_extra_vars => control_extras}})
service.update_attributes(:evm_owner => FactoryGirl.create(:user_with_group),
:miq_group => FactoryGirl.create(:miq_group),
:miq_request_task => miq_request_task)
end

it 'launches a job through ansible tower provider' do
allow(ManageIQ::Providers::AnsibleTower::AutomationManager::Job).to receive(:raw_create_stack) do |template, opts|
expect(template).to be_kind_of ConfigurationScript
expect(opts).to have_key(:limit)
expect(opts).to have_key(:extra_vars)

exposed_miq = %w(api_url api_token service user group X_MIQ_Group) + control_extras.keys
exposed_connection = %w(url token X_MIQ_Group)
expect(opts[:extra_vars].delete('manageiq').keys).to include(*exposed_miq)
expect(opts[:extra_vars].delete('manageiq_connection').keys).to include(*exposed_connection)
end.and_return(double(:raw_job,
:id => 1,
:status => "completed",
Expand Down

0 comments on commit 4358c88

Please sign in to comment.