Class: Kitchen::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/config.rb

Overview

Base configuration class for Kitchen. This class exposes configuration such as the location of the Kitchen config file, instances, log_levels, etc. This object is a factory object, meaning that it is responsible for consuming the desired testing configuration in and returning Ruby objects which are used to perfom the work.

Most internal objects are created with the expectation of being immutable, meaning that internal state cannot be modified after creation. Any data manipulation or thread-unsafe activity is performed in this object so that the subsequently created objects (such as Instances, Platforms, Drivers, etc.) can safely run in concurrent threads of execution. To prevent the re-creation of duplicate objects, most created objects are memoized. The consequence of this is that once the Instance Array has been requested (with the ‘#instances` message), you will always be returned the same Instance objects.

Examples:

fetching all instances


Kitchen::Config.new.instances

fetching an instance by name


Kitchen::Config.new.instances.get("default-ubuntu-16.04")

fetching all instances matching a regular expression


Kitchen::Config.new.instances.get_all(/ubuntu/)

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Creates a new configuration, representing a particular testing configuration for a project.

Parameters:

  • options (Hash) (defaults to: {})

    configuration

Options Hash (options):

  • :loader (#read)

    an object that responds to ‘#read` with a Hash structure suitable for manipulating (default: `Kitchen::Loader::YAML.new`)

  • :kitchen_root (String)

    an absolute path to the root of a Test Kitchen project, usually containing a ‘.kitchen.yml` file (default `Dir.pwd`)

  • :log_root (String)

    an absolute path to the directory into which all Test Kitchen log files will be written (default: ‘“##kitchen_root/.kitchen/logs”`)

  • :test_base_path (String)

    an absolute path to the directory containing test suites and other testing-related files and directories (default: ‘“##kitchen_root/test/integration”`)

  • :log_level (Symbol)

    the log level verbosity that the loggers will use when outputing information (default: ‘:info`)



103
104
105
106
107
108
109
110
111
112
# File 'lib/kitchen/config.rb', line 103

def initialize(options = {})
  @loader         = options.fetch(:loader) { Kitchen::Loader::YAML.new }
  @kitchen_root   = options.fetch(:kitchen_root) { Dir.pwd }
  @log_level      = options.fetch(:log_level) { Kitchen::DEFAULT_LOG_LEVEL }
  @log_overwrite  = options.fetch(:log_overwrite) { Kitchen::DEFAULT_LOG_OVERWRITE }
  @colorize       = options.fetch(:colorize) { Kitchen.tty? }
  @log_root       = options.fetch(:log_root) { default_log_root }
  @test_base_path = options.fetch(:test_base_path) { default_test_base_path }
  @debug          = options.fetch(:debug) { false }
end

Instance Attribute Details

#colorizeBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether to force color output or not in logger.

Returns:

  • (Boolean)

    whether to force color output or not in logger



79
80
81
# File 'lib/kitchen/config.rb', line 79

def colorize
  @colorize
end

#debugBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether to enable debugging in the provisioner/verifier plugin or not.

Returns:

  • (Boolean)

    whether to enable debugging in the provisioner/verifier plugin or not



83
84
85
# File 'lib/kitchen/config.rb', line 83

def debug
  @debug
end

#kitchen_rootString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the absolute path to the root of a Test Kitchen project.

Returns:

  • (String)

    the absolute path to the root of a Test Kitchen project



52
53
54
# File 'lib/kitchen/config.rb', line 52

def kitchen_root
  @kitchen_root
end

#loader#read (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The data loader that responds to a ‘#read` message, returning a Hash data structure

Returns:

  • (#read)

    the data loader that responds to a ‘#read` message, returning a Hash data structure



62
63
64
# File 'lib/kitchen/config.rb', line 62

def loader
  @loader
end

#log_levelSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the logging verbosity level.

Returns:

  • (Symbol)

    the logging verbosity level



66
67
68
# File 'lib/kitchen/config.rb', line 66

def log_level
  @log_level
end

#log_overwriteBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether to overwrite the log file when Test Kitchen runs.

Returns:

  • (Boolean)

    whether to overwrite the log file when Test Kitchen runs



71
72
73
# File 'lib/kitchen/config.rb', line 71

def log_overwrite
  @log_overwrite
end

#log_rootString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the absolute path to the directory into which all Test Kitchen log files will be written.

Returns:

  • (String)

    the absolute path to the directory into which all Test Kitchen log files will be written



57
58
59
# File 'lib/kitchen/config.rb', line 57

def log_root
  @log_root
end

#test_base_pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an absolute path to the directory containing test suites.

Returns:

  • (String)

    an absolute path to the directory containing test suites



75
76
77
# File 'lib/kitchen/config.rb', line 75

def test_base_path
  @test_base_path
end

Instance Method Details

#instancesCollection<Instance>

Returns all instances, resulting from all platform and suite combinations.

Returns:

  • (Collection<Instance>)

    all instances, resulting from all platform and suite combinations



116
117
118
# File 'lib/kitchen/config.rb', line 116

def instances
  @instances ||= Collection.new(build_instances)
end

#platformsCollection<Platform>

Returns all defined platforms which will be used in convergence integration.

Returns:

  • (Collection<Platform>)

    all defined platforms which will be used in convergence integration



122
123
124
125
# File 'lib/kitchen/config.rb', line 122

def platforms
  @platforms ||= Collection.new(
    data.platform_data.map { |pdata| Platform.new(pdata) })
end

#suitesCollection<Suite>

Returns all defined suites which will be used in convergence integration.

Returns:

  • (Collection<Suite>)

    all defined suites which will be used in convergence integration



129
130
131
132
# File 'lib/kitchen/config.rb', line 129

def suites
  @suites ||= Collection.new(
    data.suite_data.map { |sdata| Suite.new(sdata) })
end