diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-15 10:54:01 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-15 10:54:01 -0700 |
commit | 13339a0a0fccd8e3516ef8f4946b90f648a8907a (patch) | |
tree | ee1e1d2c70edcbb91729dc01395c024231d0fad6 | |
parent | d3b0f2ce30e4a8cbcbdd0c7128f4ae710a189e83 (diff) | |
download | chef-13339a0a0fccd8e3516ef8f4946b90f648a8907a.tar.gz |
suppress cookbook self-dependencies and warnlcg/warn-cb-self-dep
cookbooks with self-deps:
name 'foo'
depends 'foo'
are useless and can waste cycles in the depsolver (particularly in
the non-solution case), and likely limit the possible choices of
depsolvers that we could pick at some point to replace gecode.
filtering out the self-dep here will prevent the chef server depsolver
from seeing the self-dep and needing to do the work to strip it.
also warn the user so that they can remove the self-dep.
in the future this will be a hard error.
foodcritic also has a rule about removing these.
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 10 | ||||
-rw-r--r-- | spec/integration/knife/upload_spec.rb | 18 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 15 |
3 files changed, 40 insertions, 3 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 4f12275a82..01a98fda39 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -286,9 +286,13 @@ class Chef # === Returns # versions<Array>:: Returns the list of versions for the platform def depends(cookbook, *version_args) - version = new_args_format(:depends, cookbook, version_args) - constraint = validate_version_constraint(:depends, cookbook, version) - @dependencies[cookbook] = constraint.to_s + if cookbook == name + Chef::Log.warn "Ignoring self-dependency in cookbook #{name}, please remove it (in the future this will be fatal)." + else + version = new_args_format(:depends, cookbook, version_args) + constraint = validate_version_constraint(:depends, cookbook, version) + @dependencies[cookbook] = constraint.to_s + end @dependencies[cookbook] end diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index cef4f54e97..826ecec364 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -154,6 +154,24 @@ EOM end end + context 'when cookbook metadata has a self-dependency' do + before do + file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'; depends 'x'" + end + + it "should warn", :chef_lt_13_only do + knife('upload /cookbooks').should_succeed( + stdout: "Updated /cookbooks/x\n", + stderr: "WARN: Ignoring self-dependency in cookbook x, please remove it (in the future this will be fatal).\n" + ) + knife('diff --name-status /').should_succeed '' + end + it "should fail in Chef 13", :chef_gte_13_only do + knife('upload /cookbooks').should_fail '' + # FIXME: include the error message here + end + end + context 'as well as one extra copy of each thing' do before do file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY } diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 760ae5dd2a..d2954726e8 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -304,6 +304,21 @@ describe Chef::Cookbook::Metadata do end end end + + it "strips out self-dependencies", :chef_lt_13_only do + metadata.name('foo') + expect(Chef::Log).to receive(:warn).with( + "Ignoring self-dependency in cookbook foo, please remove it (in the future this will be fatal)." + ) + metadata.depends('foo') + expect(metadata.dependencies).to eql({}) + end + + it "errors on self-dependencies", :chef_gte_13_only do + metadata.name('foo') + expect { metadata.depends('foo') }.to raise_error + # FIXME: add the error type + end end describe "attribute groupings" do |