foreman_remote_execution_core 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ed4af0ca0cfa0732b3b1ab8614ac6b6429db9bd7
4
- data.tar.gz: 9e810b7d7b4d91988e0a83d182dfb5d0fc2214dd
2
+ SHA256:
3
+ metadata.gz: f58fc844cebc176f015343ed6c5ed47a97ffeac65356c8eb34009705b29322dd
4
+ data.tar.gz: 91b3890c6238578942389be52d1392a140deba33aa6261de65776788bca86fb7
5
5
  SHA512:
6
- metadata.gz: d72dfad5a53957f25eeb547c62d0214c039e7c5e654ab18e198015f24158a5c65485b5b4b49417b4e2814a2bd082d300e2e4687a0469aa1b06a481f769268a09
7
- data.tar.gz: 57d534ca297475f32ac4593db2590c7c747d74443d25600ec5d4c7b93647431275838652824d4d795a339a21f9377ea8c041c00cb712fc09ccdce6619786de15
6
+ metadata.gz: 86b4e7b8e098b493cda6214cfd5fa35ed471221c7ef8af9ba23a8966f7eca0236aea68eac9890d1333119f954e4b90b730fd2e1f73ad05c1b97f761e936bebad
7
+ data.tar.gz: cfb6aba18b777bb140e2535bd16c70a6c248ff7d4b0a44fcc9005da32c647321bcf3517d5f6fef2b2ae8377105d0209ddd7e65da0b04b6b332a138d4e297ca70
@@ -10,12 +10,43 @@ module ForemanRemoteExecutionCore
10
10
  :kerberos_auth => false,
11
11
  :async_ssh => false,
12
12
  # When set to nil, makes REX use the runner's default interval
13
- :runner_refresh_interval => nil)
13
+ :runner_refresh_interval => nil,
14
+ :ssh_log_level => :fatal)
15
+
16
+ SSH_LOG_LEVELS = %w(debug info warn error fatal).freeze
14
17
 
15
18
  def self.simulate?
16
19
  %w(yes true 1).include? ENV.fetch('REX_SIMULATE', '').downcase
17
20
  end
18
21
 
22
+ def self.validate_settings!
23
+ super
24
+ self.validate_ssh_log_level!
25
+ @settings[:ssh_log_level] = @settings[:ssh_log_level].to_sym
26
+ end
27
+
28
+ def self.validate_ssh_log_level!
29
+ wanted_level = @settings[:ssh_log_level].to_s
30
+ unless SSH_LOG_LEVELS.include? wanted_level
31
+ raise "Wrong value '#{@settings[:ssh_log_level]}' for ssh_log_level, must be one of #{SSH_LOG_LEVELS.join(', ')}"
32
+ end
33
+
34
+ current = if defined?(SmartProxyDynflowCore)
35
+ SmartProxyDynflowCore::SETTINGS.log_level.to_s.downcase
36
+ else
37
+ Rails.configuration.log_level.to_s
38
+ end
39
+
40
+ # regular log levels correspond to upcased ssh logger levels
41
+ ssh, regular = [wanted_level, current].map do |wanted|
42
+ SSH_LOG_LEVELS.each_with_index.find { |value, _index| value == wanted }.last
43
+ end
44
+
45
+ if ssh < regular
46
+ raise 'ssh_log_level cannot be more verbose than regular log level'
47
+ end
48
+ end
49
+
19
50
  def self.runner_class
20
51
  @runner_class ||= if simulate?
21
52
  FakeScriptRunner
@@ -28,6 +59,7 @@ module ForemanRemoteExecutionCore
28
59
 
29
60
  if ForemanTasksCore.dynflow_present?
30
61
  require 'foreman_tasks_core/runner'
62
+ require 'foreman_remote_execution_core/log_filter'
31
63
  if simulate?
32
64
  # Load the fake implementation of the script runner if debug is enabled
33
65
  require 'foreman_remote_execution_core/fake_script_runner'
@@ -1,5 +1,6 @@
1
1
  module ForemanRemoteExecutionCore
2
2
  class FakeScriptRunner < ForemanTasksCore::Runner::Base
3
+ DEFAULT_REFRESH_INTERVAL = 1
3
4
 
4
5
  @data = []
5
6
 
@@ -0,0 +1,13 @@
1
+ module ForemanRemoteExecutionCore
2
+ class LogFilter < ::Logger
3
+ def initialize(base_logger)
4
+ @base_logger = base_logger
5
+ end
6
+
7
+ def add(severity, *args)
8
+ severity ||= ::Logger::UNKNOWN
9
+ return true if @base_logger.nil? || severity < @level
10
+ @base_logger.add(severity, *args)
11
+ end
12
+ end
13
+ end
@@ -12,6 +12,7 @@ module ForemanRemoteExecutionCore
12
12
 
13
13
  EXPECTED_POWER_ACTION_MESSAGES = ['restart host', 'shutdown host'].freeze
14
14
  DEFAULT_REFRESH_INTERVAL = 1
15
+ MAX_PROCESS_RETRIES = 4
15
16
 
16
17
  def initialize(options)
17
18
  super()
@@ -19,6 +20,8 @@ module ForemanRemoteExecutionCore
19
20
  @script = options.fetch(:script)
20
21
  @ssh_user = options.fetch(:ssh_user, 'root')
21
22
  @ssh_port = options.fetch(:ssh_port, 22)
23
+ @ssh_password = options.fetch(:secrets, {}).fetch(:ssh_password, nil)
24
+ @key_passphrase = options.fetch(:secrets, {}).fetch(:key_passphrase, nil)
22
25
  @effective_user = options.fetch(:effective_user, nil)
23
26
  @effective_user_method = options.fetch(:effective_user_method, 'sudo')
24
27
  @host_public_key = options.fetch(:host_public_key, nil)
@@ -108,7 +111,7 @@ module ForemanRemoteExecutionCore
108
111
 
109
112
  def with_disconnect_handling
110
113
  yield
111
- rescue Net::SSH::Disconnect => e
114
+ rescue IOError, Net::SSH::Disconnect => e
112
115
  @session.shutdown!
113
116
  check_expecting_disconnect
114
117
  if @expecting_disconnect
@@ -139,6 +142,8 @@ module ForemanRemoteExecutionCore
139
142
  ssh_options = {}
140
143
  ssh_options[:port] = @ssh_port if @ssh_port
141
144
  ssh_options[:keys] = [@client_private_key_file] if @client_private_key_file
145
+ ssh_options[:password] = @ssh_password if @ssh_password
146
+ ssh_options[:passphrase] = @key_passphrase if @key_passphrase
142
147
  ssh_options[:user_known_hosts_file] = @known_hosts_file if @known_hosts_file
143
148
  ssh_options[:keys_only] = true
144
149
  # if the host public key is contained in the known_hosts_file,
@@ -146,6 +151,9 @@ module ForemanRemoteExecutionCore
146
151
  ssh_options[:paranoid] = true
147
152
  ssh_options[:auth_methods] = available_authentication_methods
148
153
  ssh_options[:user_known_hosts_file] = prepare_known_hosts if @host_public_key
154
+ ssh_options[:number_of_password_prompts] = 1
155
+ ssh_options[:verbose] = settings[:ssh_log_level]
156
+ ssh_options[:logger] = ForemanRemoteExecutionCore::LogFilter.new(SmartProxyDynflowCore::Log.instance)
149
157
  return ssh_options
150
158
  end
151
159
 
@@ -280,7 +288,7 @@ module ForemanRemoteExecutionCore
280
288
 
281
289
  def upload_file(local_path, remote_path)
282
290
  mode = File.stat(local_path).mode.to_s(8)[-3..-1]
283
- @logger.debug('Uploading local file: #{local_path} as #{remote_path} with #{mode} permissions')
291
+ @logger.debug("Uploading local file: #{local_path} as #{remote_path} with #{mode} permissions")
284
292
  upload_data(File.read(local_path), remote_path, mode)
285
293
  end
286
294
 
@@ -322,6 +330,8 @@ module ForemanRemoteExecutionCore
322
330
  @logger.warn('Kerberos authentication requested but not available')
323
331
  end
324
332
  end
333
+ methods.unshift('password') if @ssh_password
334
+
325
335
  methods
326
336
  end
327
337
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecutionCore
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-09 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks-core
@@ -38,8 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: |2
42
- Ssh remote execution provider code sharable between Foreman and Foreman-Proxy
41
+ description: " Ssh remote execution provider code sharable between Foreman and Foreman-Proxy\n"
43
42
  email:
44
43
  - inecas@redhat.com
45
44
  executables: []
@@ -51,6 +50,7 @@ files:
51
50
  - lib/foreman_remote_execution_core/actions.rb
52
51
  - lib/foreman_remote_execution_core/dispatcher.rb
53
52
  - lib/foreman_remote_execution_core/fake_script_runner.rb
53
+ - lib/foreman_remote_execution_core/log_filter.rb
54
54
  - lib/foreman_remote_execution_core/polling_script_runner.rb
55
55
  - lib/foreman_remote_execution_core/script_runner.rb
56
56
  - lib/foreman_remote_execution_core/version.rb
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.6.12
77
+ rubygems_version: 2.7.3
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Foreman remote execution - core bits