Class: ForemanRemoteExecutionCore::FakeScriptRunner

Inherits:
ForemanTasksCore::Runner::Base
  • Object
show all
Defined in:
lib/foreman_remote_execution_core/fake_script_runner.rb

Constant Summary collapse

DEFAULT_REFRESH_INTERVAL =
1

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FakeScriptRunner

Returns a new instance of FakeScriptRunner.



32
33
34
35
36
37
# 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

Class Attribute Details

.dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/foreman_remote_execution_core/fake_script_runner.rb', line 8

def data
  @data
end

Class Method Details

.build(options, suspended_action:) ⇒ Object



27
28
29
# 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) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Method Details

#killObject



52
53
54
# File 'lib/foreman_remote_execution_core/fake_script_runner.rb', line 52

def kill
  finish
end

#refreshObject

Do one step



44
45
46
47
48
49
50
# File 'lib/foreman_remote_execution_core/fake_script_runner.rb', line 44

def refresh
  if done?
    finish
  else
    step
  end
end

#startObject



39
40
41
# File 'lib/foreman_remote_execution_core/fake_script_runner.rb', line 39

def start
  refresh
end