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-12.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)



98
99
100
101
102
103
104
105
# File 'lib/kitchen/config.rb', line 98

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 }
  @log_root       = options.fetch(:log_root) { default_log_root }
  @test_base_path = options.fetch(:test_base_path) { default_test_base_path }
end

Instance Attribute Details

#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



54
55
56
# File 'lib/kitchen/config.rb', line 54

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



69
70
71
# File 'lib/kitchen/config.rb', line 69

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



73
74
75
# File 'lib/kitchen/config.rb', line 73

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



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

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



59
60
61
# File 'lib/kitchen/config.rb', line 59

def log_root
  @log_root
end

#test_base_pathString (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 containing test suites and other testing-related file and directories.

Returns:

  • (String)

    the absolute path to the directory containing test suites and other testing-related file and directories



64
65
66
# File 'lib/kitchen/config.rb', line 64

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



109
110
111
# File 'lib/kitchen/config.rb', line 109

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



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

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



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

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