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

Service AnsibleTower and EmbeddedAnsible UI parity #17712

Merged
merged 3 commits into from
Jul 19, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions app/models/service_ansible_tower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down