Skip to content

Instantly share code, notes, and snippets.

@brandocorp
Last active October 17, 2016 19:32
Show Gist options
  • Save brandocorp/8ad5910da9068705282cce6b9d456cc2 to your computer and use it in GitHub Desktop.
Save brandocorp/8ad5910da9068705282cce6b9d456cc2 to your computer and use it in GitHub Desktop.
chef-resource-and-attribute-debugging
require 'pp'
class Chef
class Node
attr_accessor :chef_callers
def cumulative_callers
@chef_callers ||= {
'accessor' => [],
'normal' => [],
'default' => []
}
end
def filter_caller(stack, type)
cumulative_callers[type] << stack.select {|trace| trace =~ %r{/tmp/kitchen/cache/cookbooks} }.first
stack.select {|trace| trace =~ %r{/tmp/kitchen/cache/cookbooks/(postgresql|ge-postgres|ge-postgres-cluster)} }.first
end
# def [](attrib)
# Chef::Log.warn(filter_caller(caller, 'accessor'))
# Chef::Log.warn("Accessing node['#{attrib}']")
# Chef::Log.warn("Value:\n #{attributes[attrib]}")
# attributes[attrib]
# end
def default
attributes.top_level_breadcrumb = nil
# Chef::Log.warn(filter_caller(caller, 'default'))
# Chef::Log.warn(cumulative_callers)
Chef::Log.warn("Accessing Default Attributes")
# Chef::Log.warn("Value:\n #{attributes.default}")
attributes.default
end
def normal
attributes.top_level_breadcrumb = nil
# Chef::Log.warn(filter_caller(caller, 'normal'))
# Chef::Log.warn(cumulative_callers['normal'])
Chef::Log.warn("Accessing Normal Attributes")
# Chef::Log.warn("Value:\n #{attributes.normal}")
attributes.normal
end
def override
attributes.top_level_breadcrumb = nil
# Chef::Log.warn(filter_caller(caller, 'override'))
# Chef::Log.warn(cumulative_callers['override'])
Chef::Log.warn("Accessing Override Attributes")
# Chef::Log.warn("Value:\n #{attributes.override}")
attributes.override
end
end
end
class Chef
class ResourceCollection
old_insert = instance_method(:insert)
define_method(:insert) do |resource, opts={}|
Chef::Log.warn "Created: #{resource}"
old_insert.bind(self).(resource, opts)
end
end
class Provider
old_run_action = instance_method(:run_action)
define_method(:run_action) do |*args|
Chef::Log.warn new_resource.to_text
old_run_action.bind(self).(*args)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment