Skip to content

Commit c61a910

Browse files
author
Ezra Zygmuntowicz
committed
Merge branch 'master' of git@github.com:hjkp/chef
2 parents b29f17c + 9952ec4 commit c61a910

35 files changed

Lines changed: 215 additions & 132 deletions

chef-server/lib/controllers/application.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
require "chef" / "mixin" / "checksum"
2020

21-
2221
class Application < Merb::Controller
2322

2423
def fix_up_node_id

chef-server/lib/controllers/cookbook_files.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def load_cookbook_files()
4242
:file => full,
4343
}
4444
end
45+
Chef::Log.debug("Remote files found: #{@remote_files.inspect}")
4546
@remote_files
4647
end
4748

@@ -72,7 +73,6 @@ def show
7273
end
7374

7475
def show_directory
75-
Chef::Log.info("totally rocking hte show_directory")
7676
dir_to_send = find_preferred_file
7777
unless (dir_to_send && File.directory?(dir_to_send))
7878
raise NotFound, "Cannot find a suitable directory"

chef-server/lib/controllers/openid_register.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def show
4141
raise e
4242
end
4343
end
44-
Merb.logger.debug(@registered_node.inspect)
44+
Chef::Log.debug(@registered_node.inspect)
4545
display @registered_node
4646
end
4747

chef-server/lib/controllers/openid_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def decision
141141
session[:last_oidreq] = nil
142142

143143
if params.has_key?(:cancel)
144-
Merb.logger.info("Cancelling OpenID Authentication")
144+
Chef::Log.info("Cancelling OpenID Authentication")
145145
return(redirect(oidreq.cancel_url))
146146
else
147147
identity = oidreq.identity

chef-server/lib/init.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
c[:log_stream] = STDOUT
152152
end
153153

154-
Merb.logger.info("Compiling routes...")
154+
Chef::Log.info("Compiling routes...")
155155
Merb::Router.prepare do |r|
156156
# RESTful routes
157157
# r.resources :posts
@@ -169,7 +169,7 @@
169169
match("/cookbooks/_attribute_files").to(:controller => "cookbooks", :action => "attribute_files")
170170
match("/cookbooks/_recipe_files").to(:controller => "cookbooks", :action => "recipe_files")
171171
match("/cookbooks/_definition_files").to(:controller => "cookbooks", :action => "definition_files")
172-
Merb.logger.info("Seriously, what the fuck")
172+
Chef::Log.info("Seriously, what the fuck")
173173
match("/cookbooks/_library_files").to(:controller => "cookbooks", :action => "library_files")
174174

175175
# r.match("/cookbooks/:cookbook_id/templates").to(:controller => "cookbook_templates", :action => "index")
@@ -208,5 +208,3 @@
208208
# Change this for your home page to be available at /
209209
match('/').to(:controller => 'nodes', :action =>'index').name(:top)
210210
end
211-
212-
puts "I have loaded my app?"

chef/lib/chef/client.rb

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def run
6161
build_node
6262
register
6363
authenticate
64+
sync_library_files
65+
sync_attribute_files
6466
sync_definitions
6567
sync_recipes
66-
do_library_files
67-
do_attribute_files
6868
save_node
6969
converge
7070
save_node
@@ -75,9 +75,15 @@ def run
7575
end
7676

7777
def run_solo
78+
start_time = Time.now
79+
Chef::Log.info("Starting Chef Solo Run")
80+
7881
build_node
7982
do_attribute_files
8083
converge
84+
85+
end_time = Time.now
86+
Chef::Log.info("Chef Run complete in #{end_time - start_time} seconds")
8187
true
8288
end
8389

@@ -246,15 +252,9 @@ def update_file_cache(segment, remote_list)
246252
#
247253
# === Returns
248254
# true:: Always returns true
249-
def do_attribute_files
255+
def sync_attribute_files
250256
Chef::Log.debug("Synchronizing attributes")
251257
update_file_cache("attributes", @rest.get_rest('cookbooks/_attribute_files'))
252-
Chef::FileCache.list.sort.each do |cache_file|
253-
if cache_file.match("cookbooks/.+?/attributes")
254-
Chef::Log.debug("Executing #{cache_file}")
255-
@node.from_file(Chef::FileCache.load(cache_file, false))
256-
end
257-
end
258258
true
259259
end
260260

@@ -263,15 +263,9 @@ def do_attribute_files
263263
#
264264
# === Returns
265265
# true:: Always returns true
266-
def do_library_files
266+
def sync_library_files
267267
Chef::Log.debug("Synchronizing libraries")
268268
update_file_cache("libraries", @rest.get_rest('cookbooks/_library_files'))
269-
Chef::FileCache.list.each do |cache_file|
270-
if cache_file.match("cookbooks/.+?/libraries")
271-
Chef::Log.debug("Requiring #{cache_file}")
272-
require Chef::FileCache.load(cache_file, false)
273-
end
274-
end
275269
true
276270
end
277271

@@ -305,10 +299,12 @@ def converge
305299
Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")
306300
compile = Chef::Compile.new()
307301
compile.node = @node
302+
compile.load_libraries
303+
compile.load_attributes
308304
compile.load_definitions
309305
compile.load_recipes
310306

311-
Chef::Log.debug("Executing recipes for node #{@safe_name}")
307+
Chef::Log.debug("Converging node #{@safe_name}")
312308
cr = Chef::Runner.new(@node, compile.collection)
313309
cr.converge
314310
true

chef/lib/chef/compile.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def load_node(name)
4141
@node
4242
end
4343

44+
# Load all the attributes, from every cookbook
45+
def load_attributes()
46+
@cookbook_loader.each do |cookbook|
47+
cookbook.load_attributes(@node)
48+
end
49+
true
50+
end
51+
4452
# Load all the definitions, from every cookbook, so they are available when we process
4553
# the recipes.
4654
#
@@ -52,12 +60,23 @@ def load_definitions()
5260
end
5361
end
5462

63+
# Load all the libraries, from every cookbook, so they are available when we process
64+
# the recipes.
65+
#
66+
def load_libraries()
67+
@cookbook_loader.each do |cookbook|
68+
cookbook.load_libraries
69+
end
70+
true
71+
end
72+
5573
# Load all the recipes specified in the node data (loaded via load_node, above.)
5674
#
5775
# The results are available via the collection accessor (which returns a Chef::ResourceCollection
5876
# object)
5977
def load_recipes
6078
@node.recipes.each do |recipe|
79+
Chef::Log.debug("Loading Recipe #{recipe}")
6180
rmatch = recipe.match(/(.+?)::(.+)/)
6281
if rmatch
6382
cookbook = @cookbook_loader[rmatch[1]]

chef/lib/chef/cookbook.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ def initialize(name)
3131
@recipe_files = Array.new
3232
@recipe_names = Hash.new
3333
@lib_files = Array.new
34-
@loaded_attributes = false
3534
end
3635

37-
def load_libs
36+
def load_libraries
3837
@lib_files.each do |file|
3938
Chef::Log.debug("Loading cookbook #{name} library file: #{file}")
4039
require file
@@ -46,9 +45,9 @@ def load_attributes(node)
4645
raise ArgumentError, "You must pass a Chef::Node to load_attributes!"
4746
end
4847
@attribute_files.each do |file|
48+
Chef::Log.debug("Loading attributes from #{file}")
4949
node.from_file(file)
5050
end
51-
@loaded_atributes = true
5251
node
5352
end
5453

@@ -107,9 +106,6 @@ def load_recipe(name, node, collection=nil, definitions=nil, cookbook_loader=nil
107106
raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{@name}"
108107
end
109108
Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{cookbook_name}") if Chef::Log.debug?
110-
unless @loaded_attributes
111-
load_attributes(node)
112-
end
113109
recipe = Chef::Recipe.new(cookbook_name, recipe_name, node,
114110
collection, definitions, cookbook_loader)
115111
recipe.from_file(@recipe_files[@recipe_names[recipe_name]])

chef/lib/chef/log.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Log
2323
@logger = nil
2424

2525
class << self
26-
attr_reader :logger #:nodoc
26+
attr_accessor :logger #:nodoc
2727

2828
# Use Chef::Logger.init when you want to set up the logger manually. Arguments to this method
2929
# get passed directly to Logger.new, so check out the documentation for the standard Logger class

chef/lib/chef/node.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ def method_missing(symbol, *args)
179179

180180
def to_index
181181
index_hash = {
182-
:index_name => "node",
183-
:id => "node_#{@name}",
184-
:name => @name,
182+
"index_name" => "node",
183+
"id" => "node_#{@name}",
184+
"name" => @name,
185185
}
186186
@attribute.each do |key, value|
187187
index_hash[key] = value
188188
end
189-
index_hash[:recipe] = @recipe_list if @recipe_list.length > 0
189+
index_hash["recipe"] = @recipe_list if @recipe_list.length > 0
190190
index_hash
191191
end
192192

0 commit comments

Comments
 (0)