Skip to content

Commit 2ec7804

Browse files
Thom MaySeth Falcon
authored andcommitted
Serve the correct cookbook version
This is pretty YAGNI right now - it doesn't deal with versioned dependencies at all, but allows you to put "recipe[foo,1.2]" on the runlist and get the foo cookbook at version 1.2 on the node.
1 parent 52e6228 commit 2ec7804

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

chef-server-api/app/controllers/nodes.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ def load_all_files
108108
# returns name -> CookbookVersion for all cookbooks included on the given node.
109109
def cookbooks_for_node(all_cookbooks)
110110
# expand returns a RunListExpansion which contains recipes, default and override attrs [cb]
111-
recipes = @node.run_list.expand('couchdb').recipes
111+
items = @node.run_list.expand('couchdb').run_list_items
112112

113113
# walk run list and accumulate included dependencies
114-
recipes.inject({}) do |included_cookbooks, recipe|
115-
expand_cookbook_deps(included_cookbooks, all_cookbooks, recipe)
114+
items.inject({}) do |included_cookbooks, rli|
115+
next unless rli.recipe?
116+
expand_cookbook_deps(included_cookbooks, all_cookbooks, rli)
116117
included_cookbooks
117118
end
118119
end
@@ -125,12 +126,18 @@ def cookbooks_for_node(all_cookbooks)
125126
# run_list_items == name of cookbook to include
126127
def expand_cookbook_deps(included_cookbooks, all_cookbooks, run_list_item)
127128
# determine the run list item's parent cookbook, which might be run_list_item in the default case
128-
cookbook_name = (run_list_item[/^(.+)::/, 1] || run_list_item.to_s)
129-
Chef::Log.debug("Node requires #{cookbook_name}")
129+
version = "latest"
130+
if run_list_item.kind_of? Chef::RunList::RunListItem
131+
cookbook_name = (run_list_item.name[/^(.+)::/, 1] || run_list_item.name)
132+
version = run_list_item.version unless run_list_item.version.nil?
133+
else
134+
cookbook_name = (run_list_item[/^(.+)::/, 1] || run_list_item.to_s)
135+
end
130136

137+
Chef::Log.debug("Node requires #{cookbook_name} at #{version}")
131138
# include its dependencies
132-
included_cookbooks[cookbook_name] = all_cookbooks[cookbook_name]
133-
if !all_cookbooks[cookbook_name]
139+
included_cookbooks[cookbook_name] = Chef::CookbookVersion.cdb_load(cookbook_name, version)
140+
if !included_cookbooks[cookbook_name]
134141
return false
135142
# NOTE [dan/cw] We don't think changing this to an exception breaks stuff.
136143
# Chef::Log.warn "#{__FILE__}:#{__LINE__}: in expand_cookbook_deps, cookbook/role #{cookbook_name} could not be found, ignoring it in cookbook expansion"
@@ -139,7 +146,7 @@ def expand_cookbook_deps(included_cookbooks, all_cookbooks, run_list_item)
139146

140147
# TODO: 5/27/2010 cw: implement dep_version_constraints according to
141148
# http://wiki.opscode.com/display/chef/Metadata#Metadata-depends,
142-
all_cookbooks[cookbook_name].metadata.dependencies.each do |depname, dep_version_constraints|
149+
included_cookbooks[cookbook_name].metadata.dependencies.each do |depname, dep_version_constraints|
143150
# recursively expand dependencies into included_cookbooks unless
144151
# we've already done it
145152
unless included_cookbooks[depname]

0 commit comments

Comments
 (0)