class Beaker::Options::Validator

Constants

FRICTIONLESS_ADDITIONAL_ROLES
FRICTIONLESS_ROLE
VALID_FAIL_MODES
VALID_PRESERVE_HOSTS

Public Instance Methods

check_yaml_file(f, msg = '') click to toggle source

Determine is a given file exists and is a valid YAML file @param [String] f The YAML file path to examine @param [String] msg An options message to report in case of error @raise [ArgumentError] Raise if file does not exist or is not valid YAML

# File lib/beaker/options/validator.rb, line 13
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
default_set?(default) click to toggle source

Raises an ArgumentError if more than one default exists, otherwise returns true or false if default is set.

@param [Array<String>] default list of host names @return [true, false]

# File lib/beaker/options/validator.rb, line 38
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
parser_error(msg = '')

alias to keep old methods and functionality from throwing errors.

Alias for: validator_error
validate_fail_mode(fail_mode) click to toggle source

Raises an error if fail_mode is not a supported failure mode.

@param [String] fail_mode Failure mode setting @return [nil] Does not return anything

# File lib/beaker/options/validator.rb, line 52
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
validate_files(file_list, path) click to toggle source

Raise an error if file_list is empty

@param [Array<String>] file_list list of files @param [String] path file path to report in error @raise [ArgumentError] Raises if file_list is empty

# File lib/beaker/options/validator.rb, line 124
def validate_files(file_list, path)
  return unless file_list.empty?

  validator_error("No files found for path: '#{path}'")
end
validate_frictionless_roles(role_array) click to toggle source

Raises an error if role_array contains the frictionless role and conflicting roles.

@param [Array<String>] role_array List of roles @raise [ArgumentError] Raises if role_array contains conflicting roles

# File lib/beaker/options/validator.rb, line 102
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
validate_master_count(count) click to toggle source

Raise an error if the master count is incorrect.

@param [Integer] count Count of roles with ‘master’ @return [nil] Nothing is returned @raise [ArgumentError] Raises if master count is greater than 1

# File lib/beaker/options/validator.rb, line 113
def validate_master_count(count)
  return unless count > 1

  validator_error("Only one host/node may have the role 'master'.")
end
validate_path(path) click to toggle source

Raise an error if path is not a valid file or directory

@param [String] path File path @raise [ArgumentError] Raises if path is not a valid file or directory

# File lib/beaker/options/validator.rb, line 134
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
validate_platform(host, name) click to toggle source

Raise an error if host does not have a platform defined.

@param [::Beaker::Host] host A beaker host @param [String] name Host name @return [nil] Does not return anything

# File lib/beaker/options/validator.rb, line 75
def validate_platform(host, name)
  return unless !host['platform'] || host['platform'].empty?

  validator_error "Host #{name} does not have a platform specified"
end
validate_preserve_hosts(hosts_setting) click to toggle source

Raises an error if hosts_setting is not a supported preserve hosts value.

@param [String] hosts_setting Preserve hosts setting @return [nil] Does not return anything

# File lib/beaker/options/validator.rb, line 63
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
validate_test_tags(tags_and, tags_or, tags_exclude) click to toggle source

Raise an error if an item exists in both the include and exclude lists.

@note see test tagging logic at {Beaker::DSL::TestTagging} module

@param [Array] tags_and included items @param [Array] tags_exclude excluded items @return [nil] Does not return anything

# File lib/beaker/options/validator.rb, line 88
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
validator_error(msg = '') click to toggle source

Raises an ArgumentError with associated message @param [String] msg The error message to be reported @raise [ArgumentError] Takes the supplied message and raises it as an ArgumentError

# File lib/beaker/options/validator.rb, line 26
def validator_error(msg = '')
  raise ArgumentError, msg.to_s
end
Also aliased as: parser_error