foreman_remote_execution 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -5
  3. data/.rubocop_todo.yml +90 -92
  4. data/app/assets/javascripts/job_templates.js +10 -0
  5. data/app/assets/stylesheets/modal_window.css.scss +4 -0
  6. data/app/controllers/api/v2/job_templates_controller.rb +22 -1
  7. data/app/controllers/job_templates_controller.rb +21 -1
  8. data/app/helpers/concerns/foreman_remote_execution/job_templates_extensions.rb +3 -2
  9. data/app/helpers/remote_execution_helper.rb +5 -3
  10. data/app/lib/actions/middleware/bind_job_invocation.rb +1 -1
  11. data/app/lib/actions/remote_execution/run_host_job.rb +15 -8
  12. data/app/lib/actions/remote_execution/run_hosts_job.rb +2 -1
  13. data/app/models/concerns/foreman_remote_execution/exportable.rb +71 -0
  14. data/app/models/foreign_input_set.rb +3 -0
  15. data/app/models/job_invocation.rb +6 -4
  16. data/app/models/job_invocation_composer.rb +1 -1
  17. data/app/models/job_template.rb +22 -6
  18. data/app/models/template_input.rb +4 -0
  19. data/app/models/template_invocation.rb +1 -1
  20. data/app/services/proxy_load_balancer.rb +3 -0
  21. data/app/views/job_invocations/_preview_hosts_modal.html.erb +3 -1
  22. data/app/views/job_templates/_import_job_template_modal.html.erb +20 -0
  23. data/app/views/job_templates/index.html.erb +5 -1
  24. data/config/routes.rb +4 -0
  25. data/lib/foreman_remote_execution/engine.rb +4 -4
  26. data/lib/foreman_remote_execution/version.rb +1 -1
  27. data/locale/Makefile +18 -19
  28. data/locale/action_names.rb +2 -2
  29. data/locale/de/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  30. data/locale/de/foreman_remote_execution.po +823 -0
  31. data/locale/en/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  32. data/locale/en/foreman_remote_execution.po +332 -283
  33. data/locale/en_GB/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  34. data/locale/en_GB/foreman_remote_execution.po +824 -0
  35. data/locale/foreman_remote_execution.pot +277 -131
  36. data/locale/fr/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  37. data/locale/fr/foreman_remote_execution.po +823 -0
  38. data/test/functional/api/v2/job_templates_controller_test.rb +15 -0
  39. data/test/unit/actions/run_host_job_test.rb +50 -0
  40. data/test/unit/concerns/exportable_test.rb +88 -0
  41. data/test/unit/job_invocation_composer_test.rb +1 -1
  42. data/test/unit/job_invocation_test.rb +3 -6
  43. data/test/unit/job_template_test.rb +34 -2
  44. data/test/unit/proxy_load_balancer_test.rb +8 -6
  45. data/test/unit/template_input_test.rb +15 -0
  46. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42b3d239b3161263e650d3d6d6dba548e732145b
4
- data.tar.gz: aeadb8c264c040867f45d224fc87724f056976db
3
+ metadata.gz: 9b67393920eea010c57e8994ea08e08b39ac660d
4
+ data.tar.gz: 5d99f91e886a5c512faced47136702fb4660977c
5
5
  SHA512:
6
- metadata.gz: 4b507b186ef9ba52d7612e2843fed86c268bb9dda737e6c8e029a7c9a1046b45caf5495d7e65ed35ce4f9e4a1b8fc2fc9c33ae9763684b5a77e60b61fb69a9ae
7
- data.tar.gz: 0b7dbd1acb92629cf67f3a4a80f87ba7280f832196efaf471f60d50b278d9823e6da9907991b25552304bf78608305c84c048162d9ae56df8bbb68da9caa2078
6
+ metadata.gz: f72a2ec071b11e5de82585ecaf63371d267215074d1e246bf2d2b29da086d09075b243a798689b1b54a92adf748726b753c7e3c6dd0c4a2a5c2ae795a5dcae9c
7
+ data.tar.gz: 7290328eb26ea95a4fb882a6f8d1258dc51052e289098105c6e261be6203cb06d8254c2eb223640ec30fa8cc6b1359b6dc99f18ab9f5468a7b642c7b209e00f3
data/.rubocop.yml CHANGED
@@ -6,10 +6,8 @@ AllCops:
6
6
  Exclude:
7
7
  - 'doc/plugins/**'
8
8
 
9
- # TODO: uncomment when on rubocop 0.35.1
10
- #Rails/Date:
11
- #Exclude:
12
- #- foreman_remote_execution.gemspec
9
+ Rails/Date:
10
+ Enabled: false
13
11
 
14
12
  # Don't enforce documentation
15
13
  Style/Documentation:
@@ -32,7 +30,7 @@ Style/RedundantSelf:
32
30
  Enabled: false
33
31
 
34
32
  Metrics/ClassLength:
35
- Max: 200
33
+ Max: 500
36
34
 
37
35
  Style/FileName:
38
36
  Exclude:
data/.rubocop_todo.yml CHANGED
@@ -1,26 +1,20 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-07-07 10:58:32 -0400 using RuboCop version 0.28.0.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-04-25 14:06:56 -0400 using RuboCop version 0.35.1.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
6
7
  # versions of RuboCop, may require this file to be generated again.
7
8
 
8
- # Offense count: 1
9
- Lint/AmbiguousRegexpLiteral:
10
- Enabled: false
11
-
12
- # Offense count: 1
13
- # Configuration parameters: AllowSafeAssignment.
14
- Lint/AssignmentInCondition:
15
- Enabled: false
16
-
17
- # Offense count: 1
9
+ # Offense count: 7
18
10
  # Cop supports --auto-correct.
11
+ # Configuration parameters: IgnoreEmptyBlocks.
19
12
  Lint/UnusedBlockArgument:
20
13
  Enabled: false
21
14
 
22
- # Offense count: 3
15
+ # Offense count: 11
23
16
  # Cop supports --auto-correct.
17
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
24
18
  Lint/UnusedMethodArgument:
25
19
  Enabled: false
26
20
 
@@ -28,78 +22,98 @@ Lint/UnusedMethodArgument:
28
22
  Lint/UselessAssignment:
29
23
  Enabled: false
30
24
 
31
- # Offense count: 2
25
+ # Offense count: 35
32
26
  Metrics/AbcSize:
33
27
  Max: 42
34
28
 
35
- # Offense count: 46
29
+ # Offense count: 3
30
+ Metrics/CyclomaticComplexity:
31
+ Max: 8
32
+
33
+ # Offense count: 775
36
34
  # Configuration parameters: AllowURI, URISchemes.
37
35
  Metrics/LineLength:
38
- Max: 171
36
+ Max: 204
39
37
 
40
- # Offense count: 1
38
+ # Offense count: 3
39
+ Metrics/PerceivedComplexity:
40
+ Max: 8
41
+
42
+ # Offense count: 2
41
43
  # Configuration parameters: Include.
42
44
  Rails/DefaultScope:
43
- Enabled: false
44
-
45
- # Offense count: 1
46
- # Cop supports --auto-correct.
47
- # Configuration parameters: EnforcedStyle, SupportedStyles.
48
- Style/AndOr:
49
- Enabled: false
45
+ Exclude:
46
+ - 'app/models/job_invocation.rb'
47
+ - 'app/models/job_template.rb'
50
48
 
51
49
  # Offense count: 2
52
- # Cop supports --auto-correct.
53
50
  # Configuration parameters: EnforcedStyle, SupportedStyles.
54
- Style/BarePercentLiterals:
55
- Enabled: false
51
+ Rails/TimeZone:
52
+ Exclude:
53
+ - 'app/models/job_invocation_composer.rb'
54
+ - 'test/functional/api/v2/job_invocations_controller_test.rb'
56
55
 
57
- # Offense count: 1
56
+ # Offense count: 15
57
+ # Cop supports --auto-correct.
58
58
  # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
59
59
  Style/CaseIndentation:
60
60
  Enabled: false
61
61
 
62
62
  # Offense count: 4
63
63
  # Cop supports --auto-correct.
64
- Style/ColonMethodCall:
65
- Enabled: false
66
-
67
- # Offense count: 1
68
64
  # Configuration parameters: Keywords.
69
65
  Style/CommentAnnotation:
70
66
  Enabled: false
71
67
 
72
68
  # Offense count: 1
69
+ Style/DoubleNegation:
70
+ Exclude:
71
+ - 'app/models/input_template_renderer.rb'
72
+
73
+ # Offense count: 5
73
74
  # Cop supports --auto-correct.
74
75
  Style/EmptyLines:
75
76
  Enabled: false
76
77
 
77
- # Offense count: 1
78
+ # Offense count: 12
78
79
  # Cop supports --auto-correct.
79
80
  # Configuration parameters: EnforcedStyle, SupportedStyles.
80
81
  Style/EmptyLinesAroundBlockBody:
81
82
  Enabled: false
82
83
 
83
- # Offense count: 7
84
+ # Offense count: 19
84
85
  # Cop supports --auto-correct.
85
86
  # Configuration parameters: EnforcedStyle, SupportedStyles.
86
87
  Style/EmptyLinesAroundClassBody:
87
88
  Enabled: false
88
89
 
89
- # Offense count: 5
90
+ # Offense count: 3
90
91
  # Cop supports --auto-correct.
91
92
  # Configuration parameters: EnforcedStyle, SupportedStyles.
92
93
  Style/EmptyLinesAroundModuleBody:
93
94
  Enabled: false
94
95
 
95
- # Offense count: 1
96
+ # Offense count: 2
97
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
98
+ Style/FormatString:
99
+ Exclude:
100
+ - 'app/controllers/job_templates_controller.rb'
101
+ - 'app/lib/actions/remote_execution/run_hosts_job.rb'
102
+
103
+ # Offense count: 9
96
104
  # Configuration parameters: MinBodyLength.
97
105
  Style/GuardClause:
98
- Enabled: false
106
+ Exclude:
107
+ - 'app/controllers/api/v2/template_inputs_controller.rb'
108
+ - 'app/models/concerns/foreman_remote_execution/errors_flattener.rb'
109
+ - 'app/models/concerns/foreman_remote_execution/nic_extensions.rb'
110
+ - 'app/models/job_template.rb'
111
+ - 'app/models/targeting.rb'
112
+ - 'app/models/template_invocation.rb'
99
113
 
100
- # Offense count: 36
114
+ # Offense count: 1299
101
115
  # Cop supports --auto-correct.
102
- # Configuration parameters: EnforcedStyle, SupportedStyles.
116
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
103
117
  Style/HashSyntax:
104
118
  Enabled: false
105
119
 
@@ -107,9 +121,10 @@ Style/HashSyntax:
107
121
  # Cop supports --auto-correct.
108
122
  # Configuration parameters: Width.
109
123
  Style/IndentationWidth:
110
- Enabled: false
124
+ Exclude:
125
+ - 'app/models/template_invocation.rb'
111
126
 
112
- # Offense count: 2
127
+ # Offense count: 12
113
128
  # Cop supports --auto-correct.
114
129
  Style/LineEndConcatenation:
115
130
  Enabled: false
@@ -117,18 +132,8 @@ Style/LineEndConcatenation:
117
132
  # Offense count: 1
118
133
  # Cop supports --auto-correct.
119
134
  Style/MethodCallParentheses:
120
- Enabled: false
121
-
122
- # Offense count: 1
123
- # Cop supports --auto-correct.
124
- # Configuration parameters: EnforcedStyle, SupportedStyles.
125
- Style/MethodDefParentheses:
126
- Enabled: false
127
-
128
- # Offense count: 1
129
- # Cop supports --auto-correct.
130
- Style/MultilineIfThen:
131
- Enabled: false
135
+ Exclude:
136
+ - 'test/unit/actions/run_hosts_job_test.rb'
132
137
 
133
138
  # Offense count: 6
134
139
  # Cop supports --auto-correct.
@@ -136,78 +141,71 @@ Style/MultilineIfThen:
136
141
  Style/MultilineOperationIndentation:
137
142
  Enabled: false
138
143
 
139
- # Offense count: 4
140
- # Cop supports --auto-correct.
141
- Style/NegatedIf:
142
- Enabled: false
143
-
144
- # Offense count: 1
145
- # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
146
- Style/Next:
147
- Enabled: false
148
-
149
- # Offense count: 2
150
- # Cop supports --auto-correct.
151
- Style/Not:
152
- Enabled: false
153
-
154
144
  # Offense count: 10
155
145
  # Cop supports --auto-correct.
156
146
  # Configuration parameters: PreferredDelimiters.
157
147
  Style/PercentLiteralDelimiters:
158
148
  Enabled: false
159
149
 
160
- # Offense count: 2
150
+ # Offense count: 1
151
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
152
+ Style/RaiseArgs:
153
+ Enabled: false
154
+
155
+ # Offense count: 8
161
156
  # Cop supports --auto-correct.
162
157
  # Configuration parameters: AllowMultipleReturnValues.
163
158
  Style/RedundantReturn:
164
159
  Enabled: false
165
160
 
166
- # Offense count: 3
161
+ # Offense count: 33
167
162
  # Cop supports --auto-correct.
168
163
  # Configuration parameters: EnforcedStyle, SupportedStyles.
169
164
  Style/SignalException:
170
165
  Enabled: false
171
166
 
172
167
  # Offense count: 1
168
+ # Configuration parameters: Methods.
169
+ Style/SingleLineBlockParams:
170
+ Exclude:
171
+ - 'app/models/job_template.rb'
172
+
173
+ # Offense count: 2
173
174
  # Cop supports --auto-correct.
174
175
  Style/SpaceAfterComma:
175
- Enabled: false
176
+ Exclude:
177
+ - 'test/functional/api/v2/job_invocations_controller_test.rb'
176
178
 
177
- # Offense count: 2
179
+ # Offense count: 5
178
180
  # Cop supports --auto-correct.
181
+ # Configuration parameters: MultiSpaceAllowedForOperators.
179
182
  Style/SpaceAroundOperators:
180
- Enabled: false
183
+ Exclude:
184
+ - 'db/migrate/20150708133242_add_invocation.rb'
185
+ - 'test/unit/input_template_renderer_test.rb'
186
+ - 'test/unit/job_invocation_composer_test.rb'
181
187
 
182
- # Offense count: 2
188
+ # Offense count: 43
183
189
  # Cop supports --auto-correct.
184
190
  Style/SpaceInsideBrackets:
185
191
  Enabled: false
186
192
 
187
- # Offense count: 4
193
+ # Offense count: 89
188
194
  # Cop supports --auto-correct.
189
195
  # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
190
196
  Style/SpaceInsideHashLiteralBraces:
191
197
  Enabled: false
192
198
 
199
+ # Offense count: 7
200
+ # Cop supports --auto-correct.
201
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
202
+ Style/StringLiterals:
203
+ Exclude:
204
+ - 'locale/action_names.rb'
205
+
193
206
  # Offense count: 1
194
207
  # Cop supports --auto-correct.
195
208
  # Configuration parameters: IgnoredMethods.
196
209
  Style/SymbolProc:
197
- Enabled: false
198
-
199
- # TODO: uncomment when on rubocop 0.35.1
200
- #Rails/FindBy:
201
- #Enabled: false # rails 4
202
-
203
- # TODO: uncomment when on rubocop 0.35.1
204
- #Style/UnneededPercentQ:
205
- #Enabled: false
206
-
207
- # TODO: uncomment when on rubocop 0.35.1
208
- #Lint/EndAlignment:
209
- #Enabled: false
210
-
211
- # TODO: uncomment when on rubocop 0.35.1
212
- #Metrics/ModuleLength:
213
- #Enabled: false
210
+ Exclude:
211
+ - 'app/models/concerns/foreman_remote_execution/host_extensions.rb'
@@ -0,0 +1,10 @@
1
+ function show_import_job_template_modal() {
2
+ var modal_window = $('#importJobTemplateModal');
3
+ modal_window.modal({'show': true});
4
+ modal_window.find('a[rel="popover-modal"]').popover();
5
+ }
6
+
7
+ function close_import_job_template_modal() {
8
+ var modal_window = $('#importJobTemplateModal');
9
+ modal_window.modal('hide');
10
+ }
@@ -0,0 +1,4 @@
1
+ div.modal-body {
2
+ overflow-y: auto;
3
+ max-height: 500px;
4
+ }
@@ -7,7 +7,7 @@ module Api
7
7
  include ::Foreman::Controller::ProvisioningTemplates
8
8
 
9
9
  before_filter :find_optional_nested_object
10
- before_filter :find_resource, :only => %w{show update destroy clone}
10
+ before_filter :find_resource, :only => %w{show update destroy clone export}
11
11
 
12
12
  before_filter :handle_template_upload, :only => [:create, :update]
13
13
 
@@ -22,6 +22,23 @@ module Api
22
22
  @job_templates = resource_scope_for_index
23
23
  end
24
24
 
25
+ api :POST, '/job_templates/import', N_('Import a job template from ERB')
26
+ param :template, String, :required => true, :desc => N_('Template ERB')
27
+ param :overwrite, :bool, :required => false, :desc => N_('Overwrite template if it already exists')
28
+ def import
29
+ options = params[:overwrite] ? { :update => true } : { :build_new => true }
30
+
31
+ @job_template = JobTemplate.import(params[:template], options)
32
+ @job_template ||= JobTemplate.new
33
+ process_response @job_template.save
34
+ end
35
+
36
+ api :GET, '/job_templates/:id/export', N_('Export a job template to ERB')
37
+ param :id, :identifier, :required => true
38
+ def export
39
+ send_data @job_template.to_erb, :type => 'text/plain', :disposition => 'attachment', :filename => @job_template.filename
40
+ end
41
+
25
42
  api :GET, '/job_templates/:id', N_('Show job template details')
26
43
  param :id, :identifier, :required => true
27
44
  def show
@@ -110,6 +127,10 @@ module Api
110
127
  case params[:action]
111
128
  when 'clone'
112
129
  :create
130
+ when 'import'
131
+ :create
132
+ when 'export'
133
+ :view
113
134
  else
114
135
  super
115
136
  end
@@ -24,6 +24,26 @@ class JobTemplatesController < ::TemplatesController
24
24
  end
25
25
  end
26
26
 
27
+ def import
28
+ contents = params.fetch(:imported_template, {}).fetch(:template, nil).try(:read)
29
+
30
+ @template = JobTemplate.import(contents, :update => Foreman::Cast.to_bool(params[:imported_template][:overwrite]))
31
+ if @template && @template.save
32
+ flash[:notice] = _('Job template imported successfully.')
33
+ redirect_to job_templates_path(:search => "name = \"#{@template.name}\"")
34
+ else
35
+ @template ||= JobTemplate.import(contents, :build_new => true)
36
+ @template.valid?
37
+ flash[:warning] = _('Unable to save template. Correct highlighted errors')
38
+ render :action => 'new'
39
+ end
40
+ end
41
+
42
+ def export
43
+ find_resource unless @template.present?
44
+ send_data @template.to_erb, :type => 'text/plain', :disposition => 'attachment', :filename => @template.filename
45
+ end
46
+
27
47
  private
28
48
 
29
49
  def find_resource
@@ -36,7 +56,7 @@ class JobTemplatesController < ::TemplatesController
36
56
 
37
57
  def action_permission
38
58
  case params[:action]
39
- when 'auto_complete_job_category'
59
+ when 'auto_complete_job_category', 'export'
40
60
  :view_job_templates
41
61
  else
42
62
  super
@@ -9,8 +9,9 @@ module ForemanRemoteExecution
9
9
  def permitted_actions_with_run_button(template)
10
10
  original = permitted_actions_without_run_button(template)
11
11
 
12
- if template.is_a?(JobTemplate) && !template.snippet
13
- original.unshift(display_link_if_authorized(_('Run'), hash_for_new_job_invocation_path(:template_id => template.id)))
12
+ if template.is_a?(JobTemplate)
13
+ original.unshift(display_link_if_authorized(_('Export'), hash_for_export_job_template_path(:id => template.id), 'data-no-turbolink' => true))
14
+ original.unshift(display_link_if_authorized(_('Run'), hash_for_new_job_invocation_path(:template_id => template.id))) unless template.snippet
14
15
  end
15
16
 
16
17
  original
@@ -1,7 +1,7 @@
1
1
  # rubocop:disable Metrics/ModuleLength
2
2
  module RemoteExecutionHelper
3
3
  def providers_options
4
- RemoteExecutionProvider.providers.map { |key, provider| [ key, _(provider) ] }
4
+ RemoteExecutionProvider.providers.map { |key, provider| [ key, _(provider.humanized_name) ] }
5
5
  end
6
6
 
7
7
  def template_input_types_options
@@ -62,6 +62,10 @@ module RemoteExecutionHelper
62
62
  def template_invocation_status(task)
63
63
  if task.nil?
64
64
  icon_text('question', 'N/A', :kind => 'fa')
65
+ elsif task.state == 'running'
66
+ icon_text('running', _('running'), :kind => 'pficon')
67
+ elsif task.state == 'planned'
68
+ icon_text('build', _('planned'), :kind => 'pficon')
65
69
  else
66
70
  case task.result
67
71
  when 'warning', 'error'
@@ -72,8 +76,6 @@ module RemoteExecutionHelper
72
76
  end
73
77
  when 'success'
74
78
  icon_text('ok', _('success'), :kind => 'pficon')
75
- when 'pending'
76
- icon_text('question', _('pending'), :kind => 'fa')
77
79
  else
78
80
  task.result
79
81
  end