diff --git a/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb b/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb index b46ccb98ce1..ae175ce761b 100644 --- a/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb +++ b/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb @@ -18,6 +18,8 @@ def self.create_stack(template, options = {}) template_ref = template.new_record? ? nil : template new(:name => template.name, :ext_management_system => template.manager, + :verbosity => template.variables["verbosity"].to_i, + :authentications => collect_authentications(template.manager, options), :job_template => template_ref).tap do |stack| stack.send(:update_with_provider_object, raw_create_stack(template, options)) end @@ -97,6 +99,17 @@ def self.reconcile_extra_vars_keys(_template, options) end private_class_method :reconcile_extra_vars_keys + def self.collect_authentications(manager, options) + credential_ids = options.values_at( + :credential, + :cloud_credential, + :network_credential, + :vault_credential + ).compact + manager.credentials.where(:id => credential_ids) + end + private_class_method :collect_authentications + def update_with_provider_object(raw_job) self.miq_task ||= raw_job.miq_task diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb index 7ff75375087..a7e62db53ad 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb @@ -72,7 +72,16 @@ end context "#refresh_ems" do - subject { described_class.create_job(template, {}) } + subject { described_class.create_job(template, job_options) } + + let(:job_options) do + { + :credential => machine_credential.id, + :cloud_credential => cloud_credential.id, + :network_credential => network_credential.id, + :vault_credential => vault_credential.id + } + end it "syncs the job with the provider" do subject.refresh_ems @@ -82,22 +91,22 @@ :status => subject.miq_task.state, :start_time => subject.miq_task.started_on, :finish_time => nil, - :verbosity => nil # TODO: Implement this as an job options, right? + :verbosity => 0 ) subject.reload expect(subject.ems_ref).to eq(subject.miq_task.id.to_s) expect(subject.status).to eq(subject.miq_task.state) + expect(subject.authentications).to match_array([machine_credential, vault_credential, cloud_credential, network_credential]) + # TODO/FIXME: This needs to be implemented. # # The following are implemented in AnsibleTower::Job but not here: # # - update_parameters - # - update_credentials # - update_plays # # expect(subject.parameters.first).to have_attributes(:name => "param1", :value => "val1") - # expect(subject.authentications).to match_array([machine_credential, vault_credential, cloud_credential, network_credential]) # expect(subject.job_plays.first).to have_attributes( # :start_time => a_value_within(1.second).of(the_raw_plays.first.created), # :finish_time => a_value_within(1.second).of(the_raw_plays.last.created),