class Beaker::Options::Validator

def check_yaml_file(f, msg = '')

Raises:
  • (ArgumentError) - Raise if file does not exist or is not valid YAML

Parameters:
  • msg (String) -- An options message to report in case of error
  • f (String) -- The YAML file path to examine
def check_yaml_file(f, msg = '')
  validator_error "#{f} does not exist (#{msg})" unless File.file?(f)
  begin
    YAML.load_file(f)
  rescue Beaker::Options::Parser::PARSE_ERROR => e
    validator_error "#{f} is not a valid YAML file (#{msg})\n\t#{e}"
  end
end

def default_set?(default)

Returns:
  • (true, false) -

Parameters:
  • default (Array) -- list of host names
def default_set?(default)
  if default.empty?
    return false
  elsif default.length > 1
    validator_error "Only one host may have the role 'default', default roles assigned to #{default}"
  end
  true
end

def validate_fail_mode(fail_mode)

Returns:
  • (nil) - Does not return anything

Parameters:
  • fail_mode (String) -- Failure mode setting
def validate_fail_mode(fail_mode)
  # check for valid fail mode
  return if fail_mode.is_a?(String) && VALID_FAIL_MODES.match?(fail_mode)
  validator_error "--fail-mode must be one of fast or slow, not '#{fail_mode}'"
end

def validate_files(file_list, path)

Raises:
  • (ArgumentError) - Raises if file_list is empty

Parameters:
  • path (String) -- file path to report in error
  • file_list (Array) -- list of files
def validate_files(file_list, path)
  return unless file_list.empty?
  validator_error("No files found for path: '#{path}'")
end

def validate_frictionless_roles(role_array)

Raises:
  • (ArgumentError) - Raises if role_array contains conflicting roles

Parameters:
  • role_array (Array) -- List of roles
def validate_frictionless_roles(role_array)
  return unless role_array.include?(FRICTIONLESS_ROLE) and !(role_array & FRICTIONLESS_ADDITIONAL_ROLES).empty?
  validator_error "Only agent nodes may have the role 'frictionless'."
end

def validate_master_count(count)

Raises:
  • (ArgumentError) - Raises if master count is greater than 1

Returns:
  • (nil) - Nothing is returned

Parameters:
  • count (Integer) -- Count of roles with 'master'
def validate_master_count(count)
  return unless count > 1
  validator_error("Only one host/node may have the role 'master'.")
end

def validate_path(path)

Raises:
  • (ArgumentError) - Raises if path is not a valid file or directory

Parameters:
  • path (String) -- File path
def validate_path(path)
  return unless !File.file?(path) && !File.directory?(path)
  validator_error("#{path} used as a file option but is not a file or directory!")
end

def validate_platform(host, name)

Returns:
  • (nil) - Does not return anything

Parameters:
  • name (String) -- Host name
  • host (::Beaker::Host) -- A beaker host
def validate_platform(host, name)
  return unless !host['platform'] || host['platform'].empty?
  validator_error "Host #{name} does not have a platform specified"
end

def validate_preserve_hosts(hosts_setting)

Returns:
  • (nil) - Does not return anything

Parameters:
  • hosts_setting (String) -- Preserve hosts setting
def validate_preserve_hosts(hosts_setting)
  # check for valid preserve_hosts option
  return if hosts_setting.is_a?(String) && VALID_PRESERVE_HOSTS.match?(hosts_setting)
  validator_error("--preserve_hosts must be one of always, onfail, onpass or never, not '#{hosts_setting}'")
end

def validate_test_tags(tags_and, tags_or, tags_exclude)

Returns:
  • (nil) - Does not return anything

Parameters:
  • tags_exclude (Array) -- excluded items
  • tags_and (Array) -- included items

Other tags:
    Note: - see test tagging logic at {Beaker::DSL::TestTagging} module
def validate_test_tags(tags_and, tags_or, tags_exclude)
  validator_error "cannot have values for both test tagging operands (AND and OR)" if tags_and.length > 0 && tags_or.length > 0
  tags_and.each do |included_tag|
    # select items from exclude set that match included_tag
    # no match is an empty list/array/[]
    validator_error "tag '#{included_tag}' cannot be in both the included and excluded tag sets" if tags_exclude.select { |ex| ex == included_tag } != []
  end
end

def validator_error(msg = '')

Raises:
  • (ArgumentError) - Takes the supplied message and raises it as an ArgumentError

Parameters:
  • msg (String) -- The error message to be reported
def validator_error(msg = '')
  raise ArgumentError, msg.to_s
end