Skip to content

Commit

Permalink
keep track of where run list items came from.
Browse files Browse the repository at this point in the history
This can be used to do things like show a tree of a run list expansion.
  • Loading branch information
danielsdeleo committed Jun 25, 2012
1 parent 7928f28 commit 4ea42e7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion chef/lib/chef/run_list/run_list_expansion.rb
Expand Up @@ -49,6 +49,12 @@ class RunListExpansion
# to fetch roles from their correct location.
attr_reader :source

# Returns a Hash of the form "including_role" => "included_role_or_recipe".
# This can be used to show the expanded run list (ordered) graph.
# ==== Caveats
# * Duplicate roles are not shown.
attr_reader :run_list_trace

def initialize(environment, run_list_items, source=nil)
@environment = environment
@missing_roles_with_including_role = Array.new
Expand All @@ -62,6 +68,7 @@ def initialize(environment, run_list_items, source=nil)
@recipes = Chef::RunList::VersionedRecipeList.new

@applied_roles = {}
@run_list_trace = Hash.new {|h, key| h[key] = [] }
end

# Did we find any errors (expanding roles)?
Expand Down Expand Up @@ -135,6 +142,8 @@ def applied_role(role_name)

def expand_run_list_items(items, included_by="top level")
if entry = items.shift
@run_list_trace[included_by.to_s] << entry.to_s

case entry.type
when :recipe
recipes.add_recipe(entry.name, entry.version)
Expand All @@ -144,7 +153,7 @@ def expand_run_list_items(items, included_by="top level")
apply_role_attributes(role)
end
end
expand_run_list_items(items)
expand_run_list_items(items, included_by)
end
end

Expand Down

0 comments on commit 4ea42e7

Please sign in to comment.