class Kitchen::Diagnostic

@author Fletcher Nichol <fnichol@nichol.ca>
configuration suitable for support and troubleshooting.
Combines and compiles diagnostic information about a Test Kitchen

def error_hash?(obj)

Other tags:
    Api: - private

Returns:
  • (true, false) - whether or not the object is an error hash

Parameters:
  • obj (Object) -- an object
def error_hash?(obj)
  obj.is_a?(Hash) && obj.key?(:error)
end

def initialize(options = {})

Options Hash: (**options)
  • :plugins (true, false) -- whether or not plugins should be
  • :instances (Array<#diagnose>, Hash) -- an Array of instances
  • :loader (#diagnose, Hash) -- a loader instance that responds

Parameters:
  • options (Hash) -- optional configuration
def initialize(options = {})
  @loader = options.fetch(:loader, nil)
  @instances = options.fetch(:instances, [])
  @plugins = options.fetch(:plugins, false)
  @result = {}
end

def prepare_common

Other tags:
    Api: - private
def prepare_common
  result[:timestamp] = Time.now.gmtime.to_s
  result[:kitchen_version] = Kitchen::VERSION
end

def prepare_instances

Other tags:
    Api: - private
def prepare_instances
  result[:instances] = {}
  if error_hash?(instances)
    result[:instances][:error] = instances[:error]
  else
    Array(instances).each { |i| result[:instances][i.name] = i.diagnose }
  end
end

def prepare_loader

Other tags:
    Api: - private
def prepare_loader
  if error_hash?(loader)
    result[:loader] = loader
  else
    result[:loader] = loader.diagnose if loader
  end
end

def prepare_plugins

Other tags:
    Api: - private
def prepare_plugins
  return unless @plugins
  if error_hash?(instances)
    result[:plugins] = { error: instances[:error] }
  elsif instances.empty?
    result[:plugins] = {}
  else
    plugins = {
      driver: [], provisioner: [], transport: [], verifier: []
    }
    instances.map(&:diagnose_plugins).each do |plugin_hash|
      plugin_hash.each { |type, plugin| plugins[type] << plugin }
    end
    plugins.each do |type, list|
      plugins[type] =
        Hash[list.uniq.map { |hash| [hash.delete(:name), hash] }]
    end
    result[:plugins] = plugins
  end
end

def read

Returns:
  • (Hash) - a configuration Hash
def read
  prepare_common
  prepare_plugins
  prepare_loader
  prepare_instances
  Util.stringified_hash(result)
end