Skip to content

Commit e73e0d6

Browse files
author
Ivan
committed
Merge branch 'thommay/CHEF-505' of git://github.com/adamhjk/chef into CHEF-505
Conflicts: chef/lib/chef/role.rb
2 parents 94e6d75 + 9e337a7 commit e73e0d6

58 files changed

Lines changed: 707 additions & 252 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ namespace :features do
338338
Cucumber::Rake::Task.new(:run_interval) do |t|
339339
t.profile = "client_run_interval"
340340
end
341+
342+
Cucumber::Rake::Task.new(:cookbook_sync) do |t|
343+
t.profile = "client_cookbook_sync"
344+
end
341345
end
342346

343347
desc "Run cucumber tests for the cookbooks"
@@ -363,6 +367,9 @@ namespace :features do
363367
Cucumber::Rake::Task.new(:recipe_include) do |t|
364368
t.profile = "recipe_inclusion"
365369
end
370+
Cucumber::Rake::Task.new(:attribute_include) do |t|
371+
t.profile = "attribute_inclusion"
372+
end
366373
end
367374

368375
Cucumber::Rake::Task.new(:lwrp) do |t|

chef-server-api/Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ spec = Gem::Specification.new do |s|
2727
["merb-slices",
2828
"stomp",
2929
"stompserver",
30-
"ferret",
3130
"merb-core",
32-
"merb-haml",
3331
"merb-assets",
3432
"merb-helpers",
3533
"mongrel",
3634
"haml",
3735
"ruby-openid",
38-
"json",
39-
"syntax",].each { |g| s.add_dependency g}
36+
"json",
37+
"uuidtools",
38+
"nanite"
39+
].each { |g| s.add_dependency g}
4040

4141
s.require_path = 'lib'
4242
s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{config,lib,spec,app,public,stubs}/**/*")

chef-server-api/lib/chef-server-api.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
dependency 'merb-slices', :immediate => true
77
dependency 'chef', :immediate=>true unless defined?(Chef)
88
dependency 'nanite', :immediate=>true
9+
dependency 'uuidtools', :immediate=>true
910

1011
require 'chef/role'
1112
require 'chef/data_bag'
@@ -61,10 +62,20 @@ def self.activate
6162
Mixlib::Authentication::Log.logger = Nanite::Log.logger = Ohai::Log.logger = Chef::Log.logger
6263

6364
Thread.new do
64-
until EM.reactor_running?
65+
# Okay, we're here because if you run this with the thin adaptor, you
66+
# need to wait for EM to heat all the way up - and it won't, until
67+
# after activate is finished.
68+
sleep 1
69+
Chef::Nanite.in_event { Chef::Log.info("Nanite is ready") }
70+
71+
# This is because nanite needs to broadcast, and we don't know how long
72+
# that will take.
73+
sleep_time = 20
74+
while sleep_time != 0
75+
Chef::Log.debug("Waiting for Nanite to heat up.. #{sleep_time} seconds left")
76+
sleep_time = sleep_time - 1
6577
sleep 1
6678
end
67-
Chef::Nanite.in_event { Chef::Log.info("Nanite is ready") }
6879

6980
unless Merb::Config.environment == "test"
7081
# create the couch design docs for nodes, roles, and databags

chef-server/bin/chef-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require "merb-core"
2828

2929
[ 'chef', 'chef-server-api' ].each do |lib|
3030
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib")))
31-
library = File.join(File.dirname(__FILE__), "..", "..", lib, "lib", "#{lib}.rb")
31+
library = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", lib, "lib", "#{lib}.rb"))
3232
require library if File.exists?(library)
3333
end
3434

chef-server/config.ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'chef'
55
Chef::Config.from_file(File.join("/etc", "chef", "server.rb"))
66

77
Merb::Config.setup(:merb_root => File.expand_path(File.dirname(__FILE__)),
8-
:environment => ENV['RACK_ENV'],
8+
:environment => 'production',
99
:fork_for_class_load => false,
1010
:init_file => File.dirname(__FILE__) / "config/init.rb")
1111
Merb.environment = Merb::Config[:environment]

chef-server/config/init.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
Merb::Config.use do |c|
1515
c[:use_mutex] = false
16+
c[:fork_for_class_load] = false
1617
c[:log_level] = Chef::Config[:log_level]
1718
if Chef::Config[:log_location].kind_of?(String)
1819
c[:log_file] = Chef::Config[:log_location]

chef-solr/spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
$LOAD_PATH.unshift(File.dirname(__FILE__))
55
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'lib'))
67
require 'chef'
78
require 'chef/solr'
89
require 'chef/solr/index'

chef/lib/chef/cache.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
22
# Author:: Adam Jacob (<adam@opscode.com>)
3-
# Copyright:: Copyright (c) 2008 Opscode, Inc.
3+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
4+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
5+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
46
# License:: Apache License, Version 2.0
57
#
68
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,35 +20,33 @@
1820

1921
require 'chef/log'
2022
require 'chef/config'
23+
require 'chef/mixin/convert_to_class_name'
24+
require 'singleton'
2125
require 'moneta'
2226

2327
class Chef
2428
class Cache
25-
29+
include Chef::Mixin::ConvertToClassName
30+
include ::Singleton
31+
2632
attr_reader :moneta
27-
28-
def initialize(type=nil, options=nil)
29-
type ||= Chef::Config[:cache_type]
33+
34+
def initialize(*args)
35+
self.reset!(*args)
36+
end
37+
38+
def reset!(backend=nil, options=nil)
39+
backend ||= Chef::Config[:cache_type]
3040
options ||= Chef::Config[:cache_options]
31-
32-
if type == "BasicFile"
33-
require_type = "basic_file"
34-
else
35-
require_type = type.downcase
36-
end
37-
41+
3842
begin
39-
require "moneta/#{require_type}"
40-
rescue LoadError
41-
raise LoadError, "Cannot find a Moneta adaptor named #{require_type}!"
43+
require "moneta/#{convert_to_snake_case(backend, 'Moneta')}"
44+
rescue LoadError => e
45+
Chef::Log.fatal("Could not load Moneta back end #{backend.inspect}")
46+
raise e
4247
end
43-
44-
m = Moneta.const_get(type)
45-
@moneta = m.new(options)
46-
end
47-
48-
def method_missing(method, *args)
49-
@moneta.send(method, *args)
48+
49+
@moneta = Moneta.const_get(backend).new(options)
5050
end
5151

5252
end

chef/lib/chef/cache/checksum.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# Author:: Adam Jacob (<adam@opscode.com>)
3+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
4+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
5+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
6+
# License:: Apache License, Version 2.0
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
require 'chef/cache'
22+
23+
class Chef
24+
class Cache
25+
class Checksum < Chef::Cache
26+
27+
def self.checksum_for_file(*args)
28+
instance.checksum_for_file(*args)
29+
end
30+
31+
def checksum_for_file(file)
32+
key, fstat = filename_to_key(file), File.stat(file)
33+
lookup_checksum(key, fstat) || generate_checksum(key, file, fstat)
34+
end
35+
36+
def lookup_checksum(key, fstat)
37+
cached = @moneta.fetch(key)
38+
if cached && file_unchanged?(cached, fstat)
39+
cached["checksum"]
40+
else
41+
nil
42+
end
43+
end
44+
45+
def generate_checksum(key, file, fstat)
46+
checksum = checksum_file(file)
47+
moneta.store(key, {"mtime" => fstat.mtime.to_f, "checksum" => checksum})
48+
checksum
49+
end
50+
51+
private
52+
53+
def file_unchanged?(cached, fstat)
54+
cached["mtime"].to_f == fstat.mtime.to_f
55+
end
56+
57+
def checksum_file(file)
58+
digest = Digest::SHA256.new
59+
IO.foreach(file) {|line| digest.update(line) }
60+
digest.hexdigest
61+
end
62+
63+
def filename_to_key(file)
64+
"chef-file-#{file.gsub(/(#{File::SEPARATOR}|\.)/, '-')}"
65+
end
66+
67+
end
68+
end
69+
end
70+

chef/lib/chef/client.rb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,15 @@ def update_file_cache(cookbook_name, parts)
223223
current_checksum = checksum(Chef::FileCache.load(cache_file, false))
224224
end
225225

226-
rf_url = generate_cookbook_url(
227-
rf['name'],
228-
cookbook_name,
229-
segment,
230-
@node,
231-
current_checksum ? { 'checksum' => current_checksum } : nil
232-
)
233226
if current_checksum != rf['checksum']
227+
rf_url = generate_cookbook_url(
228+
rf['name'],
229+
cookbook_name,
230+
segment,
231+
@node,
232+
current_checksum ? { 'checksum' => current_checksum } : nil
233+
)
234+
234235
changed = true
235236
begin
236237
raw_file = @rest.get_rest(rf_url, true)
@@ -250,15 +251,15 @@ def update_file_cache(cookbook_name, parts)
250251
end
251252
end
252253

253-
Chef::FileCache.list.each do |cache_file|
254-
if cache_file =~ /^cookbooks\/(recipes|attributes|definitions|libraries)\//
255-
unless file_canonical[cache_file]
256-
Chef::Log.info("Removing #{cache_file} from the cache; it is no longer on the server.")
257-
Chef::FileCache.delete(cache_file)
258-
end
254+
end
255+
256+
Chef::FileCache.list.each do |cache_file|
257+
if cache_file =~ /^cookbooks\/#{cookbook_name}\/(recipes|attributes|definitions|libraries|resources|providers)\//
258+
unless file_canonical[cache_file]
259+
Chef::Log.info("Removing #{cache_file} from the cache; it is no longer on the server.")
260+
Chef::FileCache.delete(cache_file)
259261
end
260262
end
261-
262263
end
263264

264265
end
@@ -271,6 +272,14 @@ def sync_cookbooks
271272
Chef::Log.debug("Synchronizing cookbooks")
272273
cookbook_hash = @rest.get_rest("nodes/#{@safe_name}/cookbooks")
273274
Chef::Log.debug("Cookbooks to load: #{cookbook_hash.inspect}")
275+
Chef::FileCache.list.each do |cache_file|
276+
if cache_file =~ /^cookbooks\/(.+?)\//
277+
unless cookbook_hash.has_key?($1)
278+
Chef::Log.info("Removing #{cache_file} from the cache; it's cookbook is no longer needed on this client.")
279+
Chef::FileCache.delete(cache_file)
280+
end
281+
end
282+
end
274283
cookbook_hash.each do |cookbook_name, parts|
275284
update_file_cache(cookbook_name, parts)
276285
end

0 commit comments

Comments
 (0)