Method: Beaker::Options::Parser#normalize_args

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

#normalize_argsObject

Validate all merged options values for correctness

Currently checks:

- each host has a valid platform
- if a keyfile is provided then use it
- paths provided to --test, --pre-suite, --post-suite provided lists of .rb files for testing
- --type is one of 'pe' or 'git'
- --fail-mode is one of 'fast', 'stop' or nil
- if using blimpy hypervisor an EC2 YAML file exists
- if using the aix, solaris, or vcloud hypervisors a .fog file exists
- that one and only one master is defined per set of hosts
- that solaris/windows/aix hosts are agent only for PE tests OR
- that windows/aix host are agent only if type is not 'pe'
- sets the default host based upon machine definitions

Raises:

  • (ArgumentError)

    Raise if argument/options values are invalid



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/beaker/options/parser.rb', line 249

def normalize_args

  @options['HOSTS'].each_key do |name|
    if not @options['HOSTS'][name]['platform']
      parser_error "Host #{name} does not have a platform specified"
    else
      @options['HOSTS'][name]['platform'] = Platform.new(@options['HOSTS'][name]['platform'])
    end
  end

  #use the keyfile if present
  if @options.has_key?(:keyfile)
    @options[:ssh][:keys] = [@options[:keyfile]]
  end

  #split out arguments - these arguments can have the form of arg1,arg2 or [arg] or just arg
  #will end up being normalized into an array
  LONG_OPTS.each do |opt|
    if @options.has_key?(opt)
      @options[opt] = split_arg(@options[opt])
      if RB_FILE_OPTS.include?(opt)
        @options[opt] = file_list(@options[opt])
      end
      if opt == :install
        @options[:install] = parse_git_repos(@options[:install])
      end
    else
      @options[opt] = []
    end
  end

  #check for valid type
  if @options[:type] !~ /pe|git|foss|aio/
    parser_error "--type must be one of pe, git, foss, or aio not '#{@options[:type]}'"
  end

  #check for valid fail mode
  if @options[:fail_mode] !~ /stop|fast|slow/
    parser_error "--fail-mode must be one of fast or slow, not '#{@options[:fail_mode]}'"
  end

  #check for valid preserve_hosts option
  if @options[:preserve_hosts] !~ /always|onfail|onpass|never/
    parser_error "--preserve_hosts must be one of always, onfail, onpass or never, not '#{@options[:preserve_hosts]}'"
  end

  #check for config files necessary for different hypervisors
  hypervisors = []
  @options[:HOSTS].each_key do |name|
    hypervisors << @options[:HOSTS][name][:hypervisor].to_s
  end
  hypervisors.uniq!
  hypervisors.each do |visor|
    if ['blimpy'].include?(visor)
      check_yaml_file(@options[:ec2_yaml], "required by #{visor}")
    end
    if ['aix', 'solaris', 'vcloud'].include?(visor)
      check_yaml_file(@options[:dot_fog], "required by #{visor}")
    end
  end

  #check that roles of hosts make sense
  # - must be one and only one master
  roles = []
  @options[:HOSTS].each_key do |name|
    roles << @options[:HOSTS][name][:roles]
  end
  master = 0
  roles.each do |role_array|
    if role_array.include?('master')
      master += 1
    end
    if role_array.include?('frictionless') and !(role_array & ['master', 'database', 'dashboard', 'console']).empty?
      parser_error "Only agent nodes may have the role 'frictionless', fix #{@options[:hosts_file]}"
    end
  end
  if master > 1
    parser_error "Only one host/node may have the role 'master', fix #{@options[:hosts_file]}"
  end

  #check that solaris/windows/el-4 boxes are only agents
  @options[:HOSTS].each_key do |name|
    host = @options[:HOSTS][name]
    if (host[:platform] =~ /windows|el-4/) ||
       (@options.is_pe? && host[:platform] =~ /solaris/)

      test_host_roles(name, host)
    end
  end

  #set the default role
  set_default_host!(@options[:HOSTS])

end