From 3756a09333bce1644babe0ed05d8725d364d9c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Magnus=20Rakv=C3=A5g?= Date: Thu, 28 Sep 2017 11:08:00 +0200 Subject: only warn about skipping sync once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tor Magnus Rakvåg --- lib/chef/cookbook/synchronizer.rb | 6 ++---- spec/unit/cookbook/synchronizer_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index ed6b1d9700..991e418f99 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -154,6 +154,7 @@ class Chef queue = Chef::Util::ThreadedJobQueue.new + Chef::Log.warn("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!") if Chef::Config[:skip_cookbook_sync] files.each do |file| queue << lambda do |lock| full_file_path = sync_file(file) @@ -279,10 +280,7 @@ class Chef end def cached_copy_up_to_date?(local_path, expected_checksum) - if Chef::Config[:skip_cookbook_sync] - Chef::Log.warn "skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!" - return true - end + return true if Chef::Config[:skip_cookbook_sync] if cache.has_key?(local_path) current_checksum = CookbookVersion.checksum_cookbook_file(cache.load(local_path, false)) expected_checksum == current_checksum diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index 6578a9e670..d55c840269 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -116,9 +116,12 @@ describe Chef::CookbookSynchronizer do let(:no_lazy_load) { true } + let(:skip_cookbook_sync) { false } + let(:synchronizer) do Chef::Config[:no_lazy_load] = no_lazy_load Chef::Config[:file_cache_path] = "/file-cache" + Chef::Config[:skip_cookbook_sync] = skip_cookbook_sync Chef::CookbookSynchronizer.new(cookbook_manifest, events) end @@ -523,5 +526,30 @@ describe Chef::CookbookSynchronizer do end end end + + context "when Chef::Config[:skip_cookbook_sync] is true" do + let(:skip_cookbook_sync) { true } + + it "loads the cookbook files and warns the user that this isn't supported" do + expect(file_cache).to receive(:load). + with("cookbooks/cookbook_a/recipes/default.rb", false). + once. + and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + expect(file_cache).to receive(:load). + with("cookbooks/cookbook_a/attributes/default.rb", false). + once. + and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + expect(file_cache).to receive(:load). + with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). + once. + and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:load). + with("cookbooks/cookbook_a/files/default/megaman.conf", false). + once. + and_return("/file-cache/cookbooks/cookbook_a/files/default/megaman.conf") + expect(Chef::Log).to receive(:warn).with("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!").once + synchronizer.sync_cookbooks + end + end end end -- cgit v1.2.1 From b133b6b25192f1bfd80d26bc2d140eb082046cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Magnus=20Rakv=C3=A5g?= Date: Thu, 28 Sep 2017 13:05:56 +0200 Subject: consistent formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tor Magnus Rakvåg --- spec/unit/cookbook/synchronizer_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index d55c840269..1e6c9ef48c 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -547,7 +547,9 @@ describe Chef::CookbookSynchronizer do with("cookbooks/cookbook_a/files/default/megaman.conf", false). once. and_return("/file-cache/cookbooks/cookbook_a/files/default/megaman.conf") - expect(Chef::Log).to receive(:warn).with("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!").once + expect(Chef::Log).to receive(:warn). + with("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!"). + once synchronizer.sync_cookbooks end end -- cgit v1.2.1