class ForemanRemoteExecutionCore::FakeScriptRunner
Constants
- DEFAULT_REFRESH_INTERVAL
Attributes
data[RW]
Public Class Methods
build(options, suspended_action:)
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 27 def build(options, suspended_action:) new(options, suspended_action: suspended_action) end
load_data(path = nil)
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 10 def load_data(path = nil) if path.nil? @data = <<-END.gsub(/^\s+\| ?/, '').lines | ====== Simulated Remote Execution ====== | | This is an output of a simulated remote | execution run. It should run for about | 5 seconds and finish successfully. END else File.open(File.expand_path(path), 'r') do |f| @data = f.readlines.map(&:chomp) end end @data.freeze end
new(*args)
click to toggle source
Calls superclass method
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 32 def initialize(*args) super # Load the fake output the first time its needed self.class.load_data(ENV['REX_SIMULATE_PATH']) unless self.class.data.frozen? @position = 0 end
Public Instance Methods
kill()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 52 def kill finish end
refresh()
click to toggle source
Do one step
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 44 def refresh if done? finish else step end end
start()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 39 def start refresh end
Private Instance Methods
done?()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 66 def done? @position == self.class.data.count end
exit_code()
click to toggle source
Decide if the execution should fail or not
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 77 def exit_code fail_chance = ENV.fetch('REX_SIMULATE_FAIL_CHANCE', 0).to_i fail_exitcode = ENV.fetch('REX_SIMULATE_EXIT', 0).to_i if fail_exitcode == 0 || fail_chance < (Random.rand * 100).round 0 else fail_exitcode end end
finish()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 58 def finish publish_exit_status exit_code end
next_chunk()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 70 def next_chunk output = self.class.data[@position] @position += 1 output end
step()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 62 def step publish_data(next_chunk, 'stdout') end