diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2020-05-20 12:40:39 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2020-05-20 12:43:45 -0700 |
commit | 6d14ba02ec07b18eb757315d9665b646470f6f56 (patch) | |
tree | c9fc136390c0bc12fc28c298fe466b14f13191fd /spec | |
parent | 0aac0e30a5532e9d2d32764c8f3221efba475f86 (diff) | |
download | chef-6d14ba02ec07b18eb757315d9665b646470f6f56.tar.gz |
Chef-16.2 breaking changelcg/resource_name_fixes
This is a breaking change to fix a breaking change in Chef 16.0.
The new behavior is that a resource which relies upon the reource_name
statement to wire the resource up to the DSL will fail (although the
very old wiring of the "<cookbook_name>_<resource filename>" continues
to work).
So for a resource which does not get its DSL wiring from the filename,
only declaring a resource_name will fail:
```
resource_name :foo
```
This can be fixed by adding an explicit `provides` line (which is
backwards compatible):
```
resource_name :foo
provides :foo
```
If backwards compatibility is not a concern, then post-16.0 the
resource_name call can be completely dropped:
```
provides :foo
```
This is a vastly simpler backwards compatibility break than the
unintentional break in #9885, which is difficult to describe and
to detect.
The rules going forward are fairly simple to explain:
1. The resource_name now only sets the resource_name.
2. The old behavior of the fallback resource_name and DSL wiring
based on the filename is preserved (unless the values are set).
3. In Chef 16, The first provides line will set the resource_name if
it has not already been set, allowing the resource_name to be
omitted.
It is recommended that all resources only set provides lines, the
use of the fallback filename-based wiring is discouraged and
explicitly setting the resource_name is discouraged.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/resource_spec.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index a2ba2b272f..3808d99a06 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -492,6 +492,20 @@ describe Chef::Resource do expect(r.resource_name).to eq :blah expect(r.declared_type).to eq :d end + + # This tests some somewhat confusing behavior that used to occur due to the resource_name call + # automatically wiring up the old canonical provides line. + it "setting resoure_name does not override provides in prior resource" do + c1 = Class.new(Chef::Resource) do + resource_name :self_resource_name_test_4 + provides :self_resource_name_test_4 + end + c2 = Class.new(Chef::Resource) do + resource_name :self_resource_name_test_4 + provides(:self_resource_name_test_4) { false } # simulates any filter that does not match + end + expect(Chef::Resource.resource_for_node(:self_resource_name_test_4, node)).to eql(c1) + end end describe "to_json" do |