Method: Beaker::Options::Parser#parse_hosts_options

Defined in:
lib/beaker/options/parser.rb

#parse_hosts_optionsHash

Parse hosts options from host files into a host options hash. Falls back to trying as a beaker-hostgenerator string if reading the hosts file doesn’t work

Returns:

  • (Hash)

    Host options, containing all host-specific details

Raises:

  • (ArgumentError)

    if a hosts file is generated, but it can’t be read by the HostsFileParser



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/beaker/options/parser.rb', line 283

def parse_hosts_options
  if @options[:hosts_file].nil? || File.exists?(@options[:hosts_file])
    #read the hosts file that contains the node configuration and hypervisor info
    return Beaker::Options::HostsFileParser.parse_hosts_file(@options[:hosts_file])
  end

  dne_message = "\nHosts file '#{@options[:hosts_file]}' does not exist."
  dne_message << "\nTrying as beaker-hostgenerator input.\n\n"
  $stdout.puts dne_message
  require 'beaker-hostgenerator'

  host_generator_options = [ @options[:hosts_file] ]
  host_generator_options += [ '--hypervisor', ENV['BEAKER_HYPERVISOR'] ] if ENV['BEAKER_HYPERVISOR']

  hosts_file_content = begin
    bhg_cli = BeakerHostGenerator::CLI.new(host_generator_options)
    bhg_cli.execute
  rescue BeakerHostGenerator::Exceptions::Error,
    BeakerHostGenerator::Exceptions::InvalidNodeSpecError => error
    error_message = "\nbeaker-hostgenerator was not able to use this value as input."
    error_message << "\nExiting with an Error.\n\n"
    $stderr.puts error_message
    raise error
  end

  @options[:hosts_file_generated] = true
  Beaker::Options::HostsFileParser.parse_hosts_string( hosts_file_content )
end