Skip to content

Commit

Permalink
Add manageiq to the extra_var before launching a job
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Mar 22, 2017
1 parent 5059d08 commit 31383b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def preprocess(action, add_options = {})

def execute(action)
jt = job_template(action)
opts = get_job_options(action)
opts = get_job_options(action).deep_merge(:extra_vars => {'manageiq' => manageiq_extra_vars})

_log.info("Launching Ansible Tower job with options: #{opts}")
new_job = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job.create_job(jt, opts)
Expand Down Expand Up @@ -47,6 +47,15 @@ def postprocess(action)

private

def manageiq_extra_vars
{
'api_url' => MiqRegion.my_region.remote_ws_url,
'api_token' => Api::UserTokenService.new.generate_token(evm_owner.userid, 'api'),
'service' => href_slug,
'user' => evm_owner.href_slug
}
end

def get_job_options(action)
job_opts = options[job_option_key(action)].deep_dup

Expand Down
15 changes: 13 additions & 2 deletions spec/models/service_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,20 @@
end

describe '#execute' do
before do
FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number)
loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user),
:miq_request_task => FactoryGirl.create(:miq_request_task))
end

it 'creates an Ansible Tower job' do
expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job)
.to receive(:create_job).with(tower_job_temp, provision_options[:provision_job_options]).and_return(tower_job)
expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job).to receive(:create_job) do |jobtemp, opts|
expect(jobtemp).to eq(tower_job_temp)
exposed_miq = %w(api_url api_token service user)
expect(opts[:extra_vars].delete('manageiq').keys).to include(*exposed_miq)
expect(opts).to include(provision_options[:provision_job_options])
tower_job
end
loaded_service.execute(action)
expected_job_attributes = {
:id => tower_job.id,
Expand Down

0 comments on commit 31383b0

Please sign in to comment.