summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-06-09 10:29:04 +0100
committerThom May <thom@may.lt>2015-06-09 10:29:04 +0100
commit59da09f64b72dbd712c890f999322493a4bc9ec4 (patch)
tree2d1bc8f0776dfef293c79bfe95999a1f09f9aa5e
parent6daea43f5578d6bf2aeb3464144dd8dbdf6bd4ef (diff)
parentd795db97bb8a79b179cd2f61355f04a856df3bd8 (diff)
downloadchef-59da09f64b72dbd712c890f999322493a4bc9ec4.tar.gz
Merge pull request #3495 from chef/jk/automatic-automatic-name
Remove use_automatic_resource_name, make resource_name automatic
-rw-r--r--CHANGELOG.md3
-rw-r--r--DOC_CHANGES.md54
-rw-r--r--lib/chef/chef_class.rb50
-rw-r--r--lib/chef/dsl/recipe.rb2
-rw-r--r--lib/chef/dsl/resources.rb1
-rw-r--r--lib/chef/node_map.rb61
-rw-r--r--lib/chef/platform/provider_mapping.rb2
-rw-r--r--lib/chef/platform/resource_priority_map.rb9
-rw-r--r--lib/chef/resource.rb308
-rw-r--r--lib/chef/resource/apt_package.rb1
-rw-r--r--lib/chef/resource/bash.rb1
-rw-r--r--lib/chef/resource/batch.rb1
-rw-r--r--lib/chef/resource/bff_package.rb1
-rw-r--r--lib/chef/resource/breakpoint.rb2
-rw-r--r--lib/chef/resource/chef_gem.rb2
-rw-r--r--lib/chef/resource/cookbook_file.rb2
-rw-r--r--lib/chef/resource/cron.rb2
-rw-r--r--lib/chef/resource/csh.rb1
-rw-r--r--lib/chef/resource/deploy.rb1
-rw-r--r--lib/chef/resource/deploy_revision.rb6
-rw-r--r--lib/chef/resource/directory.rb2
-rw-r--r--lib/chef/resource/dpkg_package.rb1
-rw-r--r--lib/chef/resource/dsc_resource.rb1
-rw-r--r--lib/chef/resource/dsc_script.rb1
-rw-r--r--lib/chef/resource/easy_install_package.rb2
-rw-r--r--lib/chef/resource/env.rb1
-rw-r--r--lib/chef/resource/erl_call.rb1
-rw-r--r--lib/chef/resource/execute.rb1
-rw-r--r--lib/chef/resource/file.rb1
-rw-r--r--lib/chef/resource/freebsd_package.rb1
-rw-r--r--lib/chef/resource/gem_package.rb2
-rw-r--r--lib/chef/resource/git.rb2
-rw-r--r--lib/chef/resource/group.rb2
-rw-r--r--lib/chef/resource/homebrew_package.rb1
-rw-r--r--lib/chef/resource/http_request.rb1
-rw-r--r--lib/chef/resource/ifconfig.rb1
-rw-r--r--lib/chef/resource/ips_package.rb1
-rw-r--r--lib/chef/resource/link.rb2
-rw-r--r--lib/chef/resource/log.rb1
-rw-r--r--lib/chef/resource/macosx_service.rb1
-rw-r--r--lib/chef/resource/macports_package.rb2
-rw-r--r--lib/chef/resource/mdadm.rb2
-rw-r--r--lib/chef/resource/mount.rb2
-rw-r--r--lib/chef/resource/ohai.rb1
-rw-r--r--lib/chef/resource/openbsd_package.rb1
-rw-r--r--lib/chef/resource/package.rb2
-rw-r--r--lib/chef/resource/pacman_package.rb3
-rw-r--r--lib/chef/resource/paludis_package.rb2
-rw-r--r--lib/chef/resource/perl.rb2
-rw-r--r--lib/chef/resource/portage_package.rb2
-rw-r--r--lib/chef/resource/powershell_script.rb2
-rw-r--r--lib/chef/resource/python.rb2
-rw-r--r--lib/chef/resource/reboot.rb2
-rw-r--r--lib/chef/resource/registry_key.rb2
-rw-r--r--lib/chef/resource/remote_directory.rb2
-rw-r--r--lib/chef/resource/remote_file.rb2
-rw-r--r--lib/chef/resource/route.rb2
-rw-r--r--lib/chef/resource/rpm_package.rb2
-rw-r--r--lib/chef/resource/ruby.rb3
-rw-r--r--lib/chef/resource/ruby_block.rb1
-rw-r--r--lib/chef/resource/scm.rb2
-rw-r--r--lib/chef/resource/script.rb2
-rw-r--r--lib/chef/resource/service.rb2
-rw-r--r--lib/chef/resource/smartos_package.rb3
-rw-r--r--lib/chef/resource/solaris_package.rb3
-rw-r--r--lib/chef/resource/subversion.rb1
-rw-r--r--lib/chef/resource/template.rb2
-rw-r--r--lib/chef/resource/timestamped_deploy.rb1
-rw-r--r--lib/chef/resource/user.rb3
-rw-r--r--lib/chef/resource/whyrun_safe_ruby_block.rb3
-rw-r--r--lib/chef/resource/windows_package.rb1
-rw-r--r--lib/chef/resource/windows_service.rb1
-rw-r--r--lib/chef/resource/yum_package.rb2
-rw-r--r--lib/chef/resource/zypper_package.rb4
-rw-r--r--lib/chef/resource_resolver.rb111
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb514
-rw-r--r--spec/integration/recipes/resource_definition_spec.rb18
-rw-r--r--spec/support/lib/chef/resource/cat.rb1
-rw-r--r--spec/support/lib/chef/resource/one_two_three_four.rb1
-rw-r--r--spec/support/lib/chef/resource/openldap_includer.rb1
-rw-r--r--spec/support/lib/chef/resource/with_state.rb2
-rw-r--r--spec/support/lib/chef/resource/zen_follower.rb1
-rw-r--r--spec/support/lib/chef/resource/zen_master.rb1
-rw-r--r--spec/unit/lwrp_spec.rb6
-rw-r--r--spec/unit/provider_resolver_spec.rb1
-rw-r--r--spec/unit/recipe_spec.rb4
-rw-r--r--spec/unit/resource_spec.rb14
-rw-r--r--spec/unit/runner_spec.rb4
88 files changed, 896 insertions, 388 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7ddb91ab3d..4fa6e1a1be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,11 +20,12 @@
* [pr#3397](https://github.com/chef/chef/pull/3397): Validate owner exists in directory resources
* [pr#3418](https://github.com/chef/chef/pull/3418): Add `shell_out` mixin to Chef::Resource class for use in `not_if`/`only_if` conditionals, etc.
* [pr#3406](https://github.com/chef/chef/pull/3406): Add wide-char 'Environment' to `broadcast_env_change` mixin for setting windows environment variables
-* [pr#3442](https://github.com/chef/chef/pull/3442): Add `resource_name` to top-level Resource class to make defining resources easier. `use_automatic_resource_name` also added, to support convention-based resource naming.
+* [pr#3442](https://github.com/chef/chef/pull/3442): Add `resource_name` to top-level Resource class to make defining resources easier.
* [pr#3447](https://github.com/chef/chef/pull/3447): Add `allowed_actions` and `default_action` to top-level Resource class.
* [pr#3475](https://github.com/chef/chef/pull/3475): Fix `shell_out` timeouts in all package providers to respect timeout property on the resource.
* [pr#3477](https://github.com/chef/chef/pull/3477): Update `zypper_package` to look like the rest of our package classes.
* [pr#3483](https://github.com/chef/chef/pull/3483): Allow `include_recipe` from LWRP providers.
+* [pr#3495](https://github.com/chef/chef/pull/3495): Make resource name automatically determined from class name, and provide DSL for it.
## 12.4.0
diff --git a/DOC_CHANGES.md b/DOC_CHANGES.md
index cba06a26e6..46712f114c 100644
--- a/DOC_CHANGES.md
+++ b/DOC_CHANGES.md
@@ -6,27 +6,61 @@ Example Doc Change:
Description of the required change.
-->
-### Resources must now use `resource_name` to declare recipe DSL
+### Resources now *all* get automatic DSL
-Resources declared in `Chef::Resource` namespace will no longer get recipe DSL
-automatically. Instead, `resource_name` is required in order to have DSL:
+When you declare a resource (no matter where) you now get automatic DSL for it, based on your class name:
```ruby
module MyModule
class MyResource < Chef::Resource
- use_automatic_resource_name # Names the resource "my_resource"
+ # Names the resource "my_resource"
end
end
```
-`resource_name :my_resource` may be used to explicitly set the resource name.
+When this happens, the resource can be used in a recipe:
-`provides :my_resource` still works, but at least one resource_name *must* be
-set for the resource to work.
+```ruby
+my_resource 'blah' do
+end
+```
+
+If you have an abstract class that should *not* have DSL, set `resource_name` to `nil`:
+
+```ruby
+module MyModule
+ # This will not have DSL
+ class MyBaseResource < Chef::Resource
+ resource_name nil
+ end
+ # This will have DSL `my_resource`
+ class MyResource < MyBaseResource
+ end
+end
+```
+
+When you do this, `my_base_resource` will not work in a recipe (but `my_resource` will).
+
+You can still use `provides` to provide other DSL names:
-Authors of HWRPs need to be aware that in the future all resources and providers will be required to include a provides line. Starting with Chef 12.4.0 any HWRPs in the `Chef::Resource` or `Chef::Provider` namespaces that do not have provides lines will trigger deprecation warning messages when called. The LWRPBase code does `provides` automatically so LWRP authors and users who write classes that inherit from LWRPBase do not need to explicitly include provides lines.
+```ruby
+module MyModule
+ class MyResource < Chef::Resource
+ provides :super_resource
+ end
+end
+```
-Users are encouraged to declare resources in their own namespaces instead of putting them in the special `Chef::Resource` namespace.
+Which enables this recipe:
+
+```ruby
+super_resource 'wowzers' do
+end
+```
+
+(Note that when you use provides in this manner, resource_name will be `my_resource` and declared_type will be `super_resource`. This won't affect most people, but it is worth noting as a matter of explanation.)
+
+Users are encouraged to declare resources in their own namespaces instead of putting them in the `Chef::Resource` namespace.
### Resources may now use `allowed_actions` and `default_action`
@@ -34,8 +68,6 @@ Instead of overriding `Chef::Resource.initialize` and setting `@allowed_actions`
```ruby
class MyResource < Chef::Resource
- use_automatic_resource_name
-
allowed_actions :create, :delete
default_action :create
end
diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb
index 7c0a2bf944..f1dd797c04 100644
--- a/lib/chef/chef_class.rb
+++ b/lib/chef/chef_class.rb
@@ -36,50 +36,74 @@ class Chef
# Public API
#
+ #
# Get the node object
#
# @return [Chef::Node] node object of the chef-client run
+ #
attr_reader :node
+ #
# Get the run context
#
# @return [Chef::RunContext] run_context of the chef-client run
+ #
attr_reader :run_context
+ #
# Get the array of providers associated with a resource_name for the current node
#
# @param resource_name [Symbol] name of the resource as a symbol
+ #
# @return [Array<Class>] Priority Array of Provider Classes to use for the resource_name on the node
+ #
def get_provider_priority_array(resource_name)
- provider_priority_map.get_priority_array(node, resource_name).dup
+ result = provider_priority_map.get_priority_array(node, resource_name)
+ result = result.dup if result
+ result
end
+ #
# Get the array of resources associated with a resource_name for the current node
#
# @param resource_name [Symbol] name of the resource as a symbol
+ #
# @return [Array<Class>] Priority Array of Resource Classes to use for the resource_name on the node
+ #
def get_resource_priority_array(resource_name)
- resource_priority_map.get_priority_array(node, resource_name).dup
+ result = resource_priority_map.get_priority_array(node, resource_name)
+ result = result.dup if result
+ result
end
+ #
# Set the array of providers associated with a resource_name for the current node
#
# @param resource_name [Symbol] name of the resource as a symbol
# @param priority_array [Class, Array<Class>] Class or Array of Classes to set as the priority for resource_name on the node
# @param filter [Hash] Chef::Nodearray-style filter
+ #
# @return [Array<Class>] Modified Priority Array of Provider Classes to use for the resource_name on the node
+ #
def set_provider_priority_array(resource_name, priority_array, *filter, &block)
- provider_priority_map.set_priority_array(resource_name, priority_array, *filter, &block).dup
+ result = provider_priority_map.set_priority_array(resource_name, priority_array, *filter, &block)
+ result = result.dup if result
+ result
end
+ #
# Get the array of resources associated with a resource_name for the current node
#
# @param resource_name [Symbol] name of the resource as a symbol
# @param priority_array [Class, Array<Class>] Class or Array of Classes to set as the priority for resource_name on the node
# @param filter [Hash] Chef::Nodearray-style filter
+ #
# @return [Array<Class>] Modified Priority Array of Resource Classes to use for the resource_name on the node
+ #
def set_resource_priority_array(resource_name, priority_array, *filter, &block)
- resource_priority_map.set_priority_array(resource_name, priority_array, *filter, &block).dup
+ result = resource_priority_map.set_priority_array(resource_name, priority_array, *filter, &block)
+ result = result.dup if result
+ result
end
#
@@ -88,22 +112,27 @@ class Chef
# *NOT* for public consumption ]
#
+ #
# Sets the resource_priority_map
#
- # @api private
# @param resource_priority_map [Chef::Platform::ResourcePriorityMap]
+ #
+ # @api private
def set_resource_priority_map(resource_priority_map)
@resource_priority_map = resource_priority_map
end
+ #
# Sets the provider_priority_map
#
- # @api private
# @param provider_priority_map [Chef::Platform::providerPriorityMap]
+ #
+ # @api private
def set_provider_priority_map(provider_priority_map)
@provider_priority_map = provider_priority_map
end
+ #
# Sets the node object
#
# @api private
@@ -112,14 +141,17 @@ class Chef
@node = node
end
+ #
# Sets the run_context object
#
- # @api private
# @param run_context [Chef::RunContext]
+ #
+ # @api private
def set_run_context(run_context)
@run_context = run_context
end
+ #
# Resets the internal state
#
# @api private
@@ -130,14 +162,14 @@ class Chef
@resource_priority_map = nil
end
- private
-
+ # @api private
def provider_priority_map
@provider_priority_map ||= begin
# these slurp in the resource+provider world, so be exceedingly lazy about requiring them
Chef::Platform::ProviderPriorityMap.instance
end
end
+ # @api private
def resource_priority_map
@resource_priority_map ||= begin
Chef::Platform::ResourcePriorityMap.instance
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb
index ff398bc9e6..d69f0a8f11 100644
--- a/lib/chef/dsl/recipe.rb
+++ b/lib/chef/dsl/recipe.rb
@@ -162,7 +162,7 @@ class Chef
# Chef::Resource::Blah = <resource>, a deprecation warning will be
# emitted and the DSL method 'blah' will be added to the DSL.
#
- resource_class = Chef::ResourceResolver.new(run_context ? run_context.node : nil, method_symbol).resolve
+ resource_class = Chef::ResourceResolver.resolve(method_symbol, node: run_context ? run_context.node : nil)
if resource_class
Chef::DSL::Resources.add_resource_dsl(method_symbol)
return send(method_symbol, *args, &block)
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb
index a181c3be33..1ce12ed0a0 100644
--- a/lib/chef/dsl/resources.rb
+++ b/lib/chef/dsl/resources.rb
@@ -15,6 +15,7 @@ class Chef
end
EOM
rescue SyntaxError
+ # Handle the case where dsl_name has spaces, etc.
define_method(dsl_name.to_sym) do |name=nil, created_at=nil, &block|
declare_resource(dsl_name, name, created_at || caller[0], &block)
end
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 34f19d18b4..f547018a38 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -19,27 +19,31 @@
class Chef
class NodeMap
+ #
# Create a new NodeMap
#
def initialize
@map = {}
end
+ #
# Set a key/value pair on the map with a filter. The filter must be true
# when applied to the node in order to retrieve the value.
#
# @param key [Object] Key to store
# @param value [Object] Value associated with the key
# @param filters [Hash] Node filter options to apply to key retrieval
+ #
# @yield [node] Arbitrary node filter as a block which takes a node argument
+ #
# @return [NodeMap] Returns self for possible chaining
#
- def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, on_platform: nil, on_platforms: nil, &block)
+ def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, on_platform: nil, on_platforms: nil, canonical: nil, &block)
Chef::Log.deprecation "The on_platform option to node_map has been deprecated" if on_platform
Chef::Log.deprecation "The on_platforms option to node_map has been deprecated" if on_platforms
platform ||= on_platform || on_platforms
filters = { platform: platform, platform_version: platform_version, platform_family: platform_family, os: os }
- new_matcher = { filters: filters, block: block, value: value }
+ new_matcher = { filters: filters, block: block, value: value, canonical: canonical }
@map[key] ||= []
# Decide where to insert the matcher; the new value is preferred over
# anything more specific (see `priority_of`) and is preferred over older
@@ -60,35 +64,58 @@ class Chef
self
end
+ #
# Get a value from the NodeMap via applying the node to the filters that
# were set on the key.
#
- # @param node [Chef::Node] The Chef::Node object for the run
+ # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
+ # ignore all filters.
# @param key [Object] Key to look up
+ # @param canonical [Boolean] `true` or `false` to match canonical or
+ # non-canonical values only. `nil` to ignore canonicality. Default: `nil`
+ #
# @return [Object] Value
#
- def get(node, key)
- # FIXME: real exception
- raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node)
- list(node, key).first
+ def get(node, key, canonical: nil)
+ raise ArgumentError, "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
+ list(node, key, canonical: canonical).first
end
+ #
# List all matches for the given node and key from the NodeMap, from
# most-recently added to oldest.
#
- # @param node [Chef::Node] The Chef::Node object for the run
+ # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
+ # ignore all filters.
# @param key [Object] Key to look up
+ # @param canonical [Boolean] `true` or `false` to match canonical or
+ # non-canonical values only. `nil` to ignore canonicality. Default: `nil`
+ #
# @return [Object] Value
#
- def list(node, key)
- # FIXME: real exception
- raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node)
+ def list(node, key, canonical: nil)
+ raise ArgumentError, "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
return [] unless @map.has_key?(key)
@map[key].select do |matcher|
- filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block])
+ node_matches?(node, matcher) && canonical_matches?(canonical, matcher)
end.map { |matcher| matcher[:value] }
end
+ # Seriously, don't use this, it's nearly certain to change on you
+ # @return remaining
+ # @api private
+ def delete_canonical(key, value)
+ remaining = @map[key]
+ if remaining
+ remaining.delete_if { |matcher| matcher[:canonical] && Array(matcher[:value]) == Array(value) }
+ if remaining.empty?
+ @map.delete(key)
+ remaining = nil
+ end
+ end
+ remaining
+ end
+
private
#
@@ -160,5 +187,15 @@ class Chef
return true if block.nil?
block.call node
end
+
+ def node_matches?(node, matcher)
+ return true if !node
+ filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block])
+ end
+
+ def canonical_matches?(canonical, matcher)
+ return true if canonical.nil?
+ !!canonical == !!matcher[:canonical]
+ end
end
end
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 0440ff8601..e3a894c8ac 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -60,8 +60,6 @@ class Chef
Chef::Log.debug("Chef::Version::Comparable does not know how to parse the platform version: #{version}")
end
end
- else
- Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)")
end
provider_map
end
diff --git a/lib/chef/platform/resource_priority_map.rb b/lib/chef/platform/resource_priority_map.rb
index e98fc12413..fb08debc53 100644
--- a/lib/chef/platform/resource_priority_map.rb
+++ b/lib/chef/platform/resource_priority_map.rb
@@ -5,8 +5,8 @@ class Chef
class ResourcePriorityMap
include Singleton
- def get_priority_array(node, resource_name)
- priority_map.get(node, resource_name.to_sym)
+ def get_priority_array(node, resource_name, canonical: nil)
+ priority_map.get(node, resource_name.to_sym, canonical: canonical)
end
def set_priority_array(resource_name, priority_array, *filter, &block)
@@ -14,6 +14,11 @@ class Chef
end
# @api private
+ def delete_canonical(resource_name, resource_class)
+ priority_map.delete_canonical(resource_name, resource_class)
+ end
+
+ # @api private
def list_handlers(*args)
priority_map.list(*args).flatten(1).uniq
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index d74b942e7d..7fe8a52d95 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -877,142 +877,144 @@ class Chef
nil
end
- # Provider lookup and naming
- class<<self
- #
- # The DSL name of this resource (e.g. `package` or `yum_package`)
- #
- # @return [String] The DSL name of this resource.
- #
- # @deprecated Use resource_name instead.
- #
- def dsl_name
- Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 13. Use resource_name instead."
- if name
- name = self.name.split('::')[-1]
- convert_to_snake_case(name)
- end
+ #
+ # The DSL name of this resource (e.g. `package` or `yum_package`)
+ #
+ # @return [String] The DSL name of this resource.
+ #
+ # @deprecated Use resource_name instead.
+ #
+ def self.dsl_name
+ Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 13. Use resource_name instead."
+ if name
+ name = self.name.split('::')[-1]
+ convert_to_snake_case(name)
end
+ end
- #
- # The display name of this resource type, for printing purposes.
- #
- # This also automatically calls "provides" to provide DSL with the given
- # name.
- #
- # @param value [Symbol] The desired name of this resource type (e.g.
- # `execute`).
- #
- # @return [Symbol] The name of this resource type (e.g. `:execute`).
- #
- def resource_name(value=NULL_ARG)
- if value != NULL_ARG
- @resource_name = value.to_sym
- provides self.resource_name
- end
- # Backcompat: set resource name for classes in Chef::Resource automatically
- if !@resource_name && self.name
- chef, resource, class_name, *extra = self.name.split('::')
- if chef == 'Chef' && resource == 'Resource' && extra.size == 0
- @resource_name = convert_to_snake_case(self.name.split('::')[-1])
+ #
+ # The display name of this resource type, for printing purposes.
+ #
+ # This also automatically calls "provides" to provide DSL with the given
+ # name.
+ #
+ # resource_name defaults to your class name.
+ #
+ # Call `resource_name nil` to remove the resource name (and any
+ # corresponding DSL).
+ #
+ # @param value [Symbol] The desired name of this resource type (e.g.
+ # `execute`), or `nil` if this class is abstract and has no resource_name.
+ #
+ # @return [Symbol] The name of this resource type (e.g. `:execute`).
+ #
+ def self.resource_name(name=NULL_ARG)
+ # Setter
+ if name != NULL_ARG
+ remove_canonical_dsl
+
+ # Set the resource_name and call provides
+ if name
+ name = name.to_sym
+ # If our class is not already providing this name, provide it.
+ if !Chef::ResourceResolver.list(name).include?(self)
+ provides name, canonical: true
end
+ @resource_name = name
+ else
+ @resource_name = nil
end
- @resource_name
- end
- alias :resource_name= :resource_name
-
- #
- # Use the class name as the resource name.
- #
- # Munges the last part of the class name from camel case to snake case,
- # and sets the resource_name to that:
- #
- # A::B::BlahDBlah -> blah_d_blah
- #
- def use_automatic_resource_name
- automatic_name = convert_to_snake_case(self.name.split('::')[-1])
- resource_name automatic_name
- end
-
- #
- # The module where Chef should look for providers for this resource.
- # The provider for `MyResource` will be looked up using
- # `provider_base::MyResource`. Defaults to `Chef::Provider`.
- #
- # @param arg [Module] The module containing providers for this resource
- # @return [Module] The module containing providers for this resource
- #
- # @example
- # class MyResource < Chef::Resource
- # provider_base Chef::Provider::Deploy
- # # ...other stuff
- # end
- #
- # @deprecated Use `provides` on the provider, or `provider` on the resource, instead.
- #
- def provider_base(arg=nil)
- if arg
- Chef::Log.deprecation("Resource.provider_base is deprecated and will be removed in Chef 13. Use provides on the provider, or provider on the resource, instead.")
+ else
+ # set resource_name automatically if it's not set
+ if !instance_variable_defined?(:@resource_name) && self.name
+ resource_name convert_to_snake_case(self.name.split('::')[-1])
end
- @provider_base ||= arg || Chef::Provider
end
- #
- # The list of allowed actions for the resource.
- #
- # @param actions [Array<Symbol>] The list of actions to add to allowed_actions.
- #
- # @return [Arrau<Symbol>] The list of actions, as symbols.
- #
- def allowed_actions(*actions)
- @allowed_actions ||=
- if superclass.respond_to?(:allowed_actions)
- superclass.allowed_actions.dup
- else
- [ :nothing ]
- end
- @allowed_actions |= actions
- end
- def allowed_actions=(value)
- @allowed_actions = value
- end
+ @resource_name
+ end
+ def self.resource_name=(name)
+ resource_name(name)
+ end
- #
- # The action that will be run if no other action is specified.
- #
- # Setting default_action will automatially add the action to
- # allowed_actions, if it isn't already there.
- #
- # Defaults to :nothing.
- #
- # @param action_name [Symbol,Array<Symbol>] The default action (or series
- # of actions) to use.
- #
- # @return [Symbol,Array<Symbol>] The default actions for the resource.
- #
- def default_action(action_name=NULL_ARG)
- unless action_name.equal?(NULL_ARG)
- if action_name.is_a?(Array)
- @default_action = action_name.map { |arg| arg.to_sym }
- else
- @default_action = action_name.to_sym
- end
+ #
+ # The module where Chef should look for providers for this resource.
+ # The provider for `MyResource` will be looked up using
+ # `provider_base::MyResource`. Defaults to `Chef::Provider`.
+ #
+ # @param arg [Module] The module containing providers for this resource
+ # @return [Module] The module containing providers for this resource
+ #
+ # @example
+ # class MyResource < Chef::Resource
+ # provider_base Chef::Provider::Deploy
+ # # ...other stuff
+ # end
+ #
+ # @deprecated Use `provides` on the provider, or `provider` on the resource, instead.
+ #
+ def self.provider_base(arg=nil)
+ if arg
+ Chef::Log.deprecation("Resource.provider_base is deprecated and will be removed in Chef 13. Use provides on the provider, or provider on the resource, instead.")
+ end
+ @provider_base ||= arg || Chef::Provider
+ end
- self.allowed_actions |= Array(@default_action)
+ #
+ # The list of allowed actions for the resource.
+ #
+ # @param actions [Array<Symbol>] The list of actions to add to allowed_actions.
+ #
+ # @return [Arrau<Symbol>] The list of actions, as symbols.
+ #
+ def self.allowed_actions(*actions)
+ @allowed_actions ||=
+ if superclass.respond_to?(:allowed_actions)
+ superclass.allowed_actions.dup
+ else
+ [ :nothing ]
end
+ @allowed_actions |= actions
+ end
+ def self.allowed_actions=(value)
+ @allowed_actions = value
+ end
- if @default_action
- @default_action
- elsif superclass.respond_to?(:default_action)
- superclass.default_action
+ #
+ # The action that will be run if no other action is specified.
+ #
+ # Setting default_action will automatially add the action to
+ # allowed_actions, if it isn't already there.
+ #
+ # Defaults to :nothing.
+ #
+ # @param action_name [Symbol,Array<Symbol>] The default action (or series
+ # of actions) to use.
+ #
+ # @return [Symbol,Array<Symbol>] The default actions for the resource.
+ #
+ def self.default_action(action_name=NULL_ARG)
+ unless action_name.equal?(NULL_ARG)
+ if action_name.is_a?(Array)
+ @default_action = action_name.map { |arg| arg.to_sym }
else
- :nothing
+ @default_action = action_name.to_sym
end
+
+ self.allowed_actions |= Array(@default_action)
end
- def default_action=(action_name)
- default_action action_name
+
+ if @default_action
+ @default_action
+ elsif superclass.respond_to?(:default_action)
+ superclass.default_action
+ else
+ :nothing
end
end
+ def self.default_action=(action_name)
+ default_action(action_name)
+ end
#
# Internal Resource Interface (for Chef)
@@ -1106,9 +1108,10 @@ class Chef
def self.sorted_descendants
@@sorted_descendants ||= descendants.sort_by { |x| x.to_s }
end
- def self.inherited(other)
+ def self.inherited(child)
super
- @@sorted_descendants = nil
+ @sorted_descendants = nil
+ child.resource_name
end
@@ -1123,14 +1126,30 @@ class Chef
end
end
- def self.provides(name, opts={}, &block)
- result = Chef.set_resource_priority_array(name, self, opts, &block)
+ #
+ # Mark this resource as providing particular DSL.
+ #
+ # Resources have an automatic DSL based on their resource_name, equivalent to
+ # `provides :resource_name` (providing the resource on all OS's). If you
+ # declare a `provides` with the given resource_name, it *replaces* that
+ # provides (so that you can provide your resource DSL only on certain OS's).
+ #
+ def self.provides(name, **options, &block)
+ name = name.to_sym
+
+ # `provides :resource_name, os: 'linux'`) needs to remove the old
+ # canonical DSL before adding the new one.
+ if @resource_name && name == @resource_name
+ remove_canonical_dsl
+ end
+
+ result = Chef.set_resource_priority_array(name, self, options, &block)
Chef::DSL::Resources.add_resource_dsl(name)
result
end
def self.provides?(node, resource)
- Chef::ResourceResolver.new(node, resource).provided_by?(self)
+ Chef::ResourceResolver.resolve(resource, node: node).provided_by?(self)
end
# Helper for #notifies
@@ -1262,15 +1281,13 @@ class Chef
# === Returns
# <Chef::Resource>:: returns the proper Chef::Resource class
def self.resource_for_node(short_name, node)
- klass = Chef::ResourceResolver.new(node, short_name).resolve
+ klass = Chef::ResourceResolver.resolve(short_name, node: node)
raise Chef::Exceptions::NoSuchResourceType.new(short_name, node) if klass.nil?
klass
end
#
- # Returns the class of a Chef::Resource based on the short name
- # Only returns the *canonical* class with the given name, not the one that
- # would be picked by the ResourceResolver.
+ # Returns the class with the given resource_name.
#
# ==== Parameters
# short_name<Symbol>:: short_name of the resource (ie :directory)
@@ -1278,20 +1295,8 @@ class Chef
# === Returns
# <Chef::Resource>:: returns the proper Chef::Resource class
#
- # @deprecated Chef::Resource::FooBar will no longer mean anything special in
- # Chef 13. Use `resource_for_node` instead.
def self.resource_matching_short_name(short_name)
- begin
- rname = convert_to_class_name(short_name.to_s)
- result = Chef::Resource.const_get(rname)
- if result <= Chef::Resource
- Chef::Log.deprecation("Class Chef::Resource::#{rname} does not declare 'provides #{short_name.inspect}'.")
- Chef::Log.deprecation("This will no longer work in Chef 13: you must use 'provides' to provide DSL.")
- result
- end
- rescue NameError
- nil
- end
+ Chef::ResourceResolver.resolve(short_name, canonical: true)
end
# @api private
@@ -1315,10 +1320,18 @@ class Chef
#
resource_subclass = class_eval <<-EOM, __FILE__, __LINE__+1
class Chef::Resource::#{class_name} < resource_class
+ resource_name nil # we do not actually provide anything
def initialize(*args, &block)
Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
super
end
+ def self.resource_name(*args)
+ if args.empty?
+ @resource_name ||= superclass.resource_name
+ else
+ super
+ end
+ end
self
end
EOM
@@ -1362,6 +1375,17 @@ class Chef
end
end
end
+
+ private
+
+ def self.remove_canonical_dsl
+ if @resource_name
+ remaining = Chef.resource_priority_map.delete_canonical(@resource_name, self)
+ if !remaining
+ Chef::DSL::Resources.remove_resource_dsl(@resource_name)
+ end
+ end
+ end
end
end
diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb
index 83bb6906d4..ca119b50c4 100644
--- a/lib/chef/resource/apt_package.rb
+++ b/lib/chef/resource/apt_package.rb
@@ -23,7 +23,6 @@ class Chef
class Resource
class AptPackage < Chef::Resource::Package
- use_automatic_resource_name
provides :package, os: "linux", platform_family: [ "debian" ]
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb
index 554d2de924..025687e879 100644
--- a/lib/chef/resource/bash.rb
+++ b/lib/chef/resource/bash.rb
@@ -22,7 +22,6 @@ require 'chef/provider/script'
class Chef
class Resource
class Bash < Chef::Resource::Script
- use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb
index 8a19e04174..efe3f2205f 100644
--- a/lib/chef/resource/batch.rb
+++ b/lib/chef/resource/batch.rb
@@ -22,7 +22,6 @@ class Chef
class Resource
class Batch < Chef::Resource::WindowsScript
- use_automatic_resource_name
provides :batch, os: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb
index f31fe6a0d8..7c1496a46b 100644
--- a/lib/chef/resource/bff_package.rb
+++ b/lib/chef/resource/bff_package.rb
@@ -22,7 +22,6 @@ require 'chef/provider/package/aix'
class Chef
class Resource
class BffPackage < Chef::Resource::Package
- use_automatic_resource_name
end
end
end
diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb
index 0107b8968a..69dbc48050 100644
--- a/lib/chef/resource/breakpoint.rb
+++ b/lib/chef/resource/breakpoint.rb
@@ -22,8 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Breakpoint < Chef::Resource
- use_automatic_resource_name
-
default_action :break
def initialize(action="break", *args)
diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb
index e4e3ccfbab..0c2fdfa819 100644
--- a/lib/chef/resource/chef_gem.rb
+++ b/lib/chef/resource/chef_gem.rb
@@ -23,8 +23,6 @@ class Chef
class Resource
class ChefGem < Chef::Resource::Package::GemPackage
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@compile_time = Chef::Config[:chef_gem_compile_time]
diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb
index 08f4733497..42f16e6db6 100644
--- a/lib/chef/resource/cookbook_file.rb
+++ b/lib/chef/resource/cookbook_file.rb
@@ -27,8 +27,6 @@ class Chef
class CookbookFile < Chef::Resource::File
include Chef::Mixin::Securable
- use_automatic_resource_name
-
default_action :create
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index a399caebe9..93cf41bc37 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -27,8 +27,6 @@ class Chef
state_attrs :minute, :hour, :day, :month, :weekday, :user
- use_automatic_resource_name
-
default_action :create
allowed_actions :create, :delete
diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb
index 1c89f2aca6..d5e9c910b1 100644
--- a/lib/chef/resource/csh.rb
+++ b/lib/chef/resource/csh.rb
@@ -22,7 +22,6 @@ require 'chef/provider/script'
class Chef
class Resource
class Csh < Chef::Resource::Script
- use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb
index f88133119a..3e5255bced 100644
--- a/lib/chef/resource/deploy.rb
+++ b/lib/chef/resource/deploy.rb
@@ -50,7 +50,6 @@ class Chef
# release directory. Callback files can contain chef code (resources, etc.)
#
class Deploy < Chef::Resource
- use_automatic_resource_name
identity_attr :repository
diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb
index 86a8631ba7..1397359ac8 100644
--- a/lib/chef/resource/deploy_revision.rb
+++ b/lib/chef/resource/deploy_revision.rb
@@ -22,15 +22,9 @@ class Chef
# Convenience class for using the deploy resource with the revision
# deployment strategy (provider)
class DeployRevision < Chef::Resource::Deploy
-
- use_automatic_resource_name
-
end
class DeployBranch < Chef::Resource::DeployRevision
-
- use_automatic_resource_name
-
end
end
diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb
index 304317e07a..9cac2ce243 100644
--- a/lib/chef/resource/directory.rb
+++ b/lib/chef/resource/directory.rb
@@ -32,8 +32,6 @@ class Chef
include Chef::Mixin::Securable
- use_automatic_resource_name
-
default_action :create
allowed_actions :create, :delete
diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb
index e0b86947f1..38adf24cf6 100644
--- a/lib/chef/resource/dpkg_package.rb
+++ b/lib/chef/resource/dpkg_package.rb
@@ -23,7 +23,6 @@ class Chef
class Resource
class DpkgPackage < Chef::Resource::Package
- use_automatic_resource_name
provides :dpkg_package, os: "linux"
end
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 7c822604e2..5db00f49ca 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -21,7 +21,6 @@ class Chef
class Resource
class DscResource < Chef::Resource
- use_automatic_resource_name
provides :dsc_resource, os: "windows"
include Chef::DSL::Powershell
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index 0ff7988d7d..2fcf183375 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -22,7 +22,6 @@ class Chef
class Resource
class DscScript < Chef::Resource
- use_automatic_resource_name
provides :dsc_script, platform: "windows"
default_action :run
diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb
index 2483b0a8b7..df4cee1ab3 100644
--- a/lib/chef/resource/easy_install_package.rb
+++ b/lib/chef/resource/easy_install_package.rb
@@ -22,8 +22,6 @@ class Chef
class Resource
class EasyInstallPackage < Chef::Resource::Package
- use_automatic_resource_name
-
def easy_install_binary(arg=nil)
set_or_return(
:easy_install_binary,
diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb
index da7d48f062..025bfc72b7 100644
--- a/lib/chef/resource/env.rb
+++ b/lib/chef/resource/env.rb
@@ -25,7 +25,6 @@ class Chef
state_attrs :value
- use_automatic_resource_name
provides :env, os: "windows"
default_action :create
diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb
index b025259b4c..1976c54c45 100644
--- a/lib/chef/resource/erl_call.rb
+++ b/lib/chef/resource/erl_call.rb
@@ -23,7 +23,6 @@ require 'chef/provider/erl_call'
class Chef
class Resource
class ErlCall < Chef::Resource
- use_automatic_resource_name
# erl_call : http://erlang.org/doc/man/erl_call.html
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 34ed6b1bd9..ec669a75d3 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -23,7 +23,6 @@ require 'chef/provider/execute'
class Chef
class Resource
class Execute < Chef::Resource
- use_automatic_resource_name
identity_attr :command
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 51969f65a0..d278652cc3 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -47,7 +47,6 @@ class Chef
# @returns [String] Checksum of the file we actually rendered
attr_accessor :final_checksum
- use_automatic_resource_name
default_action :create
allowed_actions :create, :delete, :touch, :create_if_missing
diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb
index f89e1813b9..c7c43450ba 100644
--- a/lib/chef/resource/freebsd_package.rb
+++ b/lib/chef/resource/freebsd_package.rb
@@ -29,7 +29,6 @@ class Chef
class FreebsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
- use_automatic_resource_name
provides :package, platform: "freebsd"
def after_created
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index 5bd3a89100..b981797876 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -22,8 +22,6 @@ class Chef
class Resource
class GemPackage < Chef::Resource::Package
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@clear_sources = false
diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb
index 1229914766..393a0689fe 100644
--- a/lib/chef/resource/git.rb
+++ b/lib/chef/resource/git.rb
@@ -22,8 +22,6 @@ class Chef
class Resource
class Git < Chef::Resource::Scm
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@additional_remotes = Hash[]
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb
index 49cf92a282..2e80f32fea 100644
--- a/lib/chef/resource/group.rb
+++ b/lib/chef/resource/group.rb
@@ -25,8 +25,6 @@ class Chef
state_attrs :members
- use_automatic_resource_name
-
allowed_actions :create, :remove, :modify, :manage
default_action :create
diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb
index fe0bd89ced..048ba6b3aa 100644
--- a/lib/chef/resource/homebrew_package.rb
+++ b/lib/chef/resource/homebrew_package.rb
@@ -25,7 +25,6 @@ class Chef
class Resource
class HomebrewPackage < Chef::Resource::Package
- use_automatic_resource_name
provides :package, os: "darwin"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index 192484f557..f9f056325a 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -23,7 +23,6 @@ require 'chef/provider/http_request'
class Chef
class Resource
class HttpRequest < Chef::Resource
- use_automatic_resource_name
identity_attr :url
diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb
index 47adc52425..527eb0e515 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -22,7 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Ifconfig < Chef::Resource
- use_automatic_resource_name
identity_attr :device
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index 6b40fe138c..8d720dd411 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -23,7 +23,6 @@ class Chef
class Resource
class IpsPackage < ::Chef::Resource::Package
- use_automatic_resource_name
provides :ips_package, os: "solaris2"
allowed_actions :install, :remove, :upgrade
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index 2fe4da718c..f932383cc1 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -25,8 +25,6 @@ class Chef
class Link < Chef::Resource
include Chef::Mixin::Securable
- use_automatic_resource_name
-
identity_attr :target_file
state_attrs :to, :owner, :group
diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb
index 5c119df4d8..9adffb26bb 100644
--- a/lib/chef/resource/log.rb
+++ b/lib/chef/resource/log.rb
@@ -23,7 +23,6 @@ require 'chef/provider/log'
class Chef
class Resource
class Log < Chef::Resource
- use_automatic_resource_name
identity_attr :message
diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb
index 29da2e6309..f1ed4051cb 100644
--- a/lib/chef/resource/macosx_service.rb
+++ b/lib/chef/resource/macosx_service.rb
@@ -22,7 +22,6 @@ class Chef
class Resource
class MacosxService < Chef::Resource::Service
- use_automatic_resource_name
provides :macosx_service, os: "darwin"
provides :service, os: "darwin"
diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb
index 3ccf831cf2..937839b6e1 100644
--- a/lib/chef/resource/macports_package.rb
+++ b/lib/chef/resource/macports_package.rb
@@ -19,8 +19,6 @@
class Chef
class Resource
class MacportsPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :package, os: "darwin"
end
end
diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb
index 2927cc8321..b789fab155 100644
--- a/lib/chef/resource/mdadm.rb
+++ b/lib/chef/resource/mdadm.rb
@@ -27,8 +27,6 @@ class Chef
state_attrs :devices, :level, :chunk
- use_automatic_resource_name
-
default_action :create
allowed_actions :create, :assemble, :stop
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb
index ce6d2cc232..79986d127f 100644
--- a/lib/chef/resource/mount.rb
+++ b/lib/chef/resource/mount.rb
@@ -27,8 +27,6 @@ class Chef
state_attrs :mount_point, :device_type, :fstype, :username, :password, :domain
- use_automatic_resource_name
-
default_action :mount
allowed_actions :mount, :umount, :remount, :enable, :disable
diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb
index 005b149442..9425e55c0c 100644
--- a/lib/chef/resource/ohai.rb
+++ b/lib/chef/resource/ohai.rb
@@ -20,7 +20,6 @@
class Chef
class Resource
class Ohai < Chef::Resource
- use_automatic_resource_name
identity_attr :name
diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb
index 1071958cd2..f91fdb37e0 100644
--- a/lib/chef/resource/openbsd_package.rb
+++ b/lib/chef/resource/openbsd_package.rb
@@ -28,7 +28,6 @@ class Chef
class OpenbsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
- use_automatic_resource_name
provides :package, os: "openbsd"
def after_created
diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb
index 4e265c2688..1c6da75678 100644
--- a/lib/chef/resource/package.rb
+++ b/lib/chef/resource/package.rb
@@ -22,8 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Package < Chef::Resource
- use_automatic_resource_name
-
identity_attr :package_name
state_attrs :version, :options
diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb
index 222fb3c78e..54b8efc4c2 100644
--- a/lib/chef/resource/pacman_package.rb
+++ b/lib/chef/resource/pacman_package.rb
@@ -21,10 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class PacmanPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :pacman_package, os: "linux"
-
end
end
end
diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb
index f0ddc5927a..56c47bc141 100644
--- a/lib/chef/resource/paludis_package.rb
+++ b/lib/chef/resource/paludis_package.rb
@@ -22,8 +22,6 @@ require 'chef/provider/package/paludis'
class Chef
class Resource
class PaludisPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :paludis_package, os: "linux"
allowed_actions :install, :remove, :upgrade
diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb
index 6870f487eb..773eba6571 100644
--- a/lib/chef/resource/perl.rb
+++ b/lib/chef/resource/perl.rb
@@ -22,8 +22,6 @@ require 'chef/provider/script'
class Chef
class Resource
class Perl < Chef::Resource::Script
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@interpreter = "perl"
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index 009a525d22..1af48702fa 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -21,8 +21,6 @@ require 'chef/resource/package'
class Chef
class Resource
class PortagePackage < Chef::Resource::Package
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@provider = Chef::Provider::Package::Portage
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index a3a24fce7f..7d432883e4 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -20,8 +20,6 @@ require 'chef/resource/windows_script'
class Chef
class Resource
class PowershellScript < Chef::Resource::WindowsScript
-
- use_automatic_resource_name
provides :powershell_script, os: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb
index 5c120d7d27..432ee46b85 100644
--- a/lib/chef/resource/python.rb
+++ b/lib/chef/resource/python.rb
@@ -21,8 +21,6 @@ require 'chef/provider/script'
class Chef
class Resource
class Python < Chef::Resource::Script
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@interpreter = "python"
diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb
index 216367692f..401f2f338f 100644
--- a/lib/chef/resource/reboot.rb
+++ b/lib/chef/resource/reboot.rb
@@ -24,8 +24,6 @@ require 'chef/resource'
class Chef
class Resource
class Reboot < Chef::Resource
- use_automatic_resource_name
-
allowed_actions :request_reboot, :reboot_now, :cancel
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index 9ee031b751..4ed0d4a4e0 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -22,8 +22,6 @@ require 'chef/digester'
class Chef
class Resource
class RegistryKey < Chef::Resource
- use_automatic_resource_name
-
identity_attr :key
state_attrs :values
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb
index bb052d3bd4..b731f7b201 100644
--- a/lib/chef/resource/remote_directory.rb
+++ b/lib/chef/resource/remote_directory.rb
@@ -26,8 +26,6 @@ class Chef
class RemoteDirectory < Chef::Resource::Directory
include Chef::Mixin::Securable
- use_automatic_resource_name
-
identity_attr :path
state_attrs :files_owner, :files_group, :files_mode
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb
index 99c21cae52..b7a553cbe8 100644
--- a/lib/chef/resource/remote_file.rb
+++ b/lib/chef/resource/remote_file.rb
@@ -28,8 +28,6 @@ class Chef
class RemoteFile < Chef::Resource::File
include Chef::Mixin::Securable
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@source = []
diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb
index 3df767a128..3ba8f6215b 100644
--- a/lib/chef/resource/route.rb
+++ b/lib/chef/resource/route.rb
@@ -22,8 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Route < Chef::Resource
- use_automatic_resource_name
-
identity_attr :target
state_attrs :netmask, :gateway
diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb
index 67a6c156d8..b8b5144a42 100644
--- a/lib/chef/resource/rpm_package.rb
+++ b/lib/chef/resource/rpm_package.rb
@@ -22,8 +22,6 @@ require 'chef/provider/package/rpm'
class Chef
class Resource
class RpmPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :rpm_package, os: [ "linux", "aix" ]
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb
index 759955da42..3c3909043d 100644
--- a/lib/chef/resource/ruby.rb
+++ b/lib/chef/resource/ruby.rb
@@ -22,13 +22,10 @@ require 'chef/provider/script'
class Chef
class Resource
class Ruby < Chef::Resource::Script
- use_automatic_resource_name
-
def initialize(name, run_context=nil)
super
@interpreter = "ruby"
end
-
end
end
end
diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb
index 4ce7b2cee1..ae8e4cb7cd 100644
--- a/lib/chef/resource/ruby_block.rb
+++ b/lib/chef/resource/ruby_block.rb
@@ -23,7 +23,6 @@ require 'chef/provider/ruby_block'
class Chef
class Resource
class RubyBlock < Chef::Resource
- use_automatic_resource_name
default_action :run
allowed_actions :create, :run
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index 8379a3d8a9..85028c266b 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -22,8 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Scm < Chef::Resource
- use_automatic_resource_name
-
identity_attr :destination
state_attrs :revision
diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb
index f3d3ef01f4..30bed367cb 100644
--- a/lib/chef/resource/script.rb
+++ b/lib/chef/resource/script.rb
@@ -23,8 +23,6 @@ require 'chef/provider/script'
class Chef
class Resource
class Script < Chef::Resource::Execute
- use_automatic_resource_name
-
# Chef-13: go back to using :name as the identity attr
identity_attr :command
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 9995eccb3f..aa59b543be 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -22,8 +22,6 @@ require 'chef/resource'
class Chef
class Resource
class Service < Chef::Resource
- use_automatic_resource_name
-
identity_attr :service_name
state_attrs :enabled, :running
diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb
index 7460f0f687..b8bd940c24 100644
--- a/lib/chef/resource/smartos_package.rb
+++ b/lib/chef/resource/smartos_package.rb
@@ -22,10 +22,7 @@ require 'chef/provider/package/smartos'
class Chef
class Resource
class SmartosPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :package, os: "solaris2", platform_family: "smartos"
-
end
end
end
diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb
index 545e783b75..2dc72d5c47 100644
--- a/lib/chef/resource/solaris_package.rb
+++ b/lib/chef/resource/solaris_package.rb
@@ -23,14 +23,11 @@ require 'chef/provider/package/solaris'
class Chef
class Resource
class SolarisPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :package, os: "solaris2", platform_family: "nexentacore"
provides :package, os: "solaris2", platform_family: "solaris2" do |node|
# on >= Solaris 11 we default to IPS packages instead
node[:platform_version].to_f <= 5.10
end
-
end
end
end
diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb
index e12d939ca6..ae6a37caa2 100644
--- a/lib/chef/resource/subversion.rb
+++ b/lib/chef/resource/subversion.rb
@@ -22,7 +22,6 @@ require "chef/resource/scm"
class Chef
class Resource
class Subversion < Chef::Resource::Scm
- use_automatic_resource_name
allowed_actions :force_export
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb
index a8e38aa5fb..5a7f7efd6f 100644
--- a/lib/chef/resource/template.rb
+++ b/lib/chef/resource/template.rb
@@ -27,8 +27,6 @@ class Chef
class Template < Chef::Resource::File
include Chef::Mixin::Securable
- use_automatic_resource_name
-
attr_reader :inline_helper_blocks
attr_reader :inline_helper_modules
diff --git a/lib/chef/resource/timestamped_deploy.rb b/lib/chef/resource/timestamped_deploy.rb
index 15ac296f78..344f8b0a5e 100644
--- a/lib/chef/resource/timestamped_deploy.rb
+++ b/lib/chef/resource/timestamped_deploy.rb
@@ -21,7 +21,6 @@ class Chef
# Convenience class for using the deploy resource with the timestamped
# deployment strategy (provider)
class TimestampedDeploy < Chef::Resource::Deploy
- use_automatic_resource_name
end
end
end
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index 66c183ad7e..b85b648c92 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -21,13 +21,10 @@ require 'chef/resource'
class Chef
class Resource
class User < Chef::Resource
-
identity_attr :username
state_attrs :uid, :gid, :home
- use_automatic_resource_name
-
default_action :create
allowed_actions :create, :remove, :modify, :manage, :lock, :unlock
diff --git a/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb
index 0ade9c981f..f289f15001 100644
--- a/lib/chef/resource/whyrun_safe_ruby_block.rb
+++ b/lib/chef/resource/whyrun_safe_ruby_block.rb
@@ -19,9 +19,6 @@
class Chef
class Resource
class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock
-
- use_automatic_resource_name
-
end
end
end
diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb
index bcf288e7b2..a76765cc36 100644
--- a/lib/chef/resource/windows_package.rb
+++ b/lib/chef/resource/windows_package.rb
@@ -26,7 +26,6 @@ class Chef
class WindowsPackage < Chef::Resource::Package
include Chef::Mixin::Uris
- use_automatic_resource_name
provides :windows_package, os: "windows"
provides :package, os: "windows"
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index 099042840c..a77690652e 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -25,7 +25,6 @@ class Chef
# Until #1773 is resolved, you need to manually specify the windows_service resource
# to use action :configure_startup and attribute startup_type
- use_automatic_resource_name
provides :windows_service, os: "windows"
provides :service, os: "windows"
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index ae9c840582..4d54f6051f 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -22,8 +22,6 @@ require 'chef/provider/package/yum'
class Chef
class Resource
class YumPackage < Chef::Resource::Package
-
- use_automatic_resource_name
provides :package, os: "linux", platform_family: [ "rhel", "fedora" ]
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index 74cdf72e15..f09a20e2c6 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -21,11 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class ZypperPackage < Chef::Resource::Package
-
provides :package, platform_family: "suse"
-
- use_automatic_resource_name
-
end
end
end
diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb
index 1eb5e6d840..31b39f7e24 100644
--- a/lib/chef/resource_resolver.rb
+++ b/lib/chef/resource_resolver.rb
@@ -21,65 +21,103 @@ require 'chef/platform/resource_priority_map'
class Chef
class ResourceResolver
- include Chef::Mixin::ConvertToClassName
-
- attr_reader :node
- attr_reader :resource
- attr_reader :action
-
- def initialize(node, resource)
- @node = node
- @resource = resource.to_sym
+ #
+ # Resolve a resource by name.
+ #
+ # @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
+ # @param node [Chef::Node] The node against which to resolve. `nil` causes
+ # platform filters to be ignored.
+ #
+ def self.resolve(resource_name, node: nil, canonical: nil)
+ new(node, resource_name, canonical: canonical).resolve
end
- def resolve
- maybe_dynamic_resource_resolution ||
- maybe_chef_platform_lookup
+ #
+ # Resolve a list of all resources that implement the given DSL (in order of
+ # preference).
+ #
+ # @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
+ # @param node [Chef::Node] The node against which to resolve. `nil` causes
+ # platform filters to be ignored.
+ # @param canonical [Boolean] `true` or `false` to match canonical or
+ # non-canonical values only. `nil` to ignore canonicality.
+ #
+ def self.list(resource_name, node: nil, canonical: nil)
+ new(node, resource_name, canonical: canonical).list
end
- def provided_by?(resource_class)
- !prioritized_handlers.include?(resource_class)
+
+ include Chef::Mixin::ConvertToClassName
+
+ # @api private
+ attr_reader :node
+ # @api private
+ attr_reader :resource_name
+ # @api private
+ def resource
+ Chef::Log.deprecation("Chef::ResourceResolver.resource deprecated. Use resource_name instead.")
+ resource_name
end
+ # @api private
+ attr_reader :action
+ # @api private
+ attr_reader :canonical
#
- # Resolve a resource by name.
+ # Create a resolver.
#
- # @param resource_name [Symbol] The resource DSL name (e.g. `:file`)
- # @param node [Chef::Node] The node on which the resource will run.
+ # @param node [Chef::Node] The node against which to resolve. `nil` causes
+ # platform filters to be ignored.
+ # @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
+ # @param canonical [Boolean] `true` or `false` to match canonical or
+ # non-canonical values only. `nil` to ignore canonicality. Default: `nil`
#
- def self.resolve(resource_name, node: Chef.node)
- new(node, resource_name).resolve
+ # @api private use Chef::ResourceResolver.resolve or .list instead.
+ def initialize(node, resource_name, canonical: nil)
+ @node = node
+ @resource_name = resource_name.to_sym
+ @canonical = canonical
end
- protected
-
- # try dynamically finding a resource based on querying the resources to see what they support
- def maybe_dynamic_resource_resolution
+ # @api private use Chef::ResourceResolver.resolve instead.
+ def resolve
# log this so we know what resources will work for the generic resource on the node (early cut)
- Chef::Log.debug "Resources for generic #{resource} resource enabled on node include: #{enabled_handlers}"
+ Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"
handler = prioritized_handlers.first
if handler
- Chef::Log.debug "Resource for #{resource} is #{handler}"
+ Chef::Log.debug "Resource for #{resource_name} is #{handler}"
else
- Chef::Log.debug "Dynamic resource resolver FAILED to resolve a resource for #{resource}"
+ Chef::Log.debug "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}"
end
handler
end
- # try the old static lookup of resources by mangling name to resource klass
- def maybe_chef_platform_lookup
- Chef::Resource.resource_matching_short_name(resource)
+ # @api private
+ def list
+ Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"
+ prioritized_handlers
end
+ #
+ # Whether this DSL is provided by the given resource_class.
+ #
+ # @api private
+ def provided_by?(resource_class)
+ !prioritized_handlers.include?(resource_class)
+ end
+
+ protected
+
def priority_map
Chef::Platform::ResourcePriorityMap.instance
end
def prioritized_handlers
- @prioritized_handlers ||= priority_map.list_handlers(node, resource)
+ @prioritized_handlers ||=
+ priority_map.list_handlers(node, resource_name, canonical: canonical)
end
module Deprecated
@@ -92,19 +130,22 @@ class Chef
# A list of all handlers
# @deprecated Now prioritized_handlers does its own work
def enabled_handlers
- resources.select { |klass| klass.provides?(node, resource) }
+ Chef::Log.deprecation("enabled_handlers is deprecated. If you are implementing a ResourceResolver, use provided_handlers. If you are not, use Chef::ResourceResolver.list(#{resource_name.inspect}, node: <node>)")
+ resources.select { |klass| klass.provides?(node, resource_name) }
end
protected
- # If there are no providers for a DSL, we search through the
+ # A list of all handlers for the given DSL. If there are no handlers in
+ # the map, we still check all descendants of Chef::Resource for backwards
+ # compatibility purposes.
def prioritized_handlers
@prioritized_handlers ||= super ||
resources.select do |klass|
- # Don't bother calling provides? unless it's overriden. We already
+ # Don't bother calling provides? unless it's overridden. We already
# know prioritized_handlers
- if klass.method(:provides?).owner != Chef::Resource && klass.provides?(node, resource)
- Chef::Log.deprecation("Resources #{provided.join(", ")} are marked as providing DSL #{resource}, but provides #{resource.inspect} was never called!")
+ if klass.method(:provides?).owner != Chef::Resource && klass.provides?(node, resource_name)
+ Chef::Log.deprecation("Resources #{provided.join(", ")} are marked as providing DSL #{resource_name}, but provides #{resource_name.inspect} was never called!")
Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
true
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 93270a9a19..3f4bf9fd5f 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -3,6 +3,14 @@ require 'support/shared/integration/integration_helper'
describe "Recipe DSL methods" do
include IntegrationSupport
+ module Namer
+ extend self
+ attr_accessor :current_index
+ end
+
+ before(:all) { Namer.current_index = 1 }
+ before { Namer.current_index += 1 }
+
context "With resource 'base_thingy' declared as BaseThingy" do
before(:context) {
@@ -74,12 +82,11 @@ describe "Recipe DSL methods" do
recipe = converge {
backcompat_thingy 'blah' do; end
}
- expect(recipe.logged_warnings).to match(/Class Chef::Resource::BackcompatThingy does not declare 'provides :backcompat_thingy'/i)
expect(BaseThingy.created_resource).to eq Chef::Resource::BackcompatThingy
expect(BaseThingy.created_provider).to eq Chef::Provider::BackcompatThingy
end
- context "And another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
+ context "and another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
before(:context) {
class RecipeDSLSpecNamespace::BackcompatThingy < BaseThingy
@@ -99,23 +106,425 @@ describe "Recipe DSL methods" do
end
end
- context "With a resource named RecipeDSLSpecNamespace::Bar::Thingy" do
+ context "With a resource named RecipeDSLSpecNamespace::Bar::BarThingy" do
+ before(:context) {
+
+ class RecipeDSLSpecNamespace::Bar::BarThingy < BaseThingy
+ end
+
+ }
+
+ it "bar_thingy works" do
+ recipe = converge {
+ bar_thingy 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq(RecipeDSLSpecNamespace::Bar::BarThingy)
+ end
+ end
+
+ context "With a resource named NoNameThingy with resource_name nil" do
before(:context) {
- class RecipeDSLSpecNamespace::Bar::Thingy < BaseThingy; end
+ class NoNameThingy < BaseThingy
+ resource_name nil
+ end
}
- it "thingy does not work" do
+ it "no_name_thingy does not work" do
expect_converge {
thingy 'blah' do; end
}.to raise_error(NoMethodError)
end
end
+
+ context "With a resource named AnotherNoNameThingy with resource_name :another_thingy_name" do
+ before(:context) {
+
+ class AnotherNoNameThingy < BaseThingy
+ resource_name :another_thingy_name
+ end
+
+ }
+
+ it "another_no_name_thingy does not work" do
+ expect_converge {
+ another_no_name_thingy 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+
+ it "another_thingy_name works" do
+ recipe = converge {
+ another_thingy_name 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy2 with resource_name :another_thingy_name2; resource_name :another_thingy_name3" do
+ before(:context) {
+
+ class AnotherNoNameThingy2 < BaseThingy
+ resource_name :another_thingy_name2
+ resource_name :another_thingy_name3
+ end
+
+ }
+
+ it "another_no_name_thingy does not work" do
+ expect_converge {
+ another_no_name_thingy2 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+
+ it "another_thingy_name2 does not work" do
+ expect_converge {
+ another_thingy_name2 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+
+ it "yet_another_thingy_name3 works" do
+ recipe = converge {
+ another_thingy_name3 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy2)
+ end
+ end
+
+ context "provides overriding resource_name" do
+ context "With a resource named AnotherNoNameThingy3 with provides :another_no_name_thingy3, os: 'blarghle'" do
+ before(:context) {
+
+ class AnotherNoNameThingy3 < BaseThingy
+ provides :another_no_name_thingy3, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy3 does not work" do
+ expect_converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy3 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy3 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy3 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy3)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy4 with two provides" do
+ before(:context) {
+
+ class AnotherNoNameThingy4 < BaseThingy
+ provides :another_no_name_thingy4, os: 'blarghle'
+ provides :another_no_name_thingy4, platform_family: 'foo'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy4 does not work" do
+ expect_converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy4 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy4 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy4 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
+ end
+
+ it "and platform_family = foo, another_no_name_thingy4 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:platform_family] = 'foo'
+ another_no_name_thingy4 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy5, a different resource_name, and a provides with the original resource_name" do
+ before(:context) {
+
+ class AnotherNoNameThingy5 < BaseThingy
+ resource_name :another_thingy_name_for_another_no_name_thingy5
+ provides :another_no_name_thingy5, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy5 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy5 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy5 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy5 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
+ end
+
+ it "the new resource name can be used in a recipe" do
+ recipe = converge {
+ another_thingy_name_for_another_no_name_thingy5 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy6, a provides with the original resource name, and a different resource_name" do
+ before(:context) {
+
+ class AnotherNoNameThingy6 < BaseThingy
+ provides :another_no_name_thingy6, os: 'blarghle'
+ resource_name :another_thingy_name_for_another_no_name_thingy6
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy6 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy6 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy6 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy6 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
+ end
+
+ it "the new resource name can be used in a recipe" do
+ recipe = converge {
+ another_thingy_name_for_another_no_name_thingy6 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy7, a new resource_name, and provides with that new resource name" do
+ before(:context) {
+
+ class AnotherNoNameThingy7 < BaseThingy
+ resource_name :another_thingy_name_for_another_no_name_thingy7
+ provides :another_thingy_name_for_another_no_name_thingy7, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy7 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy7 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy7)
+ end
+
+ it "the old resource name does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy_7 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+ end
+
+ # opposite order from the previous test (provides, then resource_name)
+ context "With a resource named AnotherNoNameThingy8, a provides with a new resource name, and resource_name with that new resource name" do
+ before(:context) {
+
+ class AnotherNoNameThingy8 < BaseThingy
+ provides :another_thingy_name_for_another_no_name_thingy8, os: 'blarghle'
+ resource_name :another_thingy_name_for_another_no_name_thingy8
+ end
+
+ }
+
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy8 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy8 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy8)
+ end
+
+ it "the old resource name does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name8 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+ end
+
+ context "With a resource TwoClassesOneDsl" do
+ let(:class_name) { "TwoClassesOneDsl#{Namer.current_index}" }
+ let(:dsl_method) { :"two_classes_one_dsl#{Namer.current_index}" }
+
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ class #{class_name} < BaseThingy
+ end
+ EOM
+ }
+ context "and resource BlahModule::TwoClassesOneDsl" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class #{class_name} < BaseThingy
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl (last declared)" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
+ end
+ it "resource_matching_short_name returns BlahModule::TwoClassesOneDsl" do
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("BlahModule::#{class_name}")
+ end
+ end
+ context "and resource BlahModule::TwoClassesOneDsl with resource_name nil" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ resource_name nil
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ it "resource_matching_short_name returns ::TwoClassesOneDsl" do
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("::#{class_name}")
+ end
+ end
+ context "and resource BlahModule::TwoClassesOneDsl with resource_name :argh" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ resource_name :argh
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ it "resource_matching_short_name returns ::TwoClassesOneDsl" do
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("::#{class_name}")
+ end
+ end
+ context "and resource BlahModule::TwoClassesOneDsl with provides :two_classes_one_dsl, os: 'blarghle'" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ provides #{dsl_method.inspect}, os: 'blarghle'
+ end
+ end
+ EOM
+ }
+
+ it "and os = blarghle, two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
+ end
+
+ it "and os = linux, two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ end
+ end
+ end
end
context "provides" do
- context "When MySupplier provides :hemlock" do
+ context "when MySupplier provides :hemlock" do
before(:context) {
class RecipeDSLSpecNamespace::MySupplier < BaseThingy
@@ -138,7 +547,7 @@ describe "Recipe DSL methods" do
end
end
- context "When Thingy3 provides :thingy3" do
+ context "when Thingy3 has resource_name :thingy3" do
before(:context) {
class RecipeDSLSpecNamespace::Thingy3 < BaseThingy
@@ -154,7 +563,7 @@ describe "Recipe DSL methods" do
expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
end
- context "And Thingy4 provides :thingy3" do
+ context "and Thingy4 has resource_name :thingy3" do
before(:context) {
class RecipeDSLSpecNamespace::Thingy4 < BaseThingy
@@ -175,10 +584,97 @@ describe "Recipe DSL methods" do
thingy4 'blah' do; end
}.to raise_error(NoMethodError)
end
+
+ it "resource_matching_short_name returns Thingy4" do
+ expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4
+ end
+ end
+ end
+
+ context "when Thingy5 has resource_name :thingy5" do
+ before(:context) {
+
+ class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
+ resource_name :thingy5
+ end
+
+ }
+
+ it "thingy5 works in a recipe" do
+ expect_recipe {
+ thingy5 'blah' do; end
+ }.to emit_no_warnings_or_errors
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
+ end
+
+ context "and Thingy6 provides :thingy5" do
+ before(:context) {
+
+ class RecipeDSLSpecNamespace::Thingy6 < BaseThingy
+ provides :thingy5
+ end
+
+ }
+
+ it "thingy6 works in a recipe and yields Thingy6" do
+ recipe = converge {
+ thingy6 'blah' do; end
+ }
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
+ end
+
+ it "thingy5 works in a recipe and yields Foo::Thingy6 (the later one)" do
+ recipe = converge {
+ thingy5 'blah' do; end
+ }
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
+ end
+
+ it "resource_matching_short_name returns Thingy5" do
+ expect(Chef::Resource.resource_matching_short_name(:thingy5)).to eq RecipeDSLSpecNamespace::Thingy5
+ end
+ end
+ end
+
+ context "when Thingy7 provides :thingy8" do
+ before(:context) {
+
+ class RecipeDSLSpecNamespace::Thingy7 < BaseThingy
+ provides :thingy8
+ end
+
+ }
+
+ context "and Thingy8 has resource_name :thingy8" do
+ before(:context) {
+
+ class RecipeDSLSpecNamespace::Thingy8 < BaseThingy
+ resource_name :thingy8
+ end
+
+ }
+
+ it "thingy7 works in a recipe and yields Thingy7" do
+ recipe = converge {
+ thingy7 'blah' do; end
+ }
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7
+ end
+
+ it "thingy8 works in a recipe and yields Thingy8 (the later one)" do
+ recipe = converge {
+ thingy8 'blah' do; end
+ }
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy8
+ end
+
+ it "resource_matching_short_name returns Thingy8" do
+ expect(Chef::Resource.resource_matching_short_name(:thingy8)).to eq RecipeDSLSpecNamespace::Thingy8
+ end
end
end
- context "When Thingy5 provides :thingy5, :twizzle and :twizzle2" do
+ context "when Thingy5 provides :thingy5, :twizzle and :twizzle2" do
before(:context) {
class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
diff --git a/spec/integration/recipes/resource_definition_spec.rb b/spec/integration/recipes/resource_definition_spec.rb
deleted file mode 100644
index 4e5bc53428..0000000000
--- a/spec/integration/recipes/resource_definition_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'support/shared/integration/integration_helper'
-
-describe "Resource definition" do
- include IntegrationSupport
-
- context "With a resource with only provides lines and no resource_name" do
- before(:context) {
- class ResourceDefinitionNoNameTest < Chef::Resource
- provides :resource_definition_no_name_test
- end
- }
- it "Creating said resource with the resource builder fails with an exception" do
- expect_converge {
- resource_definition_no_name_test 'blah'
- }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
- end
- end
-end
diff --git a/spec/support/lib/chef/resource/cat.rb b/spec/support/lib/chef/resource/cat.rb
index 9bfaebf07b..efc78aa59c 100644
--- a/spec/support/lib/chef/resource/cat.rb
+++ b/spec/support/lib/chef/resource/cat.rb
@@ -19,7 +19,6 @@
class Chef
class Resource
class Cat < Chef::Resource
- use_automatic_resource_name
attr_accessor :action
diff --git a/spec/support/lib/chef/resource/one_two_three_four.rb b/spec/support/lib/chef/resource/one_two_three_four.rb
index 4543744a28..8f273a0cda 100644
--- a/spec/support/lib/chef/resource/one_two_three_four.rb
+++ b/spec/support/lib/chef/resource/one_two_three_four.rb
@@ -19,7 +19,6 @@
class Chef
class Resource
class OneTwoThreeFour < Chef::Resource
- use_automatic_resource_name
attr_reader :i_can_count
diff --git a/spec/support/lib/chef/resource/openldap_includer.rb b/spec/support/lib/chef/resource/openldap_includer.rb
index 421c95532d..6f443b4c7c 100644
--- a/spec/support/lib/chef/resource/openldap_includer.rb
+++ b/spec/support/lib/chef/resource/openldap_includer.rb
@@ -20,7 +20,6 @@
class Chef
class Resource
class OpenldapIncluder < Chef::Resource::LWRPBase
- use_automatic_resource_name
allowed_actions :run
default_action :run
end
diff --git a/spec/support/lib/chef/resource/with_state.rb b/spec/support/lib/chef/resource/with_state.rb
index efff2e7c12..773ae7ddb8 100644
--- a/spec/support/lib/chef/resource/with_state.rb
+++ b/spec/support/lib/chef/resource/with_state.rb
@@ -22,8 +22,6 @@ require 'chef/json_compat'
class Chef
class Resource
class WithState < Chef::Resource
- use_automatic_resource_name
-
attr_accessor :state
end
end
diff --git a/spec/support/lib/chef/resource/zen_follower.rb b/spec/support/lib/chef/resource/zen_follower.rb
index 90d33e6039..155e6ae729 100644
--- a/spec/support/lib/chef/resource/zen_follower.rb
+++ b/spec/support/lib/chef/resource/zen_follower.rb
@@ -21,7 +21,6 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenFollower < Chef::Resource
- use_automatic_resource_name
provides :follower, platform: "zen"
diff --git a/spec/support/lib/chef/resource/zen_master.rb b/spec/support/lib/chef/resource/zen_master.rb
index 82cef0bb50..4106549d79 100644
--- a/spec/support/lib/chef/resource/zen_master.rb
+++ b/spec/support/lib/chef/resource/zen_master.rb
@@ -22,7 +22,6 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenMaster < Chef::Resource
- use_automatic_resource_name
allowed_actions :win, :score
attr_reader :peace
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index dbf76d3c13..34c6f6f1c5 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -38,7 +38,7 @@ describe "LWRP" do
end
def get_lwrp(name)
- Chef::Resource.resource_for_node(name, Chef::Node.new)
+ Chef::ResourceResolver.resolve(name)
end
def get_lwrp_provider(name)
@@ -146,7 +146,7 @@ describe "LWRP" do
content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__))
IO.write(@lwrp_path, content)
Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
- @original_resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
+ @original_resource = Chef::ResourceResolver.resolve(:lwrp_foo)
end
after do
@@ -161,7 +161,7 @@ describe "LWRP" do
end
it "Should load the old content, and not the new" do
- resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
+ resource = Chef::ResourceResolver.resolve(:lwrp_foo)
expect(resource).to eq @original_resource
expect(resource.default_action).to eq(:pass_buck)
expect(Chef.method_defined?(:method_created_by_override_lwrp_foo)).to be_falsey
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index a27074e0bc..e18d69bc19 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -113,7 +113,6 @@ describe Chef::ProviderResolver do
end
before do
- expect(provider_resolver).not_to receive(:maybe_chef_platform_lookup)
allow(resource).to receive(:service_name).and_return("ntp")
end
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 72d5cc6f63..ee98e63c1f 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -121,7 +121,6 @@ describe Chef::Recipe do
it "locate resource for particular platform" do
ShaunTheSheep = Class.new(Chef::Resource)
- ShaunTheSheep.use_automatic_resource_name
ShaunTheSheep.provides :laughter, :platform => ["television"]
node.automatic[:platform] = "television"
node.automatic[:platform_version] = "123"
@@ -132,7 +131,6 @@ describe Chef::Recipe do
it "locate a resource for all platforms" do
YourMom = Class.new(Chef::Resource)
- YourMom.use_automatic_resource_name
YourMom.provides :love_and_caring
res = recipe.love_and_caring "mommy"
expect(res.name).to eql("mommy")
@@ -143,9 +141,7 @@ describe Chef::Recipe do
before do
node.automatic[:platform] = "nbc_sports"
Sounders = Class.new(Chef::Resource)
- Sounders.use_automatic_resource_name
TottenhamHotspur = Class.new(Chef::Resource)
- TottenhamHotspur.use_automatic_resource_name
end
after do
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 1d20fcf604..8ba45d9350 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -395,20 +395,6 @@ describe Chef::Resource do
expect(r.resource_name).to eq :blah
expect(r.declared_type).to eq :d
end
- it "use_automatic_resource_name yields a resource name from the class name" do
- class SelfResourceNameTestBlahDBlah4 < Chef::Resource
- use_automatic_resource_name
- end
-
- c = SelfResourceNameTestBlahDBlah4
-
- r = c.new('hi')
- r.declared_type = :d
- expect(c.resource_name).to eq :self_resource_name_test_blah_d_blah4
- expect(r.resource_name).to eq :self_resource_name_test_blah_d_blah4
- expect(r.declared_type).to eq :d
-
- end
end
describe "is" do
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
index b30f818da1..82e57e068c 100644
--- a/spec/unit/runner_spec.rb
+++ b/spec/unit/runner_spec.rb
@@ -273,8 +273,8 @@ describe Chef::Runner do
expected_message =<<-E
Multiple failures occurred:
-* FailureProvider::ChefClientFail occurred in delayed notification: [explode] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
-* FailureProvider::ChefClientFail occurred in delayed notification: [explode again] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
+* FailureProvider::ChefClientFail occurred in delayed notification: failure_resource[explode] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
+* FailureProvider::ChefClientFail occurred in delayed notification: failure_resource[explode again] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
E
expect(exception.message).to eq(expected_message)