class ForemanRemoteExecutionCore::FakeScriptRunner
Attributes
data[RW]
Public Class Methods
load_data(path = nil)
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 9 def load_data(path = nil) if path.nil? @data = " | ====== Simulated Remote Execution ====== | | This is an output of a simulated remote | execution run. It should run for about | 5 seconds and finish successfully. ".gsub(/^\s+\| ?/, '').lines 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 27 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 47 def kill finish end
refresh()
click to toggle source
Do one step
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 39 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 34 def start refresh end
Private Instance Methods
done?()
click to toggle source
# File lib/foreman_remote_execution_core/fake_script_runner.rb, line 61 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 72 def exit_code fail_chance = ENV.fetch('REX_SIMULATE_FAIL_CHANCE', 0).to_i fail_exitcode = ENV.fetch('REX_SIMULATE_EXIT', 0) 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 53 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 65 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 57 def step publish_data(next_chunk, 'stdout') end