Class: DeepTest::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/options.rb

Defined Under Namespace

Classes: InvalidOptionError

Constant Summary collapse

VALID_OPTIONS =
[
  Option.new(:distributed_hosts, nil),
  Option.new(:number_of_agents,  nil),
  Option.new(:metrics_file,      nil),
  Option.new(:pattern,           nil),
  Option.new(:server_port,       nil),
  Option.new(:sync_options,      {}),
  Option.new(:ui,                "DeepTest::UI::Console"),
  Option.new(:listener,          "DeepTest::NullListener"),
]
UI_INSTANCES =

Don’t store UI instances in the options instance, which will need to be dumped over Telegraph since UI instances may not be dumpable.

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Options

Returns a new instance of Options.



39
40
41
42
43
44
45
46
# File 'lib/deep_test/options.rb', line 39

def initialize(hash)
  @origin_hostname = Socket.gethostname
  check_option_keys(hash)
  VALID_OPTIONS.each do |option|
    send("#{option.name}=", hash[option.name] || hash[option.name.to_s] || option.default)
  end
  self.environment_log_level = ENV['DEEP_TEST_LOG_LEVEL']
end

Instance Attribute Details

#environment_log_levelObject

Returns the value of attribute environment_log_level.



19
20
21
# File 'lib/deep_test/options.rb', line 19

def environment_log_level
  @environment_log_level
end

#ssh_client_connection_infoObject

Returns the value of attribute ssh_client_connection_info.



19
20
21
# File 'lib/deep_test/options.rb', line 19

def ssh_client_connection_info
  @ssh_client_connection_info
end

Class Method Details

.from_command_line(command_line) ⇒ Object



34
35
36
37
# File 'lib/deep_test/options.rb', line 34

def self.from_command_line(command_line)
  return new({}) if command_line.nil? || command_line.empty?
  Marshal.load Base64.decode64(command_line)
end

Instance Method Details

#connect_to_central_commandObject



63
64
65
66
67
68
# File 'lib/deep_test/options.rb', line 63

def connect_to_central_command
  address = ssh_client_connection_info ? ssh_client_connection_info.address : "localhost"
  Telegraph::Wire.connect(address, server_port) do |wire|
    yield wire
  end
end

#gathering_metrics?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/deep_test/options.rb', line 48

def gathering_metrics?
  !@metrics_file.nil?
end

#listener=(value) ⇒ Object



30
31
32
# File 'lib/deep_test/options.rb', line 30

def listener=(value)
  @listener = value.to_s
end

#mirror_pathObject



82
83
84
85
86
# File 'lib/deep_test/options.rb', line 82

def mirror_path
  raise "No source directory specified in sync_options" unless sync_options[:source]
  relative_mirror_path = @origin_hostname + sync_options[:source].gsub('/','_')
  "#{sync_options[:remote_base_dir] || '/tmp'}/#{relative_mirror_path}"
end

#new_deploymentObject



88
89
90
91
92
93
94
# File 'lib/deep_test/options.rb', line 88

def new_deployment
  if distributed_hosts.nil?
    LocalDeployment.new self
  else
    Distributed::RemoteDeployment.new self, new_landing_fleet, LocalDeployment.new(self)
  end
end

#new_landing_fleetObject



96
97
98
99
100
101
# File 'lib/deep_test/options.rb', line 96

def new_landing_fleet
  landing_ships = distributed_hosts.map do |host|
    Distributed::LandingShip.new :address => host
  end
  Distributed::LandingFleet.new self, landing_ships
end

#new_listener_listObject



52
53
54
55
56
57
# File 'lib/deep_test/options.rb', line 52

def new_listener_list
  listeners = listener.split(',').map do |listener|
    eval(listener).new
  end
  ListenerList.new(listeners)
end

#number_of_agentsObject



21
22
23
24
# File 'lib/deep_test/options.rb', line 21

def number_of_agents
  return CpuInfo.new.count unless @number_of_agents
  @number_of_agents
end

#origin_hostnameObject



59
60
61
# File 'lib/deep_test/options.rb', line 59

def origin_hostname
  (Socket.gethostname == @origin_hostname) ? 'localhost' : @origin_hostname
end

#to_command_lineObject



78
79
80
# File 'lib/deep_test/options.rb', line 78

def to_command_line
  Base64.encode64(Marshal.dump(self)).gsub("\n","")
end

#ui=(value) ⇒ Object



26
27
28
# File 'lib/deep_test/options.rb', line 26

def ui=(value)
  @ui = value.to_s
end

#ui_instanceObject



74
75
76
# File 'lib/deep_test/options.rb', line 74

def ui_instance
  UI_INSTANCES[self] ||= eval(ui).new(self)
end