foreman_remote_execution 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_remote_execution/template_input.js +0 -10
  3. data/app/assets/javascripts/foreman_remote_execution/template_invocation.js +1 -12
  4. data/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss +1 -0
  5. data/app/controllers/api/v2/job_invocations_controller.rb +5 -1
  6. data/app/helpers/job_invocation_output_helper.rb +5 -4
  7. data/app/helpers/job_invocations_helper.rb +0 -29
  8. data/app/helpers/remote_execution_helper.rb +1 -24
  9. data/app/lib/foreman_remote_execution/renderer/scope/input.rb +28 -8
  10. data/app/models/concerns/foreman_remote_execution/template_extensions.rb +0 -12
  11. data/app/models/concerns/foreman_remote_execution/template_input_extensions.rb +9 -0
  12. data/app/models/concerns/foreman_remote_execution/template_overrides.rb +11 -0
  13. data/app/models/input_template_renderer.rb +16 -17
  14. data/app/models/job_invocation.rb +14 -4
  15. data/app/models/job_invocation_composer.rb +2 -6
  16. data/app/models/job_template.rb +23 -52
  17. data/app/models/template_invocation_input_value.rb +12 -1
  18. data/app/views/api/v2/smart_proxies/pubkey.json.rabl +1 -0
  19. data/app/views/job_invocations/_form.html.erb +1 -7
  20. data/app/views/job_templates/_custom_tabs.html.erb +0 -7
  21. data/app/views/template_invocations/_output_line_set.html.erb +2 -2
  22. data/app/views/templates/ssh/module_action.erb +67 -0
  23. data/app/views/templates/ssh/package_action.erb +39 -7
  24. data/app/views/templates/ssh/power_action.erb +2 -1
  25. data/app/views/templates/ssh/puppet_run_once.erb +1 -0
  26. data/app/views/templates/ssh/run_command.erb +1 -0
  27. data/app/views/templates/ssh/service_action.erb +9 -1
  28. data/config/routes.rb +0 -1
  29. data/lib/foreman_remote_execution/engine.rb +4 -0
  30. data/lib/foreman_remote_execution/version.rb +1 -1
  31. data/locale/de/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  32. data/locale/de/foreman_remote_execution.po +3 -72
  33. data/locale/en/foreman_remote_execution.po +3 -72
  34. data/locale/en_GB/foreman_remote_execution.po +3 -72
  35. data/locale/es/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  36. data/locale/es/foreman_remote_execution.po +3 -72
  37. data/locale/foreman_remote_execution.pot +124 -225
  38. data/locale/fr/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  39. data/locale/fr/foreman_remote_execution.po +3 -72
  40. data/locale/ja/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  41. data/locale/ja/foreman_remote_execution.po +3 -72
  42. data/locale/ko/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  43. data/locale/ko/foreman_remote_execution.po +3 -72
  44. data/locale/pt_BR/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  45. data/locale/pt_BR/foreman_remote_execution.po +3 -72
  46. data/locale/ru/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  47. data/locale/ru/foreman_remote_execution.po +3 -72
  48. data/locale/zh_CN/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  49. data/locale/zh_CN/foreman_remote_execution.po +3 -72
  50. data/locale/zh_TW/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  51. data/locale/zh_TW/foreman_remote_execution.po +3 -72
  52. data/test/factories/foreman_remote_execution_factories.rb +6 -5
  53. data/test/functional/api/v2/job_invocations_controller_test.rb +10 -0
  54. data/test/unit/input_template_renderer_test.rb +52 -21
  55. data/test/unit/job_invocation_composer_test.rb +2 -2
  56. data/test/unit/job_invocation_test.rb +36 -0
  57. metadata +6 -19
  58. data/app/controllers/api/v2/template_inputs_controller.rb +0 -92
  59. data/app/controllers/concerns/foreman/controller/parameters/template_input.rb +0 -17
  60. data/app/models/template_input.rb +0 -179
  61. data/app/views/api/v2/template_inputs/base.json.rabl +0 -3
  62. data/app/views/api/v2/template_inputs/create.json.rabl +0 -3
  63. data/app/views/api/v2/template_inputs/index.json.rabl +0 -3
  64. data/app/views/api/v2/template_inputs/main.json.rabl +0 -10
  65. data/app/views/api/v2/template_inputs/show.json.rabl +0 -3
  66. data/app/views/template_inputs/_form.html.erb +0 -25
  67. data/app/views/template_inputs/_invocation_form.html.erb +0 -7
  68. data/db/migrate/20150616080015_create_template_input.rb +0 -19
  69. data/db/migrate/20150827152730_add_options_to_template_input.rb +0 -5
  70. data/db/migrate/20160127134031_add_advanced_to_template_input.rb +0 -11
  71. data/test/functional/api/v2/template_inputs_controller_test.rb +0 -56
  72. data/test/unit/template_input_test.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f8f8c5208313baaca0c289321f6cc4c07c8d27d9f8d97c83e764d58a902f152
4
- data.tar.gz: cf6df45271fa254133e0c15e1084f835984e857247b1b8980b61555db9b43ae2
3
+ metadata.gz: 4cab4376bc924e75310a2a56b5a659a5305a0da5dc8dbbd9e850f41d1a67b95b
4
+ data.tar.gz: 6d9bf2cefb54c4f8360dad8026c6bf5dd825466f0a6fe74be404016c1e312ca7
5
5
  SHA512:
6
- metadata.gz: 8c0ebcfd20e690e37e882e7a1d93be312989252d9b875977852e4587b7b3fe2232bc745f89f7d5d83bce1dc6c6480871ad4daae5d30b482d3f9b7fccf64089fd
7
- data.tar.gz: 1fc408ceb6aebaddd2fb83fe91ceb9f7674ae3735bc2eb89c522903dc1f67175f348261557a95ae30d091dc409aa20cfc9a4133426b1f42913c2f6da165c3781
6
+ metadata.gz: 06540f56e6585f76429447973081fd15dabda10f8e58da00783999bb3eec0a237fa61703c98a0e667e0bfa89d4c835e949284521005d2a27a5396958e4d05c7c
7
+ data.tar.gz: 678fa795c597717faedc8595e5f45ee51a367aa4f0bd974af7329300b82415f636751f5fa24ae3cb37bb7b67ced63d4d58907d89fb36ccfb7c618c4cab3a781d
@@ -1,13 +1,3 @@
1
- $(document).on('change', 'select.input_type_selector', function () {
2
- update_visibility_after_input_type_change($(this));
3
- });
4
-
5
- function update_visibility_after_input_type_change(select){
6
- fieldset = select.closest('fieldset');
7
- fieldset.find('div.custom_input_type_fields').hide();
8
- fieldset.find('div.' + select.val() + '_input_type').show();
9
- }
10
-
11
1
  function update_foreign_input_set_include(include_all_checkbox) {
12
2
  fieldset = $(include_all_checkbox.closest('fieldset'));
13
3
  fieldset.find('input.foreign_input_set_include').prop('disabled', include_all_checkbox.checked);
@@ -70,18 +70,7 @@ function job_invocation_form_binds() {
70
70
 
71
71
  $('select#targeting_bookmark_id').on('change', refresh_search_query);
72
72
 
73
- $('a.advanced_fields_switch').on('click', toggle_advanced_fields )
74
- }
75
-
76
- function toggle_advanced_fields() {
77
- switcher = $('a.advanced_fields_switch');
78
- original = switcher.html();
79
- switcher.html(switcher.data('alternativeLabel'));
80
- switcher.data('alternativeLabel', original);
81
-
82
- switcher.siblings('i').toggleClass('fa-angle-right').toggleClass('fa-angle-down');
83
-
84
- $('div.advanced').toggle()
73
+ tfm.advancedFields.initAdvancedFields()
85
74
  }
86
75
 
87
76
  function delayed_refresh(url, data){
@@ -44,6 +44,7 @@ div.terminal {
44
44
  div.line div.content {
45
45
  position: relative;
46
46
  margin-left: 50px;
47
+ white-space: pre;
47
48
  }
48
49
 
49
50
  a {
@@ -4,7 +4,7 @@ module Api
4
4
  include ::Api::Version2
5
5
  include ::Foreman::Renderer
6
6
 
7
- before_action :find_optional_nested_object
7
+ before_action :find_optional_nested_object, :only => %w{output}
8
8
  before_action :find_host, :only => %w{output}
9
9
  before_action :find_resource, :only => %w{show update destroy clone cancel rerun}
10
10
 
@@ -123,6 +123,10 @@ module Api
123
123
 
124
124
  private
125
125
 
126
+ def allowed_nested_id
127
+ %w(job_invocation_id)
128
+ end
129
+
126
130
  def action_permission
127
131
  case params[:action]
128
132
  when 'output'
@@ -1,4 +1,5 @@
1
1
  module JobInvocationOutputHelper
2
+ COLOR_PATTERN = /\e\[.*?m/
2
3
  CONSOLE_COLOR = {
3
4
  '31' => 'red',
4
5
  '32' => 'lightgreen',
@@ -17,19 +18,19 @@ module JobInvocationOutputHelper
17
18
  }.tap { |h| h.default = 'default' }.freeze
18
19
 
19
20
  def colorize_line(line)
20
- line = line.gsub(/\e\[.*?m/) do |seq|
21
+ line = line.gsub(COLOR_PATTERN) do |seq|
21
22
  color = seq[/(\d+)m/,1]
22
23
  "{{{format color:#{color}}}}"
23
24
  end
24
25
 
25
- current_color = 'default'
26
+ @current_color ||= 'default'
26
27
  out = %{<span style="color: #{@current_color}">}
27
28
  parts = line.split(/({{{format.*?}}})/)
28
29
  parts.each do |console_line|
29
30
  if console_line.include?('{{{format')
30
31
  if (color_index = console_line[/color:(\d+)/, 1]).present?
31
- current_color = CONSOLE_COLOR[color_index]
32
- out << %{</span><span style="color: #{current_color}">}
32
+ @current_color = CONSOLE_COLOR[color_index]
33
+ out << %{</span><span style="color: #{@current_color}">}
33
34
  end
34
35
  else
35
36
  out << h(console_line)
@@ -12,35 +12,6 @@ module JobInvocationsHelper
12
12
  end
13
13
  end
14
14
 
15
- def job_invocation_task_buttons(task)
16
- job_invocation = task.task_groups.find { |group| group.class == JobInvocationTaskGroup }.job_invocation
17
- buttons = []
18
- if authorized_for(hash_for_new_job_invocation_path)
19
- buttons << link_to(_('Rerun'), rerun_job_invocation_path(:id => job_invocation.id),
20
- :class => 'btn btn-default',
21
- :title => _('Rerun the job'))
22
- end
23
- if authorized_for(hash_for_new_job_invocation_path)
24
- buttons << link_to(_('Rerun failed'), rerun_job_invocation_path(:id => job_invocation.id, :failed_only => 1),
25
- :class => 'btn btn-default',
26
- :disabled => task.sub_tasks.none? { |sub_task| task_failed?(sub_task) },
27
- :title => _('Rerun on failed hosts'))
28
- end
29
- if authorized_for(:permission => :view_foreman_tasks, :auth_object => task)
30
- buttons << link_to(_('Job Task'), foreman_tasks_task_path(task),
31
- :class => 'btn btn-default',
32
- :title => _('See the last task details'))
33
- end
34
- if authorized_for(:permission => :edit_foreman_tasks, :auth_object => task)
35
- buttons << link_to(_('Cancel Job'), cancel_foreman_tasks_task_path(task),
36
- :class => 'btn btn-danger',
37
- :title => _('Try to cancel the job'),
38
- :disabled => !task.cancellable?,
39
- :method => :post)
40
- end
41
- buttons
42
- end
43
-
44
15
  def job_invocations_buttons
45
16
  [
46
17
  documentation_button_rex('3.2ExecutingaJob'),
@@ -4,10 +4,6 @@ module RemoteExecutionHelper
4
4
  RemoteExecutionProvider.providers.map { |key, provider| [ key, _(provider.humanized_name) ] }
5
5
  end
6
6
 
7
- def template_input_types_options
8
- TemplateInput::TYPES.map { |key, name| [ _(name), key ] }
9
- end
10
-
11
7
  def job_hosts_authorizer
12
8
  @job_hosts_authorizer ||= Authorizer.new(User.current, :collection => @hosts)
13
9
  end
@@ -78,7 +74,7 @@ module RemoteExecutionHelper
78
74
  if authorized_for(hash_for_new_job_invocation_path)
79
75
  buttons << link_to(_('Rerun failed'), rerun_job_invocation_path(:id => job_invocation.id, :failed_only => 1),
80
76
  :class => 'btn btn-default',
81
- :disabled => task.sub_tasks.where(:result => %w(error warning)).count.zero?,
77
+ :disabled => job_invocation.failed_hosts.none?,
82
78
  :title => _('Rerun on failed hosts'))
83
79
  end
84
80
  if authorized_for(:permission => :view_foreman_tasks, :auth_object => task, :authorizer => task_authorizer)
@@ -188,15 +184,6 @@ module RemoteExecutionHelper
188
184
  documentation_button section, :root_url => url
189
185
  end
190
186
 
191
- def template_input_header(f, template)
192
- header = _('Template input')
193
- unless template.locked?
194
- header += ' ' + remove_child_link('x', f, {:rel => 'twipsy', :'data-title' => _('remove template input'), :'data-placement' => 'left',
195
- :class => 'fr badge badge-danger'})
196
- end
197
- header.html_safe # rubocop:disable Rails/OutputSafety
198
- end
199
-
200
187
  def description_checkbox_f(f, job_template, disabled)
201
188
  check_box_tag('description_format_override',
202
189
  job_template.generate_description_format,
@@ -225,16 +212,6 @@ module RemoteExecutionHelper
225
212
  'name using %{job_category} and %{template_name}.').html_safe # rubocop:disable Rails/OutputSafety
226
213
  end
227
214
 
228
- def advanced_switch_f(default_text, switch_text)
229
- content_tag :div, :class => 'form-group' do
230
- content_tag(:div, '', :class => 'col-md-2 control-label') +
231
- content_tag(:div, :class => 'col-md-4') do
232
- content_tag(:i, '', :class => 'fa fa-angle-right') + ' ' +
233
- link_to(default_text, '#', :class => 'advanced_fields_switch', :'data-alternative-label' => switch_text)
234
- end
235
- end
236
- end
237
-
238
215
  def load_template_from_task(template_invocation, target)
239
216
  task = template_invocation.job_invocation.sub_task_for_host(target)
240
217
  return if task.nil?
@@ -1,10 +1,10 @@
1
1
  module ForemanRemoteExecution
2
2
  module Renderer
3
3
  module Scope
4
- class Input < ::Foreman::Renderer::Scope::Base
4
+ class Input < ::Foreman::Renderer::Scope::Template
5
5
  include Foreman::Renderer::Scope::Macros::HostTemplate
6
6
 
7
- attr_reader :template, :host, :invocation, :input_values, :input_template_instance
7
+ attr_reader :template, :host, :invocation, :input_template_instance, :current_user
8
8
  delegate :input, to: :input_template_instance
9
9
 
10
10
  def render_error(message)
@@ -31,10 +31,14 @@ module ForemanRemoteExecution
31
31
  self.error_message = _('included template \'%s\' not found') % template_name
32
32
  raise error_message
33
33
  end
34
+
35
+ default_values = template.default_input_values(input_values.keys)
34
36
  if with_foreign_input_set
35
37
  input_values = foreign_input_set_values(template, input_values)
36
38
  end
37
- included_renderer = InputTemplateRenderer.new(template, host, invocation, input_values.with_indifferent_access, @preview, @templates_stack)
39
+ input_values = default_values.merge(input_values).with_indifferent_access
40
+
41
+ included_renderer = InputTemplateRenderer.new(template, host, invocation, input_values, @preview, @templates_stack)
38
42
  out = included_renderer.render
39
43
  if included_renderer.error_message
40
44
  @input_template_instance.error_message = included_renderer.error_message
@@ -48,16 +52,32 @@ module ForemanRemoteExecution
48
52
  input_set = @template.foreign_input_sets.find_by(:target_template_id => target_template)
49
53
  return overrides if input_set.nil?
50
54
 
51
- inputs_to_generate = input_set.inputs.map(&:name) - overrides.keys.map(&:to_s)
52
- included_renderer = InputTemplateRenderer.new(input_set.target_template, host, invocation, nil, @preview, @templates_stack)
55
+ inputs_to_generate = input_set.inputs.map { |i| i.name.to_s } - overrides.keys.map(&:to_s)
53
56
  input_values = inputs_to_generate.inject(HashWithIndifferentAccess.new) do |hash, input_name|
54
- hash.merge(input_name => included_renderer.input(input_name))
57
+ hash.merge(input_name.to_s => input(input_name))
58
+ end
59
+ input_values.merge(overrides).with_indifferent_access
60
+ end
61
+
62
+ def input(name)
63
+ return template_input_values[name.to_s] if template_input_values.key?(name.to_s)
64
+ input = find_by_name(template.template_inputs_with_foreign, name) # rubocop:disable Rails/DynamicFindBy
65
+ if input
66
+ @preview ? input.preview(self) : input.value(self)
67
+ else
68
+ error_message = _('input macro with name \'%s\' used, but no input with such name defined for this template') % name
69
+ raise UndefinedInput, "Rendering failed, no input with name #{name} for input macro found"
55
70
  end
56
- input_values.merge(overrides)
57
71
  end
58
72
 
59
73
  def allowed_helpers
60
- super + [:input, :render_template, :preview?, :render_error]
74
+ super + [:input, :render_template, :preview?, :render_error, :current_user]
75
+ end
76
+
77
+ private
78
+
79
+ def find_by_name(collection, name)
80
+ collection.detect { |i| i.name == name.to_s }
61
81
  end
62
82
  end
63
83
  end
@@ -4,24 +4,12 @@ module ForemanRemoteExecution
4
4
 
5
5
  included do
6
6
  # autosave => true is required so the changes of inputs are saved even if template was not changed
7
- has_many :template_inputs, :dependent => :destroy, :foreign_key => 'template_id', :autosave => true
8
7
  has_many :foreign_input_sets, :dependent => :destroy, :foreign_key => 'template_id', :autosave => true
9
8
 
10
9
  def template_inputs_with_foreign(templates_stack = [])
11
10
  self.template_inputs.to_a + foreign_input_sets.map { |set| set.inputs(templates_stack) }.flatten
12
11
  end
13
- accepts_nested_attributes_for :template_inputs, :allow_destroy => true
14
12
  accepts_nested_attributes_for :foreign_input_sets, :allow_destroy => true
15
13
  end
16
-
17
- # create or overwrite instance methods...
18
- # def instance_method_name
19
- # end
20
-
21
- # module ClassMethods
22
- # # create or overwrite class methods...
23
- # def class_method_name
24
- # end
25
- # end
26
14
  end
27
15
  end
@@ -0,0 +1,9 @@
1
+ module ForemanRemoteExecution
2
+ module TemplateInputExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :template_invocation_input_values, :dependent => :destroy
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module ForemanRemoteExecution
2
+ module TemplateOverrides
3
+ def inputs_unchanged_when_locked
4
+ inputs_changed = template_inputs.any? { |input| input.changed? || input.new_record? }
5
+ foreign_input_sets_changed = foreign_input_sets.any? { |input_set| input_set.changed? || input_set.new_record? }
6
+ if inputs_changed || foreign_input_sets_changed
7
+ errors.add(:base, _('This template is locked. Please clone it to a new template to customize.'))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -7,7 +7,7 @@ class InputTemplateRenderer
7
7
 
8
8
  delegate :logger, to: Rails
9
9
 
10
- attr_accessor :template, :host, :invocation, :input_values, :error_message, :templates_stack
10
+ attr_accessor :template, :host, :invocation, :template_input_values, :error_message, :templates_stack, :current_user
11
11
 
12
12
  # takes template object that should be rendered
13
13
  # host and template invocation arguments are optional
@@ -18,48 +18,40 @@ class InputTemplateRenderer
18
18
  @host = host
19
19
  @template = template
20
20
  @invocation = invocation
21
- @input_values = input_values
21
+ @template_input_values = input_values
22
22
  @preview = preview
23
23
  @templates_stack = templates_stack + [template]
24
24
  end
25
25
 
26
26
  def render
27
+ @template_input_values ||= values_from_invocation
27
28
  @template.validate_unique_inputs!
28
29
  source = Foreman::Renderer.get_source(
29
30
  template: template,
30
31
  host: host
31
32
  )
32
- scope = Foreman::Renderer.get_scope(
33
+ @scope = Foreman::Renderer.get_scope(
33
34
  host: host,
34
35
  klass: renderer_scope,
36
+ template_input_values: @template_input_values,
35
37
  variables: {
36
38
  host: host,
37
39
  template: template,
38
40
  preview: @preview,
39
41
  invocation: invocation,
40
- input_values: input_values,
42
+ input_values: @template_input_values,
41
43
  templates_stack: templates_stack,
42
- input_template_instance: self
44
+ input_template_instance: self,
45
+ current_user: User.current.try(:login)
43
46
  }
44
47
  )
45
- Foreman::Renderer.render(source, scope)
48
+ Foreman::Renderer.render(source, @scope)
46
49
  rescue => e
47
50
  self.error_message ||= _('error during rendering: %s') % e.message
48
51
  Foreman::Logging.exception('Error during rendering of a job template', e)
49
52
  false
50
53
  end
51
54
 
52
- def input(name)
53
- return @input_values[name.to_s] if @input_values
54
- input = find_by_name(template.template_inputs_with_foreign, name) # rubocop:disable Rails/DynamicFindBy
55
- if input
56
- @preview ? input.preview(self) : input.value(self)
57
- else
58
- error_message = _('input macro with name \'%s\' used, but no input with such name defined for this template') % name
59
- raise UndefinedInput, "Rendering failed, no input with name #{name} for input macro found"
60
- end
61
- end
62
-
63
55
  def preview
64
56
  old_preview = @preview
65
57
  @preview = true
@@ -70,6 +62,13 @@ class InputTemplateRenderer
70
62
 
71
63
  private
72
64
 
65
+ def values_from_invocation
66
+ input_values = @invocation ? Hash[@invocation.input_values.map { |iv| [iv.template_input.name, iv.value] }] : {}
67
+ default_values = template.default_input_values(input_values.keys)
68
+ result = @preview ? input_values : default_values.merge(input_values)
69
+ result.with_indifferent_access
70
+ end
71
+
73
72
  def renderer_scope
74
73
  ForemanRemoteExecution::Renderer::Scope::Input
75
74
  end
@@ -156,11 +156,16 @@ class JobInvocation < ApplicationRecord
156
156
  end
157
157
 
158
158
  def failed_host_ids
159
- failed_template_invocations.map(&:host_id)
159
+ failed_hosts.pluck(:id)
160
160
  end
161
161
 
162
162
  def failed_hosts
163
- failed_template_invocations.includes(:host).map(&:host)
163
+ base = targeting.hosts
164
+ if finished?
165
+ base.where.not(:id => not_failed_template_invocations.select(:host_id))
166
+ else
167
+ base.where(:id => failed_template_invocations.select(:host_id))
168
+ end
164
169
  end
165
170
 
166
171
  def total_hosts_count
@@ -240,7 +245,12 @@ class JobInvocation < ApplicationRecord
240
245
  private
241
246
 
242
247
  def failed_template_invocations
243
- results = TemplateInvocation::TaskResultMap.status_to_task_result(:failed)
244
- template_invocations.joins(:run_host_job_task).where("#{ForemanTasks::Task.table_name}.result" => results)
248
+ results = [:cancelled, :failed].map { |state| TemplateInvocation::TaskResultMap.status_to_task_result(state) }.flatten
249
+ template_invocations.joins(:run_host_job_task).where(ForemanTasks::Task.table_name => { :result => results })
250
+ end
251
+
252
+ def not_failed_template_invocations
253
+ results = [:cancelled, :failed].map { |state| TemplateInvocation::TaskResultMap.status_to_task_result(state) }.flatten
254
+ template_invocations.joins(:run_host_job_task).where.not(ForemanTasks::Task.table_name => { :result => results })
245
255
  end
246
256
  end
@@ -461,14 +461,10 @@ class JobInvocationComposer
461
461
  pattern_template_invocations.find { |invocation| invocation.template == job_template }
462
462
  end
463
463
 
464
- def template_invocation_input_value_for(job_template, input)
464
+ def input_value_for(input)
465
465
  invocations = pattern_template_invocations
466
466
  default = TemplateInvocationInputValue.new
467
- if (invocation = invocations.detect { |i| i.template_id == job_template.id })
468
- invocation.input_values.detect { |iv| iv.template_input_id == input.id } || default
469
- else
470
- default
471
- end
467
+ invocations.map(&:input_values).flatten.detect { |iv| iv.template_input_id == input.id } || default
472
468
  end
473
469
 
474
470
  def job_template_ids