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_connection as an extra_var key sent through services #16668

Merged
merged 1 commit into from
Dec 19, 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
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
Copy link
Contributor Author

@syncrou syncrou Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good way for us to share this method with automate?

{
'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