From 71ef10ae1c181658d970fd24a596a05a8a7b0a9f Mon Sep 17 00:00:00 2001 From: Tomas Coufal Date: Mon, 16 Jul 2018 15:46:49 +0200 Subject: [PATCH 1/3] Unify `.job` method interface (Playbook and Tower) --- app/models/service_ansible_tower.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/service_ansible_tower.rb b/app/models/service_ansible_tower.rb index b1227a2f11d..3c44a5201d5 100644 --- a/app/models/service_ansible_tower.rb +++ b/app/models/service_ansible_tower.rb @@ -16,8 +16,9 @@ def launch_job save_launch_options end - def job - @job ||= service_resources.find { |sr| sr.resource.kind_of?(OrchestrationStack) }.try(:resource) + def job(_action = nil) + # parameter _action unifies the interface with ServiceAnsiblePlaybook + @job ||= service_resources.find_by(:resource_type => "OrchestrationStack").try(:resource) end def build_stack_options_from_dialog(dialog_options) From 598a309f7dbfe20df33f6da1d55c79ce3904413c Mon Sep 17 00:00:00 2001 From: Tomas Coufal Date: Mon, 16 Jul 2018 15:48:06 +0200 Subject: [PATCH 2/3] Move `raw_stdout_via_worker` to shared Ansible job definition --- .../providers/embedded_ansible/automation_manager/job.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 a731e315758..8fb78ffe135 100644 --- a/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb +++ b/app/models/manageiq/providers/embedded_ansible/automation_manager/job.rb @@ -17,13 +17,6 @@ def raw_stdout_via_worker(userid, format = 'txt') ).id end - options = {:userid => userid || 'system', :action => 'ansible_stdout'} - queue_options = {:class_name => self.class, - :method_name => 'raw_stdout', - :instance_id => id, - :args => [format], - :priority => MiqQueue::HIGH_PRIORITY, - :role => 'embedded_ansible'} - MiqTask.generic_action_with_callback(options, queue_options) + super(userid, format, 'embedded_ansible') end end From 0385c05103018b5b667a411f3320d5b21c2a011f Mon Sep 17 00:00:00 2001 From: Tomas Coufal Date: Wed, 18 Jul 2018 13:07:12 +0200 Subject: [PATCH 3/3] Move spec to shared codebase --- .../automation_manager/job_spec.rb | 51 ++++--------------- 1 file changed, 11 insertions(+), 40 deletions(-) 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 d9add37a37e..02c85f7266c 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 @@ -1,49 +1,20 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job do let(:job) { FactoryGirl.create(:embedded_ansible_job) } - it_behaves_like 'ansible job' - - describe '#raw_stdout_via_worker' do - before do - EvmSpecHelper.create_guid_miq_server_zone - region = MiqRegion.seed - allow(region).to receive(:role_active?).with("embedded_ansible").and_return(role_enabled) - allow(MiqRegion).to receive(:my_region).and_return(region) - end - - context 'when embedded_ansible role is enabled' do - let(:role_enabled) { true } - - before do - allow(described_class).to receive(:find).and_return(job) + before do + region = MiqRegion.seed + allow(region).to receive(:role_active?).with("embedded_ansible").and_return(role_enabled) + allow(MiqRegion).to receive(:my_region).and_return(region) + end - allow(MiqTask).to receive(:wait_for_taskid) do - request = MiqQueue.find_by(:class_name => described_class.name) - request.update_attributes(:state => MiqQueue::STATE_DEQUEUE) - request.delivered(*request.deliver) - end - end + context 'when embedded_ansible role is enabled' do + let(:role_enabled) { true } - it 'gets stdout from the job' do - expect(job).to receive(:raw_stdout).and_return('A stdout from the job') - taskid = job.raw_stdout_via_worker('user') - MiqTask.wait_for_taskid(taskid) - expect(MiqTask.find(taskid)).to have_attributes( - :task_results => 'A stdout from the job', - :status => 'Ok' - ) - end - - it 'returns the error message' do - expect(job).to receive(:raw_stdout).and_throw('Failed to get stdout from the job') - taskid = job.raw_stdout_via_worker('user') - MiqTask.wait_for_taskid(taskid) - expect(MiqTask.find(taskid).message).to include('Failed to get stdout from the job') - expect(MiqTask.find(taskid).status).to eq('Error') - end - end + it_behaves_like 'ansible job' + end - context 'when embedded_ansible role is disabled' do + context 'when embedded_ansible role is disabled' do + describe '#raw_stdout_via_worker' do let(:role_enabled) { false } it 'returns an error message' do