From 4ea42e7fe5377547cbb802ff0233307a5e444820 Mon Sep 17 00:00:00 2001 From: Daniel DeLeo Date: Mon, 25 Jun 2012 15:33:05 -0700 Subject: [PATCH] keep track of where run list items came from. This can be used to do things like show a tree of a run list expansion. --- chef/lib/chef/run_list/run_list_expansion.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chef/lib/chef/run_list/run_list_expansion.rb b/chef/lib/chef/run_list/run_list_expansion.rb index d4bad472a97..690eb3392b9 100644 --- a/chef/lib/chef/run_list/run_list_expansion.rb +++ b/chef/lib/chef/run_list/run_list_expansion.rb @@ -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 @@ -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)? @@ -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) @@ -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