Skip to content

Commit

Permalink
Merge pull request #16668 from syncrou/syncronize_with_automation
Browse files Browse the repository at this point in the history
Add manageiq_connection as an extra_var key sent through services
  • Loading branch information
mkanoor authored Dec 19, 2017
2 parents 2fa99b2 + 50b08b4 commit 17b389f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
31 changes: 24 additions & 7 deletions app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def preprocess(action, add_options = {})

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

_log.info("Launching Ansible Tower job with options:")
Expand Down Expand Up @@ -63,15 +63,32 @@ def on_error(action)

def manageiq_extra_vars(action)
{
'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,
'group' => miq_group.href_slug,
'action' => action
'api_url' => api_url,
'api_token' => api_token,
'service' => href_slug,
'user' => evm_owner.href_slug,
'group' => miq_group.href_slug,
'action' => action,
'X_MIQ_Group' => evm_owner.current_group.description
}.merge(request_options_extra_vars)
end

def manageiq_connection_env
{
'url' => api_url,
'token' => api_token,
'X_MIQ_Group' => evm_owner.current_group.description
}
end

def api_token
@api_token ||= Api::UserTokenService.new.generate_token(evm_owner.userid, 'api')
end

def api_url
@api_url ||= MiqRegion.my_region.remote_ws_url
end

def request_options_extra_vars
miq_request_task.options.fetch_path(:request_options, :manageiq_extra_vars) || {}
end
Expand Down
6 changes: 4 additions & 2 deletions spec/models/service_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@
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}})
loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user),
loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user_with_group),
:miq_group => FactoryGirl.create(:miq_group),
:miq_request_task => miq_request_task)
end

it 'creates an Ansible Tower job' do
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 group) + control_extras.keys
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)

expected_opts = provision_options[:provision_job_options].except(:hosts)
expected_opts[:extra_vars]['pswd'] = decrpyted_val
Expand Down

0 comments on commit 17b389f

Please sign in to comment.