foreman_remote_execution 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -1
  3. data/.rubocop.yml +80 -50
  4. data/.rubocop_todo.yml +113 -73
  5. data/Gemfile +4 -0
  6. data/app/controllers/api/v2/foreign_input_sets_controller.rb +3 -2
  7. data/app/controllers/api/v2/job_invocations_controller.rb +7 -6
  8. data/app/controllers/api/v2/job_templates_controller.rb +3 -2
  9. data/app/controllers/api/v2/remote_execution_features_controller.rb +3 -2
  10. data/app/controllers/api/v2/template_invocations_controller.rb +1 -1
  11. data/app/controllers/cockpit_controller.rb +1 -0
  12. data/app/controllers/concerns/foreman/controller/parameters/foreign_input_set.rb +1 -1
  13. data/app/controllers/concerns/foreman/controller/parameters/job_template.rb +4 -4
  14. data/app/controllers/job_invocations_controller.rb +10 -6
  15. data/app/controllers/job_templates_controller.rb +1 -1
  16. data/app/controllers/remote_execution_features_controller.rb +3 -2
  17. data/app/helpers/concerns/foreman_remote_execution/hosts_helper_extensions.rb +16 -5
  18. data/app/helpers/job_invocations_chart_helper.rb +11 -10
  19. data/app/helpers/job_invocations_helper.rb +13 -5
  20. data/app/helpers/remote_execution_helper.rb +43 -46
  21. data/app/lib/actions/remote_execution/run_host_job.rb +5 -6
  22. data/app/lib/actions/remote_execution/run_hosts_job.rb +2 -2
  23. data/app/lib/foreman_remote_execution/renderer/scope/input.rb +1 -0
  24. data/app/models/concerns/foreman_remote_execution/errors_flattener.rb +0 -2
  25. data/app/models/concerns/foreman_remote_execution/host_extensions.rb +3 -5
  26. data/app/models/concerns/foreman_remote_execution/nic_extensions.rb +1 -0
  27. data/app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb +1 -0
  28. data/app/models/foreign_input_set.rb +3 -2
  29. data/app/models/input_template_renderer.rb +1 -1
  30. data/app/models/job_invocation.rb +10 -12
  31. data/app/models/job_invocation_composer.rb +20 -14
  32. data/app/models/job_invocation_task_group.rb +1 -1
  33. data/app/models/job_template.rb +3 -3
  34. data/app/models/remote_execution_feature.rb +0 -2
  35. data/app/models/remote_execution_provider.rb +4 -2
  36. data/app/models/setting/remote_execution.rb +54 -56
  37. data/app/models/ssh_execution_provider.rb +2 -2
  38. data/app/models/targeting.rb +1 -0
  39. data/app/models/template_invocation.rb +2 -3
  40. data/app/views/api/v2/job_invocations/base.json.rabl +1 -1
  41. data/app/views/api/v2/job_invocations/main.json.rabl +5 -2
  42. data/app/views/job_invocations/_card_target_hosts.html.erb +12 -0
  43. data/app/views/job_invocations/_card_user_input.html.erb +1 -1
  44. data/app/views/job_invocations/_form.html.erb +3 -2
  45. data/app/views/job_invocations/_rerun_taxonomies.html.erb +22 -0
  46. data/app/views/job_invocations/_user_input.html.erb +1 -1
  47. data/app/views/job_invocations/show.html.erb +2 -0
  48. data/db/migrate/20151215114631_add_host_id_to_template_invocation.rb +1 -0
  49. data/db/migrate/20180110104432_rename_template_invocation_permission.rb +1 -0
  50. data/db/seeds.d/50-notification_blueprints.rb +4 -4
  51. data/db/seeds.d/90-bookmarks.rb +1 -0
  52. data/extra/cockpit/foreman-cockpit-session +7 -2
  53. data/lib/foreman_remote_execution/engine.rb +18 -17
  54. data/lib/foreman_remote_execution/version.rb +1 -1
  55. data/test/benchmark/run_hosts_job_benchmark.rb +1 -1
  56. data/test/factories/foreman_remote_execution_factories.rb +1 -1
  57. data/test/functional/api/v2/job_invocations_controller_test.rb +9 -9
  58. data/test/functional/api/v2/job_templates_controller_test.rb +1 -1
  59. data/test/functional/api/v2/remote_execution_features_controller_test.rb +2 -2
  60. data/test/functional/api/v2/template_invocations_controller_test.rb +4 -4
  61. data/test/functional/job_invocations_controller_test.rb +11 -11
  62. data/test/functional/job_templates_controller_test.rb +1 -1
  63. data/test/unit/actions/run_hosts_job_test.rb +8 -8
  64. data/test/unit/concerns/foreman_tasks_cleaner_extensions_test.rb +3 -3
  65. data/test/unit/concerns/host_extensions_test.rb +19 -19
  66. data/test/unit/concerns/nic_extensions_test.rb +1 -1
  67. data/test/unit/execution_task_status_mapper_test.rb +10 -10
  68. data/test/unit/input_template_renderer_test.rb +77 -77
  69. data/test/unit/job_invocation_composer_test.rb +100 -96
  70. data/test/unit/job_invocation_test.rb +29 -29
  71. data/test/unit/job_template_effective_user_test.rb +3 -3
  72. data/test/unit/job_template_test.rb +31 -31
  73. data/test/unit/remote_execution_feature_test.rb +19 -19
  74. data/test/unit/remote_execution_provider_test.rb +29 -29
  75. data/test/unit/renderer_scope_input.rb +6 -6
  76. data/test/unit/targeting_test.rb +6 -6
  77. data/test/unit/template_invocation_input_value_test.rb +3 -3
  78. metadata +3 -2
@@ -6,10 +6,10 @@ class JobInvocationsControllerTest < ActionController::TestCase
6
6
  test 'should parse inputs coming from the URL params' do
7
7
  template = FactoryBot.create(:job_template, :with_input)
8
8
  feature = FactoryBot.create(:remote_execution_feature,
9
- :job_template => template)
9
+ :job_template => template)
10
10
  params = {
11
11
  feature: feature.label,
12
- inputs: { template.template_inputs.first.name => 'foobar' }
12
+ inputs: { template.template_inputs.first.name => 'foobar' },
13
13
  }
14
14
 
15
15
  get :new, params: params, session: set_session_user
@@ -19,20 +19,20 @@ class JobInvocationsControllerTest < ActionController::TestCase
19
19
  [
20
20
  {
21
21
  'value' => 'foobar',
22
- 'template_input_id' => template.template_inputs.first.id
23
- }
22
+ 'template_input_id' => template.template_inputs.first.id,
23
+ },
24
24
  ],
25
- 'template_id' => template.id
26
- }
25
+ 'template_id' => template.id,
26
+ },
27
27
  ]
28
28
  assert_equal(template_invocation_params,
29
- assigns(:composer).params['template_invocations'])
29
+ assigns(:composer).params['template_invocations'])
30
30
  end
31
31
 
32
32
  test 'should allow no inputs' do
33
33
  template = FactoryBot.create(:job_template)
34
34
  feature = FactoryBot.create(:remote_execution_feature,
35
- :job_template => template)
35
+ :job_template => template)
36
36
  params = {
37
37
  feature: feature.label,
38
38
  }
@@ -40,10 +40,10 @@ class JobInvocationsControllerTest < ActionController::TestCase
40
40
  template_invocation_params = [
41
41
  {
42
42
  'template_id' => template.id,
43
- 'input_values' => {}
44
- }
43
+ 'input_values' => {},
44
+ },
45
45
  ]
46
46
  assert_equal(template_invocation_params,
47
- assigns(:composer).params['template_invocations'])
47
+ assigns(:composer).params['template_invocations'])
48
48
  end
49
49
  end
@@ -16,7 +16,7 @@ class JobTemplatesControllerTest < ActionController::TestCase
16
16
  post :preview, params: {
17
17
  job_template: template.to_param,
18
18
  template: '<%= @host.name %>',
19
- preview_host_id: host.id
19
+ preview_host_id: host.id,
20
20
  }, session: set_session_user
21
21
  assert_response :success
22
22
  assert_equal host.name, @response.body
@@ -54,13 +54,13 @@ module ForemanRemoteExecution
54
54
  delayed
55
55
  assert_not targeting.resolved?
56
56
  planned
57
- targeting.hosts.must_include(host)
57
+ _(targeting.hosts).must_include(host)
58
58
  end
59
59
 
60
60
  it 'resolves the hosts on static targeting in delay' do
61
61
  assert_not targeting.resolved?
62
62
  delayed
63
- targeting.hosts.must_include(host)
63
+ _(targeting.hosts).must_include(host)
64
64
  # Verify Targeting#resolve_hosts! won't be hit again
65
65
  targeting.expects(:resolve_hosts!).never
66
66
  planned
@@ -68,7 +68,7 @@ module ForemanRemoteExecution
68
68
 
69
69
  it 'resolves the hosts on static targeting in plan phase if not resolved yet' do
70
70
  planned
71
- targeting.hosts.must_include(host)
71
+ _(targeting.hosts).must_include(host)
72
72
  end
73
73
  end
74
74
 
@@ -80,16 +80,16 @@ module ForemanRemoteExecution
80
80
 
81
81
  it 'uses the BindJobInvocation middleware' do
82
82
  planned
83
- job_invocation.task_id.must_equal uuid
83
+ _(job_invocation.task_id).must_equal uuid
84
84
  end
85
85
 
86
86
  # In plan phase this is handled by #action_subject
87
87
  # which is expected in tests
88
88
  it 'sets input in delay phase when delayed' do
89
89
  job_invocation_hash = delayed.input[:job_invocation]
90
- job_invocation_hash['id'].must_equal job_invocation.id
91
- job_invocation_hash['name'].must_equal job_invocation.job_category
92
- job_invocation_hash['description'].must_equal job_invocation.description
90
+ _(job_invocation_hash['id']).must_equal job_invocation.id
91
+ _(job_invocation_hash['name']).must_equal job_invocation.job_category
92
+ _(job_invocation_hash['description']).must_equal job_invocation.description
93
93
  planned # To make the expectations happy
94
94
  end
95
95
 
@@ -100,7 +100,7 @@ module ForemanRemoteExecution
100
100
  it 'can be disabled' do
101
101
  job_invocation.expects(:concurrency_level)
102
102
  job_invocation.expects(:time_span)
103
- planned.input.key?(:concurrency_control).must_equal false
103
+ _(planned.input.key?(:concurrency_control)).must_equal false
104
104
  end
105
105
 
106
106
  it 'can limit concurrency level' do
@@ -18,11 +18,11 @@ class ForemanRemoteExecutionForemanTasksCleanerExtensionsTest < ActiveSupport::T
18
18
 
19
19
  it 'removes orphaned job invocations' do
20
20
  job = FactoryBot.create(:job_invocation, :with_task)
21
- JobInvocation.where(:id => job.id).count.must_equal 1
21
+ _(JobInvocation.where(:id => job.id).count).must_equal 1
22
22
  job.task.delete
23
23
  job.reload
24
- job.task.must_be :nil?
25
- job.task_id.wont_be :nil?
24
+ _(job.task).must_be :nil?
25
+ _(job.task_id).wont_be :nil?
26
26
  ForemanTasks::Cleaner.new(:filter => '').delete
27
27
  JobInvocation.where(:id => job.id).must_be :empty?
28
28
  end
@@ -20,32 +20,32 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
20
20
  end
21
21
 
22
22
  it 'has ssh user in the parameters' do
23
- host.host_param('remote_execution_ssh_user').must_equal Setting[:remote_execution_ssh_user]
23
+ _(host.host_param('remote_execution_ssh_user')).must_equal Setting[:remote_execution_ssh_user]
24
24
  end
25
25
 
26
26
  it 'can override ssh user' do
27
27
  host.host_parameters << FactoryBot.create(:host_parameter, :host => host, :name => 'remote_execution_ssh_user', :value => 'amy')
28
- host.host_param('remote_execution_ssh_user').must_equal 'amy'
28
+ _(host.host_param('remote_execution_ssh_user')).must_equal 'amy'
29
29
  end
30
30
 
31
31
  it 'has effective user method in the parameters' do
32
- host.host_param('remote_execution_effective_user_method').must_equal Setting[:remote_execution_effective_user_method]
32
+ _(host.host_param('remote_execution_effective_user_method')).must_equal Setting[:remote_execution_effective_user_method]
33
33
  end
34
34
 
35
35
  it 'can override effective user method' do
36
36
  host.host_parameters << FactoryBot.create(:host_parameter, :host => host, :name => 'remote_execution_effective_user_method', :value => 'su')
37
- host.host_param('remote_execution_effective_user_method').must_equal 'su'
37
+ _(host.host_param('remote_execution_effective_user_method')).must_equal 'su'
38
38
  end
39
39
 
40
40
  it 'has ssh keys in the parameters' do
41
- host.remote_execution_ssh_keys.must_include sshkey
41
+ _(host.remote_execution_ssh_keys).must_include sshkey
42
42
  end
43
43
 
44
44
  it 'merges ssh keys from host parameters and proxies' do
45
45
  key = 'ssh-rsa not-even-a-key something@somewhere.com'
46
46
  host.host_parameters << FactoryBot.create(:host_parameter, :host => host, :name => 'remote_execution_ssh_keys', :value => [key])
47
- host.host_param('remote_execution_ssh_keys').must_include key
48
- host.host_param('remote_execution_ssh_keys').must_include sshkey
47
+ _(host.host_param('remote_execution_ssh_keys')).must_include key
48
+ _(host.host_param('remote_execution_ssh_keys')).must_include sshkey
49
49
  end
50
50
 
51
51
  it 'has ssh keys in the parameters even when no user specified' do
@@ -53,7 +53,7 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
53
53
  FactoryBot.create(:smart_proxy, :ssh)
54
54
  host.interfaces.first.subnet.remote_execution_proxies.clear
55
55
  User.current = nil
56
- host.remote_execution_ssh_keys.must_include sshkey
56
+ _(host.remote_execution_ssh_keys).must_include sshkey
57
57
  end
58
58
  end
59
59
 
@@ -63,11 +63,11 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
63
63
  it 'should only have one execution interface' do
64
64
  host.interfaces << FactoryBot.build(:nic_managed)
65
65
  host.interfaces.each { |interface| interface.execution = true }
66
- host.wont_be :valid?
66
+ _(host).wont_be :valid?
67
67
  end
68
68
 
69
69
  it 'returns the execution interface' do
70
- host.execution_interface.must_be_kind_of Nic::Managed
70
+ _(host.execution_interface).must_be_kind_of Nic::Managed
71
71
  end
72
72
  end
73
73
 
@@ -86,16 +86,16 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
86
86
 
87
87
  it 'finds hosts for job_invocation.id' do
88
88
  found_ids = Host.search_for("job_invocation.id = #{job.id}").map(&:id).sort
89
- found_ids.must_equal job.template_invocations_host_ids.sort
89
+ _(found_ids).must_equal job.template_invocations_host_ids.sort
90
90
  end
91
91
 
92
92
  it 'finds hosts by job_invocation.result' do
93
93
  success, failed = job.template_invocations
94
94
  .partition { |template| template.run_host_job_task.result == 'success' }
95
95
  found_ids = Host.search_for('job_invocation.result = success').map(&:id)
96
- found_ids.must_equal success.map(&:host_id)
96
+ _(found_ids).must_equal success.map(&:host_id)
97
97
  found_ids = Host.search_for('job_invocation.result = failed').map(&:id)
98
- found_ids.must_equal failed.map(&:host_id)
98
+ _(found_ids).must_equal failed.map(&:host_id)
99
99
  end
100
100
 
101
101
  it 'finds hosts by job_invocation.id and job_invocation.result' do
@@ -103,17 +103,17 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
103
103
  job
104
104
  job2
105
105
 
106
- Host.search_for("job_invocation.id = #{job.id}").count.must_equal 2
107
- Host.search_for("job_invocation.id = #{job2.id}").count.must_equal 2
108
- Host.search_for('job_invocation.result = success').count.must_equal 2
109
- Host.search_for('job_invocation.result = failed').count.must_equal 2
106
+ _(Host.search_for("job_invocation.id = #{job.id}").count).must_equal 2
107
+ _(Host.search_for("job_invocation.id = #{job2.id}").count).must_equal 2
108
+ _(Host.search_for('job_invocation.result = success').count).must_equal 2
109
+ _(Host.search_for('job_invocation.result = failed').count).must_equal 2
110
110
 
111
111
  success, failed = job.template_invocations
112
112
  .partition { |template| template.run_host_job_task.result == 'success' }
113
113
  found_ids = Host.search_for("job_invocation.id = #{job.id} AND job_invocation.result = success").map(&:id)
114
- found_ids.must_equal success.map(&:host_id)
114
+ _(found_ids).must_equal success.map(&:host_id)
115
115
  found_ids = Host.search_for("job_invocation.id = #{job.id} AND job_invocation.result = failed").map(&:id)
116
- found_ids.must_equal failed.map(&:host_id)
116
+ _(found_ids).must_equal failed.map(&:host_id)
117
117
  end
118
118
  end
119
119
 
@@ -4,6 +4,6 @@ class ForemanRemoteExecutionNicExtensionsTest < ActiveSupport::TestCase
4
4
  let(:host) { FactoryBot.create(:host) }
5
5
 
6
6
  it 'sets the first primary interface as the execution interface' do
7
- host.execution_interface.must_equal host.interfaces.first
7
+ _(host.execution_interface).must_equal host.interfaces.first
8
8
  end
9
9
  end
@@ -5,11 +5,11 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
5
5
  let(:subject) { HostStatus::ExecutionStatus::ExecutionTaskStatusMapper }
6
6
 
7
7
  it 'accepts status number as well as string representation' do
8
- subject.sql_conditions_for(HostStatus::ExecutionStatus::ERROR).must_equal subject.sql_conditions_for('failed')
8
+ _(subject.sql_conditions_for(HostStatus::ExecutionStatus::ERROR)).must_equal subject.sql_conditions_for('failed')
9
9
  end
10
10
 
11
11
  it 'does not find any task for unknown state' do
12
- subject.sql_conditions_for(-1).must_equal [ '1 = 0' ]
12
+ _(subject.sql_conditions_for(-1)).must_equal [ '1 = 0' ]
13
13
  end
14
14
  end
15
15
 
@@ -22,12 +22,12 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
22
22
  describe 'is queued' do
23
23
  context 'when there is no task' do
24
24
  before { subject.task = nil }
25
- specify { subject.status.must_equal HostStatus::ExecutionStatus::QUEUED }
25
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::QUEUED }
26
26
  end
27
27
 
28
28
  context 'when the task is scheduled in future' do
29
29
  before { subject.task.state = 'scheduled' }
30
- specify { subject.status.must_equal HostStatus::ExecutionStatus::QUEUED }
30
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::QUEUED }
31
31
  end
32
32
  end
33
33
 
@@ -37,19 +37,19 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
37
37
  describe 'is succeeded' do
38
38
  context 'without error' do
39
39
  before { subject.task.result = 'success' }
40
- specify { subject.status.must_equal HostStatus::ExecutionStatus::OK }
40
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::OK }
41
41
  end
42
42
  end
43
43
 
44
44
  describe 'is failed' do
45
45
  context 'with error' do
46
46
  before { subject.task.result = 'error' }
47
- specify { subject.status.must_equal HostStatus::ExecutionStatus::ERROR }
47
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::ERROR }
48
48
  end
49
49
 
50
50
  context 'without error but just with warning (sub task failed)' do
51
51
  before { subject.task.result = 'warning' }
52
- specify { subject.status.must_equal HostStatus::ExecutionStatus::ERROR }
52
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::ERROR }
53
53
  end
54
54
  end
55
55
  end
@@ -58,7 +58,7 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
58
58
  before { subject.task.state = 'running' }
59
59
 
60
60
  describe 'is pending' do
61
- specify { subject.status.must_equal HostStatus::ExecutionStatus::RUNNING }
61
+ specify { _(subject.status).must_equal HostStatus::ExecutionStatus::RUNNING }
62
62
  end
63
63
  end
64
64
  end
@@ -73,7 +73,7 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
73
73
  end
74
74
 
75
75
  it 'returns ok label' do
76
- subject.must_equal HostStatus::ExecutionStatus::STATUS_NAMES[HostStatus::ExecutionStatus::OK]
76
+ _(subject).must_equal HostStatus::ExecutionStatus::STATUS_NAMES[HostStatus::ExecutionStatus::OK]
77
77
  end
78
78
  end
79
79
 
@@ -84,7 +84,7 @@ class ExecutionTaskStatusMapperTest < ActiveSupport::TestCase
84
84
  end
85
85
 
86
86
  it 'returns failed label' do
87
- subject.must_equal HostStatus::ExecutionStatus::STATUS_NAMES[HostStatus::ExecutionStatus::ERROR]
87
+ _(subject).must_equal HostStatus::ExecutionStatus::STATUS_NAMES[HostStatus::ExecutionStatus::ERROR]
88
88
  end
89
89
  end
90
90
  end
@@ -7,17 +7,17 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
7
7
  let(:renderer) { InputTemplateRenderer.new(FactoryBot.build(:job_template, :template => 'id <%= preview? %>')) }
8
8
 
9
9
  it 'should render the content' do
10
- renderer.render.must_equal 'id false'
10
+ _(renderer.render).must_equal 'id false'
11
11
  end
12
12
 
13
13
  it 'should render preview' do
14
- renderer.preview.must_equal 'id true'
14
+ _(renderer.preview).must_equal 'id true'
15
15
  end
16
16
 
17
17
  it 'should allow accessing current_user' do
18
18
  setup_user(:view_job_templates)
19
19
  renderer = InputTemplateRenderer.new(FactoryBot.build(:job_template, :template => "They call me '<%= current_user %>'"))
20
- renderer.preview.must_equal "They call me '#{User.current.login}'"
20
+ _(renderer.preview).must_equal "They call me '#{User.current.login}'"
21
21
  end
22
22
  end
23
23
 
@@ -28,23 +28,23 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
28
28
  context 'but without input defined' do
29
29
  describe 'rendering' do
30
30
  let(:result) { renderer.render }
31
- it { result.must_equal false }
31
+ it { _(result).must_equal false }
32
32
 
33
33
  it 'registers an error' do
34
34
  result # let is lazy
35
- renderer.error_message.wont_be_nil
36
- renderer.error_message.wont_be_empty
35
+ _(renderer.error_message).wont_be_nil
36
+ _(renderer.error_message).wont_be_empty
37
37
  end
38
38
  end
39
39
 
40
40
  describe 'preview' do
41
41
  let(:result) { renderer.preview }
42
- it { result.must_equal false }
42
+ it { _(result).must_equal false }
43
43
 
44
44
  it 'registers an error' do
45
45
  result # let is lazy
46
- renderer.error_message.wont_be_nil
47
- renderer.error_message.wont_be_empty
46
+ _(renderer.error_message).wont_be_nil
47
+ _(renderer.error_message).wont_be_empty
48
48
  end
49
49
  end
50
50
  end
@@ -62,41 +62,41 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
62
62
 
63
63
  describe 'rendering' do
64
64
  it 'can preview' do
65
- renderer.preview.must_equal 'service restart $USER_INPUT[service_name]'
65
+ _(renderer.preview).must_equal 'service restart $USER_INPUT[service_name]'
66
66
  end
67
67
 
68
68
  context 'with invocation specified and a required input' do
69
69
  before do
70
- template.template_inputs.first.update_attributes(:required => true)
70
+ template.template_inputs.first.update(:required => true)
71
71
  template_invocation.reload
72
72
  renderer.invocation = template_invocation
73
73
  end
74
74
 
75
75
  it 'cannot render the content' do
76
76
  assert_not result
77
- renderer.error_message.wont_be_nil
78
- renderer.error_message.wont_be_empty
77
+ _(renderer.error_message).wont_be_nil
78
+ _(renderer.error_message).wont_be_empty
79
79
  end
80
80
  end
81
81
 
82
82
  context 'with invocation specified' do
83
83
  before do
84
84
  FactoryBot.create(:template_invocation_input_value,
85
- :template_invocation => template_invocation,
86
- :template_input => template.template_inputs.first,
87
- :value => 'foreman')
85
+ :template_invocation => template_invocation,
86
+ :template_input => template.template_inputs.first,
87
+ :value => 'foreman')
88
88
  template_invocation.reload # need to get input_values findable
89
89
  renderer.invocation = template_invocation
90
90
  end
91
91
 
92
92
  it 'can render with job invocation with corresponding value' do
93
- renderer.render.must_equal 'service restart foreman'
93
+ _(renderer.render).must_equal 'service restart foreman'
94
94
  end
95
95
  end
96
96
 
97
97
  it 'renders even without an input value' do
98
98
  renderer.invocation = template_invocation
99
- renderer.render.must_equal 'service restart '
99
+ _(renderer.render).must_equal 'service restart '
100
100
  end
101
101
 
102
102
  describe 'with circular reference' do
@@ -126,7 +126,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
126
126
  renderer.invocation = FactoryBot.build(:template_invocation, :template => template_without_inputs)
127
127
  renderer.template = template_without_inputs
128
128
  assert_not renderer.render
129
- renderer.error_message.must_include 'Recursive rendering of templates detected'
129
+ _(renderer.error_message).must_include 'Recursive rendering of templates detected'
130
130
  end
131
131
 
132
132
  it 'handles circular references in inputs' do
@@ -161,7 +161,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
161
161
 
162
162
  let(:template) do
163
163
  FactoryBot.create(:job_template,
164
- :template => '<%= render_template("package action", { :action => "install" }, { :with_foreign_input_set => true }) %>').tap do |template|
164
+ :template => '<%= render_template("package action", { :action => "install" }, { :with_foreign_input_set => true }) %>').tap do |template|
165
165
  template.foreign_input_sets << FactoryBot.build(:foreign_input_set, :target_template => package_template, :include_all => true, :exclude => 'action')
166
166
  end
167
167
  end
@@ -189,13 +189,13 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
189
189
  let(:template_2) do
190
190
  FactoryBot.create(:job_template, :template => '<%= render_template("package action", "action" => "install") %>').tap do |template|
191
191
  template.foreign_input_sets << FactoryBot.build(:foreign_input_set,
192
- :target_template => package_template, :include_all => true, :include => '', :exclude => '')
192
+ :target_template => package_template, :include_all => true, :include => '', :exclude => '')
193
193
  end
194
194
  end
195
195
 
196
196
  it 'includes all inputs from the imported template' do
197
- template.template_inputs_with_foreign.map(&:name).sort.must_equal ['action', 'debug', 'package']
198
- template_2.template_inputs_with_foreign.map(&:name).sort.must_equal ['action', 'debug', 'package']
197
+ _(template.template_inputs_with_foreign.map(&:name).sort).must_equal ['action', 'debug', 'package']
198
+ _(template_2.template_inputs_with_foreign.map(&:name).sort).must_equal ['action', 'debug', 'package']
199
199
  end
200
200
  end
201
201
 
@@ -207,7 +207,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
207
207
  end
208
208
 
209
209
  it 'includes all inputs from the imported template except the listed once' do
210
- template.template_inputs_with_foreign.map(&:name).sort.must_equal ['package']
210
+ _(template.template_inputs_with_foreign.map(&:name).sort).must_equal ['package']
211
211
  end
212
212
  end
213
213
 
@@ -220,7 +220,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
220
220
  end
221
221
 
222
222
  it 'includes all inputs from the imported template' do
223
- template.template_inputs_with_foreign.map(&:name).sort.must_equal ['package']
223
+ _(template.template_inputs_with_foreign.map(&:name).sort).must_equal ['package']
224
224
  end
225
225
  end
226
226
  end
@@ -228,24 +228,24 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
228
228
  context 'with invocation specified' do
229
229
  before do
230
230
  FactoryBot.create(:template_invocation_input_value,
231
- :template_invocation => template_invocation,
232
- :template_input => template.template_inputs_with_foreign.find { |input| input.name == 'package' },
233
- :value => 'zsh')
231
+ :template_invocation => template_invocation,
232
+ :template_input => template.template_inputs_with_foreign.find { |input| input.name == 'package' },
233
+ :value => 'zsh')
234
234
  renderer.invocation = template_invocation
235
235
  renderer.invocation.reload
236
236
  end
237
237
 
238
238
  it 'can render with job invocation with corresponding value' do
239
239
  rendered = renderer.render
240
- renderer.error_message.must_be_nil
241
- rendered.must_equal 'yum -y install zsh'
240
+ _(renderer.error_message).must_be_nil
241
+ _(rendered).must_equal 'yum -y install zsh'
242
242
  end
243
243
  end
244
244
 
245
245
  context 'with explicitly specifying inputs' do
246
246
  let(:template) do
247
247
  FactoryBot.create(:job_template,
248
- :template => '<%= render_template("package action", {"action" => "install", :package => "zsh"}) %>')
248
+ :template => '<%= render_template("package action", {"action" => "install", :package => "zsh"}) %>')
249
249
  end
250
250
 
251
251
  before do
@@ -255,16 +255,16 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
255
255
 
256
256
  it 'can render with job invocation with corresponding value' do
257
257
  rendered = renderer.render
258
- renderer.error_message.must_be_nil
259
- rendered.must_equal 'yum -y install zsh'
258
+ _(renderer.error_message).must_be_nil
259
+ _(rendered).must_equal 'yum -y install zsh'
260
260
  end
261
261
  end
262
262
 
263
263
  it 'renders even without an input value' do
264
264
  renderer.invocation = template_invocation
265
265
  rendered = renderer.render
266
- renderer.error_message.must_be_nil
267
- rendered.must_equal 'yum -y install '
266
+ _(renderer.error_message).must_be_nil
267
+ _(rendered).must_equal 'yum -y install '
268
268
  end
269
269
  end
270
270
 
@@ -275,9 +275,9 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
275
275
  let(:required) { false }
276
276
  let(:input) do
277
277
  FactoryBot.create(:template_invocation_input_value,
278
- :template_invocation => template_invocation,
279
- :template_input => template.template_inputs.first,
280
- :value => 'foreman')
278
+ :template_invocation => template_invocation,
279
+ :template_input => template.template_inputs.first,
280
+ :value => 'foreman')
281
281
  end
282
282
 
283
283
  before do
@@ -291,7 +291,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
291
291
  context 'with a valid input defined' do
292
292
  context 'with an optional input' do
293
293
  it 'can render with job invocation with corresponding value' do
294
- result.must_equal 'service restart foreman'
294
+ _(result).must_equal 'service restart foreman'
295
295
  end
296
296
  end
297
297
 
@@ -299,7 +299,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
299
299
  let(:required) { true }
300
300
 
301
301
  it 'renders the template when the input is provided' do
302
- result.must_equal 'service restart foreman'
302
+ _(result).must_equal 'service restart foreman'
303
303
  end
304
304
  end
305
305
  end
@@ -309,7 +309,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
309
309
 
310
310
  context 'with optional input' do
311
311
  it 'renders the template' do
312
- result.must_equal 'service restart '
312
+ _(result).must_equal 'service restart '
313
313
  end
314
314
  end
315
315
 
@@ -340,8 +340,8 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
340
340
 
341
341
  it 'registers an error' do
342
342
  result # let is lazy
343
- renderer.error_message.wont_be_nil
344
- renderer.error_message.wont_be_empty
343
+ _(renderer.error_message).wont_be_nil
344
+ _(renderer.error_message).wont_be_empty
345
345
  end
346
346
 
347
347
  context 'with host specified' do
@@ -354,14 +354,14 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
354
354
 
355
355
  it 'registers an error' do
356
356
  result # let is lazy
357
- renderer.error_message.wont_be_nil
358
- renderer.error_message.wont_be_empty
357
+ _(renderer.error_message).wont_be_nil
358
+ _(renderer.error_message).wont_be_empty
359
359
  end
360
360
  end
361
361
 
362
362
  describe 'preview' do
363
363
  it 'should render preview' do
364
- renderer.preview.must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
364
+ _(renderer.preview).must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
365
365
  end
366
366
  end
367
367
 
@@ -376,14 +376,14 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
376
376
 
377
377
  it 'registers an error' do
378
378
  result # let is lazy
379
- renderer.error_message.wont_be_nil
380
- renderer.error_message.wont_be_empty
379
+ _(renderer.error_message).wont_be_nil
380
+ _(renderer.error_message).wont_be_empty
381
381
  end
382
382
  end
383
383
 
384
384
  describe 'preview' do
385
385
  it 'should render preview' do
386
- renderer.preview.must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
386
+ _(renderer.preview).must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
387
387
  end
388
388
  end
389
389
 
@@ -393,7 +393,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
393
393
  let(:result) { renderer.render }
394
394
 
395
395
  it 'can render with job invocation with corresponding value' do
396
- result.must_equal 'echo banner > /etc/issue'
396
+ _(result).must_equal 'echo banner > /etc/issue'
397
397
  end
398
398
  end
399
399
  end
@@ -402,7 +402,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
402
402
 
403
403
  describe 'preview' do
404
404
  it 'should render preview' do
405
- renderer.preview.must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
405
+ _(renderer.preview).must_equal 'echo $FACT_INPUT[issue] > /etc/issue'
406
406
  end
407
407
 
408
408
  context 'with host specified' do
@@ -416,7 +416,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
416
416
  let(:result) { renderer.render }
417
417
 
418
418
  it 'uses the value even in preview' do
419
- result.must_equal 'echo banner > /etc/issue'
419
+ _(result).must_equal 'echo banner > /etc/issue'
420
420
  end
421
421
  end
422
422
  end
@@ -438,8 +438,8 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
438
438
 
439
439
  it 'registers an error' do
440
440
  result # let is lazy
441
- renderer.error_message.wont_be_nil
442
- renderer.error_message.wont_be_empty
441
+ _(renderer.error_message).wont_be_nil
442
+ _(renderer.error_message).wont_be_empty
443
443
  end
444
444
 
445
445
  context 'with host specified' do
@@ -456,14 +456,14 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
456
456
 
457
457
  it 'registers an error' do
458
458
  result # let is lazy
459
- renderer.error_message.wont_be_nil
460
- renderer.error_message.wont_be_empty
459
+ _(renderer.error_message).wont_be_nil
460
+ _(renderer.error_message).wont_be_empty
461
461
  end
462
462
  end
463
463
 
464
464
  describe 'preview' do
465
465
  it 'should render preview' do
466
- renderer.preview.must_equal 'echo $VARIABLE_INPUT[client_key] > /etc/chef/client.pem'
466
+ _(renderer.preview).must_equal 'echo $VARIABLE_INPUT[client_key] > /etc/chef/client.pem'
467
467
  end
468
468
  end
469
469
 
@@ -475,7 +475,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
475
475
  it 'renders the value from host parameter' do
476
476
  parameter
477
477
  renderer.host.reload
478
- result.must_equal 'echo RSA KEY > /etc/chef/client.pem'
478
+ _(result).must_equal 'echo RSA KEY > /etc/chef/client.pem'
479
479
  end
480
480
  end
481
481
 
@@ -483,7 +483,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
483
483
  it 'should render preview' do
484
484
  parameter
485
485
  renderer.host.reload
486
- renderer.preview.must_equal 'echo RSA KEY > /etc/chef/client.pem'
486
+ _(renderer.preview).must_equal 'echo RSA KEY > /etc/chef/client.pem'
487
487
  end
488
488
  end
489
489
  end
@@ -491,7 +491,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
491
491
 
492
492
  describe 'preview' do
493
493
  it 'should render preview' do
494
- renderer.preview.must_equal 'echo $VARIABLE_INPUT[client_key] > /etc/chef/client.pem'
494
+ _(renderer.preview).must_equal 'echo $VARIABLE_INPUT[client_key] > /etc/chef/client.pem'
495
495
  end
496
496
  end
497
497
  end
@@ -505,10 +505,10 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
505
505
  context 'with matching input defined' do
506
506
  before do
507
507
  renderer.template.template_inputs<< FactoryBot.build(:template_input,
508
- :name => 'nginx_version',
509
- :input_type => 'puppet_parameter',
510
- :puppet_parameter_name => 'version',
511
- :puppet_class_name => 'nginx')
508
+ :name => 'nginx_version',
509
+ :input_type => 'puppet_parameter',
510
+ :puppet_parameter_name => 'version',
511
+ :puppet_class_name => 'nginx')
512
512
  end
513
513
  let(:result) { renderer.render }
514
514
 
@@ -519,8 +519,8 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
519
519
 
520
520
  it 'registers an error' do
521
521
  result # let is lazy
522
- renderer.error_message.wont_be_nil
523
- renderer.error_message.wont_be_empty
522
+ _(renderer.error_message).wont_be_nil
523
+ _(renderer.error_message).wont_be_empty
524
524
  end
525
525
 
526
526
  context 'with host specified' do
@@ -534,14 +534,14 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
534
534
 
535
535
  it 'registers an error' do
536
536
  result # let is lazy
537
- renderer.error_message.wont_be_nil
538
- renderer.error_message.wont_be_empty
537
+ _(renderer.error_message).wont_be_nil
538
+ _(renderer.error_message).wont_be_empty
539
539
  end
540
540
  end
541
541
 
542
542
  describe 'preview' do
543
543
  it 'should render preview' do
544
- renderer.preview.must_equal 'echo "This is WebServer with nginx $PUPPET_PARAMETER_INPUT[nginx_version]" > /etc/motd'
544
+ _(renderer.preview).must_equal 'echo "This is WebServer with nginx $PUPPET_PARAMETER_INPUT[nginx_version]" > /etc/motd'
545
545
  end
546
546
  end
547
547
 
@@ -553,24 +553,24 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
553
553
  end
554
554
  let(:lookup_key) do
555
555
  FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param,
556
- :key => 'version',
557
- :puppetclass => puppet_class,
558
- :path => 'fqdn',
559
- :override => true,
560
- :overrides => {"fqdn=#{renderer.host.fqdn}" => '1.4.7'})
556
+ :key => 'version',
557
+ :puppetclass => puppet_class,
558
+ :path => 'fqdn',
559
+ :override => true,
560
+ :overrides => {"fqdn=#{renderer.host.fqdn}" => '1.4.7'})
561
561
  end
562
562
 
563
563
  describe 'rendering' do
564
564
  it 'renders the value from puppet parameter' do
565
565
  lookup_key
566
- result.must_equal 'echo "This is WebServer with nginx 1.4.7" > /etc/motd'
566
+ _(result).must_equal 'echo "This is WebServer with nginx 1.4.7" > /etc/motd'
567
567
  end
568
568
  end
569
569
 
570
570
  describe 'preview' do
571
571
  it 'should render preview' do
572
572
  lookup_key
573
- renderer.preview.must_equal 'echo "This is WebServer with nginx 1.4.7" > /etc/motd'
573
+ _(renderer.preview).must_equal 'echo "This is WebServer with nginx 1.4.7" > /etc/motd'
574
574
  end
575
575
  end
576
576
  end
@@ -578,7 +578,7 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
578
578
 
579
579
  describe 'preview' do
580
580
  it 'should render preview' do
581
- renderer.preview.must_equal 'echo "This is WebServer with nginx $PUPPET_PARAMETER_INPUT[nginx_version]" > /etc/motd'
581
+ _(renderer.preview).must_equal 'echo "This is WebServer with nginx $PUPPET_PARAMETER_INPUT[nginx_version]" > /etc/motd'
582
582
  end
583
583
  end
584
584
  end