From 1c224cbfeae8d489eec7b7caf415bb93b35f3555 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Thu, 14 Jun 2018 16:25:44 +0200 Subject: [PATCH] Change and rename raw_stdout to fix displaying details of active ansible services --- .../shared/automation_manager/job.rb | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/job.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/job.rb index 82e6afb3714..270d6975310 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/job.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/job.rb @@ -134,16 +134,25 @@ def raw_status raise MiqException::MiqOrchestrationStatusError, err.to_s, err.backtrace end - def raw_stdout(format = 'txt') - ext_management_system.with_provider_connection do |connection| - connection.api.jobs.find(ems_ref).stdout(format) + # Intend to be called by UI to display stdout. Therefore the error message directly returned + # instead of raising an exception. + def raw_stdout_via_worker(userid = User.current_user, format = 'txt') + unless MiqRegion.my_region.role_active?("embedded_ansible") + return "Cannot get standard output of this playbook because the embedded Ansible role is not enabled" end - rescue AnsibleTowerClient::ResourceNotFoundError - msg = "AnsibleTower Job #{name} with id(#{id}) does not exist on #{ext_management_system.name}" - raise MiqException::MiqOrchestrationStackNotExistError, msg - rescue => err - _log.error "Reading AnsibleTower Job #{name} with id(#{id}) stdout failed with error: #{err}" - raise MiqException::MiqOrchestrationStatusError, err.to_s, err.backtrace - end + options = {:userid => userid, :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'} + taskid = MiqTask.generic_action_with_callback(options, queue_options) + MiqTask.wait_for_taskid(taskid) + miq_task = MiqTask.find(taskid) + results = miq_task.task_results || miq_task.message + miq_task.destroy + results + end end