class Kitchen::Diagnostic
Combines and compiles diagnostic information about a Test Kitchen
configuration suitable for support and troubleshooting.
@author Fletcher Nichol <fnichol@nichol.ca>
Attributes
@return [Array<#diagnose>,Hash] an Array of instances that respond to
`#diagnose` or an error Hash
@api private
@return [#diagnose,Hash] a loader instance that responds to `#diagnose`
or an error Hash
@api private
@return [Hash] a result hash @api private
Public Class Methods
Constructs a new Diagnostic
object with an optional loader and optional instances array.
@param options [Hash] optional configuration @option options [#diagnose,Hash] :loader a loader instance that responds
to `#diagnose` or an error Hash
@option options [Array<#diagnose>,Hash] :instances an Array of instances
that respond to `#diagnose` or an error Hash
@option options [true,false] :plugins whether or not plugins should be
returned
# File lib/kitchen/diagnostic.rb, line 37 def initialize(options = {}) @loader = options.fetch(:loader, nil) @instances = options.fetch(:instances, []) @plugins = options.fetch(:plugins, false) @result = {} end
Public Instance Methods
Private Instance Methods
Determins whether or not the object is an error hash. An error hash is defined as a Hash
containing an `:error` key.
@param obj [Object] an object @return [true,false] whether or not the object is an error hash @api private
# File lib/kitchen/diagnostic.rb, line 134 def error_hash?(obj) obj.is_a?(Hash) && obj.key?(:error) end
Adds common information to the result Hash
.
@api private
# File lib/kitchen/diagnostic.rb, line 75 def prepare_common result[:timestamp] = Time.now.gmtime.to_s result[:kitchen_version] = Kitchen::VERSION end
Adds instance information to the result Hash
.
@api private
# File lib/kitchen/diagnostic.rb, line 119 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
Adds loader information to the result Hash
.
@api private
# File lib/kitchen/diagnostic.rb, line 83 def prepare_loader if error_hash?(loader) result[:loader] = loader else result[:loader] = loader.diagnose if loader end end
Adds plugin information to the result Hash
.
@api private
# File lib/kitchen/diagnostic.rb, line 94 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