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

Add manageiq to the extra_var before launching a job #14354

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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