foreman_remote_execution 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -0
  3. data/app/controllers/api/v2/foreign_input_sets_controller.rb +1 -1
  4. data/app/helpers/concerns/foreman_remote_execution/hosts_helper_extensions.rb +1 -1
  5. data/app/helpers/remote_execution_helper.rb +4 -9
  6. data/app/models/job_invocation.rb +3 -0
  7. data/app/models/job_invocation_composer.rb +11 -2
  8. data/app/models/job_template.rb +2 -2
  9. data/app/models/job_template_effective_user.rb +2 -0
  10. data/app/models/setting/remote_execution.rb +4 -1
  11. data/app/views/job_templates/index.html.erb +1 -3
  12. data/app/views/template_invocations/show.html.erb +5 -5
  13. data/app/views/templates/README.md +6 -0
  14. data/app/views/templates/{package_action.erb → ssh/package_action.erb} +0 -0
  15. data/app/views/templates/{power_action.erb → ssh/power_action.erb} +0 -0
  16. data/app/views/templates/{puppet_run_once.erb → ssh/puppet_run_once.erb} +0 -0
  17. data/app/views/templates/{run_command.erb → ssh/run_command.erb} +0 -0
  18. data/app/views/templates/{service_action.erb → ssh/service_action.erb} +0 -0
  19. data/foreman_remote_execution.gemspec +1 -1
  20. data/lib/foreman_remote_execution/engine.rb +2 -2
  21. data/lib/foreman_remote_execution/version.rb +1 -1
  22. data/test/factories/foreman_remote_execution_factories.rb +10 -1
  23. data/test/unit/concerns/host_extensions_test.rb +4 -7
  24. data/test/unit/input_template_renderer_test.rb +3 -0
  25. data/test/unit/job_template_test.rb +11 -0
  26. data/test/unit/remote_execution_feature_test.rb +4 -0
  27. data/test/unit/remote_execution_provider_test.rb +5 -2
  28. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbd4cc854e9c31820b3dc2a1f9003613c5aa5ca1
4
- data.tar.gz: 3f6b42cc33bac2022990315ed31d29fd537a5df9
3
+ metadata.gz: 5b0446f3fb6c5f2d4640bbe0e15ddee61123fd03
4
+ data.tar.gz: 49de19a88a35ff89dd770be96886a75600634012
5
5
  SHA512:
6
- metadata.gz: 7bdbfca1932005c1d8fe09c9a72adb2b72bedd9455a9a6bed8e53fd3fa750dbf659920a6f443503007ac529da9136a5bbee8964fa9271123227e7f501d3ff31e
7
- data.tar.gz: 8f7d084a004c1c8b0705e2f37625801090cfb789990a14ce50613781e21e72c9be595f14e0c05a3cb915d70d68fd94966bc5ff9bea80cd13bb58c807fdba56c4
6
+ metadata.gz: 777c28e28ab17cc1e5db620faff516f3b350cb6ae4acb3361e7fecd99821919d1a2ad5ca3706c79e4df246a7f6c92a78e6a0500de52c8fcbb4ac02411e747dab
7
+ data.tar.gz: cde19bd5f565b9d823f7668ddb7dbb4458d3d31f1607bef4a685f580bcfd0f340c9fcaef1916b1c9543419f11d6aa794cb7027ee0fa1534f768aefc7fbf9e6b4
data/README.md CHANGED
@@ -33,6 +33,17 @@ Check the Foreman manual [remote execution section](http://theforeman.org/plugin
33
33
 
34
34
  Fork and send a Pull Request. Thanks!
35
35
 
36
+ ## Release Process
37
+
38
+ ### Pull Translations from Transifex
39
+
40
+ As part of the release process, localization must be synced from Transifex. See the [wiki](http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin#Pulling-translations-from-Transifex) for more information.
41
+
42
+ ### Sync Job Templates from Community Templates
43
+
44
+ The [community-templates](https://github.com/theforeman/community-templates.git) repo is the source for our job templates. Prior to release, use the script/sync_templates.sh script to pull in any changes.
45
+
46
+
36
47
  ## Copyright
37
48
 
38
49
  Copyright (c) 2015 The Foreman developers
@@ -23,7 +23,7 @@ module Api
23
23
  def_param_group :foreign_input_set do
24
24
  param :foreign_input_set, Hash, :required => true, :action_aware => true do
25
25
  param :target_template_id, :identifier, :required => true, :desc => N_('Target template ID')
26
- param :include_all, :bool, :desc => N_('Include all inputs form the foreign template')
26
+ param :include_all, :bool, :desc => N_('Include all inputs from the foreign template')
27
27
  param :include, String, :desc => N_('A comma separated list of input names to be included from the foreign template.')
28
28
  param :exclude, String, :desc => N_('A comma separated list of input names to be included from the foreign template.')
29
29
  param :description, String, :required => false, :desc => N_('Input set description')
@@ -12,7 +12,7 @@ module ForemanRemoteExecution
12
12
  end
13
13
 
14
14
  def host_title_actions_with_run_button(*args)
15
- title_actions(button_group(link_to(_('Run Job'), new_job_invocation_path(:host_ids => [args.first.id]), :id => :run_button)))
15
+ title_actions(button_group(link_to(_('Run Job'), new_job_invocation_path(:host_ids => [args.first.id]), :id => :run_button, :class => 'btn btn-default')))
16
16
  host_title_actions_without_run_button(*args)
17
17
  end
18
18
  end
@@ -35,7 +35,7 @@ module RemoteExecutionHelper
35
35
  when HostStatus::ExecutionStatus::QUEUED
36
36
  _('queued')
37
37
  when HostStatus::ExecutionStatus::RUNNING
38
- _('running %{percent}%') % {:percent => invocation.progress}
38
+ _('running %{percent}%%') % {:percent => invocation.progress}
39
39
  when HostStatus::ExecutionStatus::OK
40
40
  _('succeeded')
41
41
  when HostStatus::ExecutionStatus::ERROR
@@ -96,7 +96,7 @@ module RemoteExecutionHelper
96
96
  def job_invocations_buttons
97
97
  [
98
98
  documentation_button_rex('3.2ExecutingaJob'),
99
- display_link_if_authorized(_('Run Job'), hash_for_new_job_invocation_path)
99
+ new_link(_('Run Job'))
100
100
  ]
101
101
  end
102
102
 
@@ -206,13 +206,8 @@ module RemoteExecutionHelper
206
206
 
207
207
  def documentation_button_rex(section = '')
208
208
  url = 'http://theforeman.org/plugins/foreman_remote_execution/' +
209
- "#{ForemanRemoteExecution::VERSION.split('.').take(2).join('.')}/index.html#" +
210
- section
211
- link_to(
212
- icon_text('help', _('Documentation'),
213
- :class => 'icon-white', :kind => 'pficon'),
214
- url,
215
- :rel => 'external', :class => 'btn btn-info', :target => '_blank')
209
+ "#{ForemanRemoteExecution::VERSION.split('.').take(2).join('.')}/index.html#"
210
+ documentation_button section, :root_url => url
216
211
  end
217
212
 
218
213
  def template_input_header(f, template)
@@ -20,6 +20,9 @@ class JobInvocation < ActiveRecord::Base
20
20
  scoped_search :on => :job_category, :complete_value => true
21
21
  scoped_search :on => :description # FIXME No auto complete because of https://github.com/wvanbergen/scoped_search/issues/138
22
22
 
23
+ has_many :template_invocations_hosts, :through => :template_invocations, :source => :host
24
+ scoped_search :in => :template_invocations_hosts, :on => :name, :rename => 'host', :complete_value => true
25
+
23
26
  delegate :bookmark, :resolved?, :to => :targeting, :allow_nil => true
24
27
 
25
28
  include ForemanTasks::Concerns::ActionSubject
@@ -9,7 +9,7 @@ class JobInvocationComposer
9
9
  def params
10
10
  { :job_category => job_invocation_base[:job_category],
11
11
  :targeting => ui_params.fetch(:targeting, {}).merge(:user_id => User.current.id),
12
- :triggering => ui_params.fetch(:triggering, {}),
12
+ :triggering => triggering,
13
13
  :host_ids => ui_params[:host_ids],
14
14
  :description_format => job_invocation_base[:description_format],
15
15
  :concurrency_control => concurrency_control_params,
@@ -57,6 +57,14 @@ class JobInvocationComposer
57
57
  :level => job_invocation_base[:concurrency_level]
58
58
  }
59
59
  end
60
+
61
+ def triggering
62
+ return {} unless ui_params.key?(:triggering)
63
+ trig = ui_params[:triggering]
64
+ keys = (1..5).map { |i| "end_time(#{i}i)" }
65
+ return trig unless trig.key?(:end_time) && trig[:end_time].keys == keys
66
+ trig.merge(:end_time => Time.local(*trig[:end_time].values_at(*keys)))
67
+ end
60
68
  end
61
69
 
62
70
  class ApiParams
@@ -304,7 +312,8 @@ class JobInvocationComposer
304
312
  end
305
313
 
306
314
  def valid?
307
- targeting.valid? & job_invocation.valid? & !pattern_template_invocations.map(&:valid?).include?(false)
315
+ targeting.valid? & job_invocation.valid? & !pattern_template_invocations.map(&:valid?).include?(false) &
316
+ triggering.valid?
308
317
  end
309
318
 
310
319
  def save
@@ -195,8 +195,8 @@ class JobTemplate < ::Template
195
195
  end
196
196
 
197
197
  def sync_feature(feature_name)
198
- if feature_name && (feature = RemoteExecutionFeature.feature(feature_name))
199
- feature.job_template ||= self
198
+ if feature_name && (feature = RemoteExecutionFeature.feature(feature_name)) && feature.job_template.blank?
199
+ self.remote_execution_features << feature
200
200
  end
201
201
  end
202
202
 
@@ -1,5 +1,7 @@
1
1
  class JobTemplateEffectiveUser < ActiveRecord::Base
2
2
 
3
+ attr_accessible :value, :current_user, :overridable
4
+
3
5
  belongs_to :job_template
4
6
 
5
7
  before_validation :set_defaults
@@ -22,7 +22,10 @@ class Setting::RemoteExecution < Setting
22
22
  'root'),
23
23
  self.set('remote_execution_effective_user_method',
24
24
  N_('What command should be used to switch to the effective user. One of %s') % SSHExecutionProvider::EFFECTIVE_USER_METHODS.inspect,
25
- 'sudo'),
25
+ 'sudo',
26
+ 'remote_execution_effective_user_method',
27
+ nil,
28
+ { :collection => Proc.new {Hash[SSHExecutionProvider::EFFECTIVE_USER_METHODS.map{|method| [method, method]}]} }),
26
29
  self.set('remote_execution_sync_templates',
27
30
  N_('Whether we should sync templates from disk when running db:seed.'),
28
31
  true)
@@ -1,4 +1,3 @@
1
- <%= include_javascript if SETTINGS[:version].short == '1.9' %>
2
1
  <%= javascript 'job_templates' %>
3
2
  <%= javascript 'lookup_keys' %>
4
3
  <%= javascript 'template_input' %>
@@ -6,8 +5,7 @@
6
5
  <% title _("Job Templates") %>
7
6
  <% title_actions(documentation_button_rex('3.1JobTemplates'),
8
7
  link_to_function(_('Import'), 'show_import_job_template_modal();', :class => 'btn btn-default'),
9
- display_link_if_authorized(_("New Job Template"),
10
- hash_for_new_job_template_path)) %>
8
+ new_link(_("New Job Template"))) %>
11
9
 
12
10
  <table class="table table-bordered table-striped table-two-pane table-fixed">
13
11
  <thead>
@@ -4,11 +4,11 @@
4
4
 
5
5
  <div id="title_action">
6
6
  <div class="btn-toolbar pull-right">
7
- <%= link_to(_('Back to Job'), job_invocation_path(@template_invocation.job_invocation)) %>
8
- <%= button_group(link_to_function(_('Toggle command'), '$("div.preview").toggle()'),
9
- link_to_function(_('Toggle STDERR'), '$("div.line.stderr").toggle()'),
10
- link_to_function(_('Toggle STDOUT'), '$("div.line.stdout").toggle()'),
11
- link_to_function(_('Toggle DEBUG'), '$("div.line.debug").toggle()')) %>
7
+ <%= link_to(_('Back to Job'), job_invocation_path(@template_invocation.job_invocation), :class => 'btn btn-default') %>
8
+ <%= button_group(link_to_function(_('Toggle command'), '$("div.preview").toggle()', :class => 'btn btn-default'),
9
+ link_to_function(_('Toggle STDERR'), '$("div.line.stderr").toggle()', :class => 'btn btn-default'),
10
+ link_to_function(_('Toggle STDOUT'), '$("div.line.stdout").toggle()', :class => 'btn btn-default'),
11
+ link_to_function(_('Toggle DEBUG'), '$("div.line.debug").toggle()', :class => 'btn btn-default')) %>
12
12
  <%= button_group(template_invocation_task_buttons(@template_invocation_task)) %>
13
13
  </div>
14
14
  </div>
@@ -0,0 +1,6 @@
1
+ # Job Templates
2
+
3
+ **IMPORTANT** Do not submit pull requests here, these templates are only
4
+ updated during the release process. The
5
+ [community-templates](https://github.com/theforeman/community-templates) repos
6
+ is the canonical source for job templates.
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.description = 'A plugin bringing remote execution to the Foreman, completing the config ' +
15
15
  'management functionality with remote management functionality.'
16
16
 
17
- s.files = `git ls-files`.split("\n")
17
+ s.files = `git ls-files`.split("\n").reject { |f| f =~ /^scripts/ }
18
18
  s.test_files = `git ls-files test`.split("\n")
19
19
  s.extra_rdoc_files = `git ls-files doc`.split("\n") + Dir['README*', 'LICENSE']
20
20
 
@@ -27,9 +27,9 @@ module ForemanRemoteExecution
27
27
  ForemanTasks.dynflow.config.eager_load_paths << File.join(ForemanRemoteExecution::Engine.root, 'app/lib/actions')
28
28
  end
29
29
 
30
- initializer 'foreman_remote_execution.register_plugin', after: :finisher_hook do |_app|
30
+ initializer 'foreman_remote_execution.register_plugin', before: :finisher_hook do |_app|
31
31
  Foreman::Plugin.register :foreman_remote_execution do
32
- requires_foreman '>= 1.11'
32
+ requires_foreman '>= 1.12'
33
33
 
34
34
  apipie_documented_controllers ["#{ForemanRemoteExecution::Engine.root}/app/controllers/api/v2/*.rb"]
35
35
 
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecution
2
- VERSION = '0.3.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -15,6 +15,10 @@ FactoryGirl.define do
15
15
  trait :with_description_format do
16
16
  description_format 'Factory-built %{job_category}'
17
17
  end
18
+
19
+ trait :with_feature do
20
+ remote_execution_feature
21
+ end
18
22
  end
19
23
 
20
24
  factory :template_input do |f|
@@ -54,6 +58,11 @@ FactoryGirl.define do
54
58
  factory :template_invocation_input_value do |f|
55
59
  f.sequence(:value) { |n| "Input Value #{n}" }
56
60
  end
61
+
62
+ factory :remote_execution_feature do |f|
63
+ f.sequence(:label) { |n| "remote_execution_feature_#{n}" }
64
+ f.sequence(:name) { |n| "Remote Execution Feature #{n}" }
65
+ end
57
66
  end
58
67
 
59
68
  FactoryGirl.modify do
@@ -89,7 +98,7 @@ FactoryGirl.modify do
89
98
  overrides[:organizations] = [organization] unless organization.nil?
90
99
 
91
100
  FactoryGirl.create(
92
- :subnet,
101
+ :subnet_ipv4,
93
102
  overrides
94
103
  )
95
104
  end
@@ -3,14 +3,11 @@ require 'test_plugin_helper'
3
3
  describe ForemanRemoteExecution::HostExtensions do
4
4
  let(:provider) { 'SSH' }
5
5
 
6
- before do
7
- User.current = FactoryGirl.build(:user, :admin)
8
- end
9
-
6
+ before { User.current = FactoryGirl.build(:user, :admin) }
10
7
  after { User.current = nil }
11
8
 
12
9
  describe 'ssh specific params' do
13
- let(:host) { FactoryGirl.build(:host, :with_execution) }
10
+ let(:host) { FactoryGirl.create(:host, :with_execution) }
14
11
  let(:sshkey) { 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQ foo@example.com' }
15
12
 
16
13
  before do
@@ -24,7 +21,7 @@ describe ForemanRemoteExecution::HostExtensions do
24
21
  end
25
22
 
26
23
  it 'can override ssh user' do
27
- host.host_parameters << FactoryGirl.build(:host_parameter, :name => 'remote_execution_ssh_user', :value => 'amy')
24
+ host.host_parameters << FactoryGirl.create(:host_parameter, :host => host, :name => 'remote_execution_ssh_user', :value => 'amy')
28
25
  host.params['remote_execution_ssh_user'].must_equal 'amy'
29
26
  end
30
27
 
@@ -33,7 +30,7 @@ describe ForemanRemoteExecution::HostExtensions do
33
30
  end
34
31
 
35
32
  it 'can override effective user method' do
36
- host.host_parameters << FactoryGirl.build(:host_parameter, :name => 'remote_execution_effective_user_method', :value => 'su')
33
+ host.host_parameters << FactoryGirl.create(:host_parameter, :host => host, :name => 'remote_execution_effective_user_method', :value => 'su')
37
34
  host.params['remote_execution_effective_user_method'].must_equal 'su'
38
35
  end
39
36
 
@@ -412,6 +412,9 @@ TEMPLATE
412
412
  end
413
413
 
414
414
  context 'with host specified' do
415
+ before { User.current = FactoryGirl.build(:user, :admin) }
416
+ after { User.current = nil }
417
+
415
418
  let(:environment) { FactoryGirl.create(:environment) }
416
419
  before { renderer.host = FactoryGirl.create(:host, :environment => environment) }
417
420
 
@@ -73,6 +73,10 @@ describe JobTemplate do
73
73
  end
74
74
 
75
75
  context 'importing a new template' do
76
+ let(:remote_execution_feature) do
77
+ FactoryGirl.create(:remote_execution_feature)
78
+ end
79
+
76
80
  let(:template) do
77
81
  template = <<-END_TEMPLATE
78
82
  <%#
@@ -80,6 +84,7 @@ describe JobTemplate do
80
84
  name: Service Restart
81
85
  job_category: Service Restart
82
86
  provider_type: SSH
87
+ feature: #{remote_execution_feature.label}
83
88
  template_inputs:
84
89
  - name: service_name
85
90
  input_type: user
@@ -129,6 +134,12 @@ describe JobTemplate do
129
134
  template_with_input_sets.template_inputs_with_foreign.map(&:name).must_equal ['service_name']
130
135
  end
131
136
 
137
+ it 'imports feature' do
138
+ template # let is lazy
139
+ remote_execution_feature.reload
140
+ remote_execution_feature.job_template.must_equal template
141
+ end
142
+
132
143
  it 'sets additional options' do
133
144
  template.default.must_equal true
134
145
  end
@@ -1,6 +1,10 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  describe RemoteExecutionFeature do
4
+ should validate_presence_of(:name)
5
+ should validate_presence_of(:label)
6
+ should validate_uniqueness_of(:name)
7
+ should validate_uniqueness_of(:label)
4
8
 
5
9
  let(:install_feature) do
6
10
  RemoteExecutionFeature.register(:katello_install_package, N_('Katello: Install package'),
@@ -50,6 +50,9 @@ describe RemoteExecutionProvider do
50
50
  end
51
51
 
52
52
  describe SSHExecutionProvider do
53
+ before { User.current = FactoryGirl.build(:user, :admin) }
54
+ after { User.current = nil }
55
+
53
56
  before do
54
57
  Setting::RemoteExecution.load_defaults
55
58
  end
@@ -69,7 +72,7 @@ describe RemoteExecutionProvider do
69
72
  describe 'ssh user' do
70
73
  it 'uses the remote_execution_ssh_user on the host param' do
71
74
  host.params['remote_execution_ssh_user'] = 'my user'
72
- host.host_parameters << FactoryGirl.build(:host_parameter, :name => 'remote_execution_ssh_user', :value => 'my user')
75
+ host.host_parameters << FactoryGirl.create(:host_parameter, :host => host, :name => 'remote_execution_ssh_user', :value => 'my user')
73
76
  proxy_options[:ssh_user].must_equal 'my user'
74
77
  end
75
78
  end
@@ -77,7 +80,7 @@ describe RemoteExecutionProvider do
77
80
  describe 'sudo' do
78
81
  it 'uses the remote_execution_ssh_user on the host param' do
79
82
  host.params['remote_execution_effective_user_method'] = 'sudo'
80
- method_param = FactoryGirl.build(:host_parameter, :name => 'remote_execution_effective_user_method', :value => 'sudo')
83
+ method_param = FactoryGirl.create(:host_parameter, :host => host, :name => 'remote_execution_effective_user_method', :value => 'sudo')
81
84
  host.host_parameters << method_param
82
85
  proxy_options[:effective_user_method].must_equal 'sudo'
83
86
  method_param.update_attributes!(:value => 'su')
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: 0.3.2
4
+ version: 1.0.0
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: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -254,11 +254,12 @@ files:
254
254
  - app/views/template_invocations/_refresh.js.erb
255
255
  - app/views/template_invocations/show.html.erb
256
256
  - app/views/template_invocations/show.js.erb
257
- - app/views/templates/package_action.erb
258
- - app/views/templates/power_action.erb
259
- - app/views/templates/puppet_run_once.erb
260
- - app/views/templates/run_command.erb
261
- - app/views/templates/service_action.erb
257
+ - app/views/templates/README.md
258
+ - app/views/templates/ssh/package_action.erb
259
+ - app/views/templates/ssh/power_action.erb
260
+ - app/views/templates/ssh/puppet_run_once.erb
261
+ - app/views/templates/ssh/run_command.erb
262
+ - app/views/templates/ssh/service_action.erb
262
263
  - config/routes.rb
263
264
  - db/migrate/20150612121541_add_job_template_to_template.rb
264
265
  - db/migrate/20150616080015_create_template_input.rb