foreman_remote_execution 1.6.6 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50fc3a3d806569cd6ef1430201210365ab43135ff49037437b5ff7d5ae26e95c
4
- data.tar.gz: 49444e24cc7ce4d174942869a87815c7f58ac1d824493df7cba3c5f592c0dc89
3
+ metadata.gz: 8984a2dd913e555a9c90380466a664e33a43b07281623ea730737919fe281419
4
+ data.tar.gz: 2db7e60c25e0cddcabb57f4541850be79fb2cceb65e3a721a81f5e46a06d0bda
5
5
  SHA512:
6
- metadata.gz: 221de0ed7b0c41a9451b8fc5fa5d1cc2cea6ef25b969e9b28e166ac31c971da5fdbfe624cca3006832f7618cc6e63aff674264d5d6346e83847f7fdb46aa6969
7
- data.tar.gz: 2aa565d2f95cb0704cbc73d49aa7806489fb497a5a73c3738cc23240b8fc582667b8427f892da6a8523baaf69970fba4d343b1751e29e125a84cbba262551ef6
6
+ metadata.gz: 0c63109a7327c158919bd835707556ca487c9840e901a1a2fa43bb2e9ea8d30c08f3c2d73b33c53f2d1f6dc1214b287fbbec35291e2bdc4573c8f744d29e2458
7
+ data.tar.gz: fc2ca8b0cd9bb7da6aa789dda541eaead960780e757d085b52fa393918bbfbf9bd4437df07e91c24af7f886178df66baad31afa31e621aa26881672c794b644f
@@ -4,8 +4,8 @@ module Api
4
4
  include ::Api::Version2
5
5
  include ::Foreman::Renderer
6
6
 
7
- before_action :find_optional_nested_object, :only => %w{output}
8
- before_action :find_host, :only => %w{output}
7
+ before_action :find_optional_nested_object, :only => %w{output raw_output}
8
+ before_action :find_host, :only => %w{output raw_output}
9
9
  before_action :find_resource, :only => %w{show update destroy clone cancel rerun}
10
10
 
11
11
  wrap_parameters JobInvocation, :include => (JobInvocation.attribute_names + [:ssh])
@@ -78,19 +78,23 @@ module Api
78
78
  param :since, String, :required => false
79
79
  def output
80
80
  if @nested_obj.task.scheduled?
81
- render :json => { :refresh => true, :output => [], :delayed => true, :start_at => @nested_obj.task.start_at }
81
+ render :json => delayed_task_output(@nested_obj.task, :default => [])
82
82
  return
83
83
  end
84
- task = @nested_obj.sub_task_for_host(@host)
85
- refresh = true
86
- line_sets = []
87
84
 
88
- if task
89
- refresh = task.pending?
90
- line_sets = output_lines_since task, params[:since]
85
+ render :json => host_output(@nested_obj, @host, :default => [], :since => params[:since])
86
+ end
87
+
88
+ api :GET, '/job_invocations/:id/hosts/:host_id/raw', N_('Get raw output for a host')
89
+ param :id, :identifier, :required => true
90
+ param :host_id, :identifier, :required => true
91
+ def raw_output
92
+ if @nested_obj.task.scheduled?
93
+ render :json => delayed_task_output(@nested_obj.task)
94
+ return
91
95
  end
92
96
 
93
- render :json => { :refresh => refresh, :output => line_sets || [] }
97
+ render :json => host_output(@nested_obj, @host, :raw => true)
94
98
  end
95
99
 
96
100
  api :POST, '/job_invocations/:id/cancel', N_('Cancel job invocation')
@@ -129,7 +133,7 @@ module Api
129
133
 
130
134
  def action_permission
131
135
  case params[:action]
132
- when 'output'
136
+ when 'output', 'raw_output'
133
137
  :view
134
138
  when 'cancel'
135
139
  :cancel
@@ -177,6 +181,22 @@ module Api
177
181
  line_sets = line_sets.drop_while { |o| o['timestamp'].to_f <= since } if since
178
182
  line_sets
179
183
  end
184
+
185
+ def host_output(job_invocation, host, default: nil, since: nil, raw: false)
186
+ refresh = true
187
+
188
+ if (task = job_invocation.sub_task_for_host(host))
189
+ refresh = task.pending?
190
+ output = output_lines_since(task, since)
191
+ output = output.map { |set| set['output'] }.join if raw
192
+ end
193
+
194
+ { :complete => !refresh, :refresh => refresh, :output => output || default }
195
+ end
196
+
197
+ def delayed_task_output(task, default: nil)
198
+ { :complete => false, :refresh => true, :output => default, :delayed => true, :start_at => task.start_at }
199
+ end
180
200
  end
181
201
  end
182
202
  end
@@ -234,6 +234,6 @@ module RemoteExecutionHelper
234
234
  def load_template_from_task(template_invocation, target)
235
235
  task = template_invocation.job_invocation.sub_task_for_host(target)
236
236
  return if task.nil?
237
- task.execution_plan.actions[1].try(:input) { |input| input['script'] }
237
+ task.execution_plan.actions[1].try(:input).try(:[], 'script')
238
238
  end
239
239
  end
@@ -1,4 +1,4 @@
1
- <% title @job_invocation.description, trunc_with_tooltip(@job_invocation.description, 120) %>
1
+ <% title @job_invocation.description %>
2
2
  <% stylesheet 'foreman_remote_execution/job_invocations' %>
3
3
  <% javascript 'charts', 'foreman_remote_execution/template_invocation' %>
4
4
  <%= javascript_include_tag *webpack_asset_paths('foreman_remote_execution', :extension => 'js'), "data-turbolinks-track" => true, 'defer' => 'defer' %>
data/config/routes.rb CHANGED
@@ -43,6 +43,7 @@ Rails.application.routes.draw do
43
43
  resources :job_invocations, :except => [:new, :edit, :update, :destroy] do
44
44
  resources :hosts, :only => :none do
45
45
  get '/', :to => 'job_invocations#output'
46
+ get '/raw', :to => 'job_invocations#raw_output'
46
47
  end
47
48
  member do
48
49
  post 'cancel'
@@ -58,7 +58,7 @@ module ForemanRemoteExecution
58
58
  permission :create_job_invocations, { :job_invocations => [:new, :create, :refresh, :rerun, :preview_hosts],
59
59
  'api/v2/job_invocations' => [:create, :rerun] }, :resource_type => 'JobInvocation'
60
60
  permission :view_job_invocations, { :job_invocations => [:index, :chart, :show, :auto_complete_search], :template_invocations => [:show],
61
- 'api/v2/job_invocations' => [:index, :show, :output] }, :resource_type => 'JobInvocation'
61
+ 'api/v2/job_invocations' => [:index, :show, :output, :raw_output] }, :resource_type => 'JobInvocation'
62
62
  permission :view_template_invocations, { :template_invocations => [:show],
63
63
  'api/v2/template_invocations' => [:template_invocations] }, :resource_type => 'TemplateInvocation'
64
64
  permission :create_template_invocations, {}, :resource_type => 'TemplateInvocation'
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecution
2
- VERSION = '1.6.6'.freeze
2
+ VERSION = '1.6.7'.freeze
3
3
  end
@@ -101,34 +101,83 @@ module Api
101
101
  end
102
102
  end
103
103
 
104
- test 'should provide output for delayed task' do
105
- host = @invocation.template_invocations_hosts.first
106
- ForemanTasks::Task.any_instance.expects(:scheduled?).returns(true)
107
- get :output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
108
- result = ActiveSupport::JSON.decode(@response.body)
109
- assert_equal result['delayed'], true
110
- assert_equal result['refresh'], true
111
- assert_equal result['output'], []
112
- assert_response :success
113
- end
104
+ describe '#output' do
105
+ let(:host) { @invocation.template_invocations_hosts.first }
114
106
 
115
- test 'should provide empty output for host which does not have a task yet' do
116
- host = @invocation.template_invocations_hosts.first
117
- JobInvocation.any_instance.expects(:sub_task_for_host).returns(nil)
118
- get :output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
119
- result = ActiveSupport::JSON.decode(@response.body)
120
- assert_equal result['refresh'], true
121
- assert_equal result['output'], []
122
- assert_response :success
107
+ test 'should provide output for delayed task' do
108
+ ForemanTasks::Task.any_instance.expects(:scheduled?).returns(true)
109
+ get :output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
110
+ result = ActiveSupport::JSON.decode(@response.body)
111
+ assert_equal result['delayed'], true
112
+ assert_equal result['refresh'], true
113
+ assert_equal result['output'], []
114
+ assert_response :success
115
+ end
116
+
117
+ test 'should provide empty output for host which does not have a task yet' do
118
+ JobInvocation.any_instance.expects(:sub_task_for_host).returns(nil)
119
+ get :output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
120
+ result = ActiveSupport::JSON.decode(@response.body)
121
+ assert_equal result['refresh'], true
122
+ assert_equal result['output'], []
123
+ assert_response :success
124
+ end
125
+
126
+ test 'should fail with 404 for non-existing job invocation' do
127
+ invocation_id = @invocation.id + 1
128
+ assert_empty JobInvocation.where(:id => invocation_id)
129
+ get :output, params: { :job_invocation_id => invocation_id, :host_id => 1234 }
130
+ result = ActiveSupport::JSON.decode(@response.body)
131
+ assert_equal result['message'], "Job invocation not found by id '#{invocation_id}'"
132
+ assert_response :missing
133
+ end
123
134
  end
124
135
 
125
- test 'should fail with 404 for non-existing job invocation' do
126
- invocation_id = @invocation.id + 1
127
- assert_empty JobInvocation.where(:id => invocation_id)
128
- get :output, params: { :job_invocation_id => invocation_id, :host_id => 1234 }
129
- result = ActiveSupport::JSON.decode(@response.body)
130
- assert_equal result['message'], "Job invocation not found by id '#{invocation_id}'"
131
- assert_response :missing
136
+ describe 'raw output' do
137
+ let(:fake_output) do
138
+ (1..5).map do |i|
139
+ { 'timestamp' => (Time.now - (5 - i)).to_f, 'output' => "#{i}\n" }
140
+ end
141
+ end
142
+ let(:fake_task) do
143
+ OpenStruct.new :pending? => false, :main_action => OpenStruct.new(:live_output => fake_output)
144
+ end
145
+ let(:host) { @invocation.template_invocations_hosts.first }
146
+
147
+ test 'should provide raw output for a host' do
148
+ JobInvocation.any_instance.expects(:task).returns(OpenStruct.new(:scheduled? => false))
149
+ JobInvocation.any_instance.expects(:sub_task_for_host).returns(fake_task)
150
+ get :raw_output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
151
+ result = ActiveSupport::JSON.decode(@response.body)
152
+ assert_equal result['complete'], true
153
+ assert_equal result['output'], (1..5).map(&:to_s).join("\n") + "\n"
154
+ assert_response :success
155
+ end
156
+
157
+ test 'should provide raw output for delayed task' do
158
+ start_time = Time.now
159
+ JobInvocation.any_instance
160
+ .expects(:task).twice
161
+ .returns(OpenStruct.new(:scheduled? => true, :start_at => start_time))
162
+ JobInvocation.any_instance.expects(:sub_task_for_host).never
163
+ get :raw_output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
164
+ result = ActiveSupport::JSON.decode(@response.body)
165
+ assert_equal result['complete'], false
166
+ assert_equal result['delayed'], true
167
+ assert_nil result['output']
168
+ Time.parse(result['start_at']).to_f.must_be_close_to start_time.to_f
169
+ assert_response :success
170
+ end
171
+
172
+ test 'should provide raw output for host without task' do
173
+ JobInvocation.any_instance.expects(:task).returns(OpenStruct.new(:scheduled? => false))
174
+ JobInvocation.any_instance.expects(:sub_task_for_host)
175
+ get :raw_output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
176
+ result = ActiveSupport::JSON.decode(@response.body)
177
+ assert_equal result['complete'], false
178
+ assert_nil result['output']
179
+ assert_response :success
180
+ end
132
181
  end
133
182
 
134
183
  test 'should cancel a job' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6
4
+ version: 1.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Remote Execution team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-06 00:00:00.000000000 Z
11
+ date: 2018-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface