diff options
author | Bryan McLellan <btm@opscode.com> | 2013-01-24 20:18:26 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-06-18 13:51:48 -0700 |
commit | 5ba4b559a726c8b297bbcfd55edfb4e4cb303645 (patch) | |
tree | 1d47b47ab5a4d7477846456cc50191246f8e773f | |
parent | 137874c445f808bb3d511c300313ed10cbd1f288 (diff) | |
download | chef-5ba4b559a726c8b297bbcfd55edfb4e4cb303645.tar.gz |
CHEF-3045: Re-provide lost support for no_lazy_load
Originally added in 1938b77, but the move of the cookbook sync code
in f880869c93 got messed up in bad merge b36f636
Also, add something test-like.
-rw-r--r-- | chef/lib/chef/cookbook/synchronizer.rb | 14 | ||||
-rw-r--r-- | chef/spec/unit/cookbook/synchronizer_spec.rb | 50 |
2 files changed, 57 insertions, 7 deletions
diff --git a/chef/lib/chef/cookbook/synchronizer.rb b/chef/lib/chef/cookbook/synchronizer.rb index 54cadb941c..4522323fac 100644 --- a/chef/lib/chef/cookbook/synchronizer.rb +++ b/chef/lib/chef/cookbook/synchronizer.rb @@ -56,12 +56,14 @@ class Chef # Synchronizes the locally cached copies of cookbooks with the files on the # server. class CookbookSynchronizer - EAGER_SEGMENTS = Chef::CookbookVersion::COOKBOOK_SEGMENTS.dup - EAGER_SEGMENTS.delete(:files) - EAGER_SEGMENTS.delete(:templates) - EAGER_SEGMENTS.freeze - def initialize(cookbooks_by_name, events) + @eager_segments = Chef::CookbookVersion::COOKBOOK_SEGMENTS.dup + unless Chef::Config[:no_lazy_load] + @eager_segments.delete(:files) + @eager_segments.delete(:templates) + end + @eager_segments.freeze + @cookbooks_by_name, @events = cookbooks_by_name, events end @@ -138,7 +140,7 @@ class Chef # files and templates are lazily loaded, and will be done later. - EAGER_SEGMENTS.each do |segment| + @eager_segments.each do |segment| segment_filenames = Array.new cookbook.manifest[segment].each do |manifest_record| diff --git a/chef/spec/unit/cookbook/synchronizer_spec.rb b/chef/spec/unit/cookbook/synchronizer_spec.rb index e84fd3cfc5..4c6aa0c0ed 100644 --- a/chef/spec/unit/cookbook/synchronizer_spec.rb +++ b/chef/spec/unit/cookbook/synchronizer_spec.rb @@ -63,6 +63,7 @@ describe Chef::CookbookSynchronizer do "checksum" => "abc456" } @cookbook_a_manifest["attributes"] = [ @cookbook_a_default_attrs ] @cookbook_a_manifest["templates"] = [{"path" => "templates/default/apache2.conf.erb", "url" => "http://chef.example.com/ffffff"}] + @cookbook_a_manifest["files"] = [{"path" => "files/default/megaman.conf", "url" => "http://chef.example.com/megaman.conf"}] @cookbook_a.manifest = @cookbook_a_manifest @cookbook_manifest["cookbook_a"] = @cookbook_a @@ -102,7 +103,7 @@ describe Chef::CookbookSynchronizer do before do # Would rather not stub out methods on the test subject, but setting up # the state is a PITA and tests for this behavior are above. - @synchronizer.should_receive(:clear_obsoleted_cookbooks) + @synchronizer.stub!(:clear_obsoleted_cookbooks) @server_api = mock("Chef::REST (mock)") @file_cache = mock("Chef::FileCache (mock)") @@ -162,6 +163,53 @@ describe Chef::CookbookSynchronizer do @synchronizer.sync_cookbooks end + context "Chef::Config[:no_lazy_load] is true" do + before do + Chef::Config[:no_lazy_load] = true + @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events) + @synchronizer.stub!(:server_api).and_return(@server_api) + @synchronizer.stub!(:cache).and_return(@file_cache) + @synchronizer.stub!(:clear_obsoleted_cookbooks) + + @cookbook_a_file_default_tempfile = mock("Tempfile for cookbook_a megaman.conf file", + :path => "/tmp/cookbook_a_file_default_tempfile") + @cookbook_a_template_default_tempfile = mock("Tempfile for cookbook_a apache.conf.erb template", + :path => "/tmp/cookbook_a_template_default_tempfile") + end + + after do + Chef::Config[:no_lazy_load] = false + end + + it "fetches templates and cookbook files" do + @file_cache.should_receive(:has_key?). + with("cookbooks/cookbook_a/files/default/megaman.conf"). + and_return(false) + @file_cache.should_receive(:has_key?). + with("cookbooks/cookbook_a/templates/default/apache2.conf.erb"). + and_return(false) + + @server_api.should_receive(:get_rest). + with('http://chef.example.com/megaman.conf', true). + and_return(@cookbook_a_file_default_tempfile) + @file_cache.should_receive(:move_to). + with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") + @file_cache.should_receive(:load). + with("cookbooks/cookbook_a/files/default/megaman.conf", false). + and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + + @server_api.should_receive(:get_rest). + with('http://chef.example.com/ffffff', true). + and_return(@cookbook_a_template_default_tempfile) + @file_cache.should_receive(:move_to). + with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") + @file_cache.should_receive(:load). + with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). + and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + + @synchronizer.sync_cookbooks + end + end end context "when the cache contains outdated files" do |