diff options
Diffstat (limited to 'lib')
69 files changed, 180 insertions, 236 deletions
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 7cfe57a92a..7324822eff 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -28,8 +28,8 @@ class Chef class Service class Macosx < Chef::Provider::Service::Simple - provides :service, os: "darwin" provides :macosx_service, os: "darwin" + provides :service, os: "darwin" def self.gather_plist_dirs locations = %w{/Library/LaunchAgents diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 18759b29f7..ac98df5513 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -57,6 +57,8 @@ class Chef include Chef::Mixin::ShellOut include Chef::Mixin::PowershellOut + NULL_ARG = Object.new + # # The node the current Chef run is using. # @@ -88,7 +90,6 @@ class Chef run_context.resource_collection.find(*args) end - # # Resource User Interface (for users) # @@ -606,7 +607,7 @@ class Chef # def to_s - "#{@resource_name}[#{@name}]" + "#{resource_name}[#{name}]" end def to_text @@ -825,23 +826,15 @@ class Chef end # - # The DSL name of this resource (e.g. `package` or `yum_package`) - # - # @return [String] The DSL name of this resource. - def self.dsl_name - Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 11. Use resource.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. # - # The name of this resource (e.g. `file`) + # Will be used to print out the resource in messages, e.g. resource_name[name] # - # @return [String] The name of this resource. + # @return [Symbol] The name of this resource type (e.g. `:execute`). # - attr_reader :resource_name + def resource_name + @resource_name || self.class.resource_name + end # # Sets a list of capabilities of the real resource. For example, `:remount` @@ -873,23 +866,85 @@ class Chef nil 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 - # - def self.provider_base(arg=nil) - @provider_base ||= arg - @provider_base ||= Chef::Provider + # 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 + 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]) + end + 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.") + end + @provider_base ||= arg || Chef::Provider + end end @@ -1162,7 +1217,7 @@ class Chef def const_missing(class_name) if deprecated_constants[class_name.to_sym] - Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 12 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.") + 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.") deprecated_constants[class_name.to_sym] else raise NameError, "uninitialized constant Chef::Resource::#{class_name}" diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb index f944825ac3..83bb6906d4 100644 --- a/lib/chef/resource/apt_package.rb +++ b/lib/chef/resource/apt_package.rb @@ -23,12 +23,11 @@ class Chef class Resource class AptPackage < Chef::Resource::Package - provides :apt_package + use_automatic_resource_name provides :package, os: "linux", platform_family: [ "debian" ] def initialize(name, run_context=nil) super - @resource_name = :apt_package @default_release = nil end diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb index 366d8c7bd6..554d2de924 100644 --- a/lib/chef/resource/bash.rb +++ b/lib/chef/resource/bash.rb @@ -22,11 +22,10 @@ require 'chef/provider/script' class Chef class Resource class Bash < Chef::Resource::Script - provides :bash + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :bash @interpreter = "bash" end diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb index c091ec56b6..8a19e04174 100644 --- a/lib/chef/resource/batch.rb +++ b/lib/chef/resource/batch.rb @@ -22,10 +22,11 @@ class Chef class Resource class Batch < Chef::Resource::WindowsScript + use_automatic_resource_name provides :batch, os: "windows" def initialize(name, run_context=nil) - super(name, run_context, :batch, "cmd.exe") + super(name, run_context, nil, "cmd.exe") end end diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb index d4139e7ffe..f31fe6a0d8 100644 --- a/lib/chef/resource/bff_package.rb +++ b/lib/chef/resource/bff_package.rb @@ -22,13 +22,7 @@ require 'chef/provider/package/aix' class Chef class Resource class BffPackage < Chef::Resource::Package - provides :bff_package - - def initialize(name, run_context=nil) - super - @resource_name = :bff_package - end - + use_automatic_resource_name end end end diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb index 5a55858f71..dca4fd04a6 100644 --- a/lib/chef/resource/breakpoint.rb +++ b/lib/chef/resource/breakpoint.rb @@ -22,14 +22,12 @@ require 'chef/resource' class Chef class Resource class Breakpoint < Chef::Resource - provides :breakpoint + use_automatic_resource_name def initialize(action="break", *args) - @name = caller.first - super(@name, *args) + super(caller.first, *args) @action = "break" @allowed_actions << :break - @resource_name = :breakpoint end end end diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb index 59f575a524..e4e3ccfbab 100644 --- a/lib/chef/resource/chef_gem.rb +++ b/lib/chef/resource/chef_gem.rb @@ -23,11 +23,10 @@ class Chef class Resource class ChefGem < Chef::Resource::Package::GemPackage - provides :chef_gem + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :chef_gem @compile_time = Chef::Config[:chef_gem_compile_time] @gem_binary = RbConfig::CONFIG['bindir'] + "/gem" end diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb index 7be353b648..ade9c0e3e3 100644 --- a/lib/chef/resource/cookbook_file.rb +++ b/lib/chef/resource/cookbook_file.rb @@ -27,12 +27,11 @@ class Chef class CookbookFile < Chef::Resource::File include Chef::Mixin::Securable - provides :cookbook_file + use_automatic_resource_name def initialize(name, run_context=nil) super @provider = Chef::Provider::CookbookFile - @resource_name = :cookbook_file @action = "create" @source = ::File.basename(name) @cookbook = nil diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index cb16506012..daf462866e 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -27,11 +27,10 @@ class Chef state_attrs :minute, :hour, :day, :month, :weekday, :user - provides :cron + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :cron @action = :create @allowed_actions.push(:create, :delete) @minute = "*" diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb index d37f1a8e0c..1c89f2aca6 100644 --- a/lib/chef/resource/csh.rb +++ b/lib/chef/resource/csh.rb @@ -22,11 +22,10 @@ require 'chef/provider/script' class Chef class Resource class Csh < Chef::Resource::Script - provides :csh + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :csh @interpreter = "csh" end diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb index 55e3547b25..8d007df348 100644 --- a/lib/chef/resource/deploy.rb +++ b/lib/chef/resource/deploy.rb @@ -50,9 +50,7 @@ class Chef # release directory. Callback files can contain chef code (resources, etc.) # class Deploy < Chef::Resource - provides :deploy - - provider_base Chef::Provider::Deploy + use_automatic_resource_name identity_attr :repository @@ -60,7 +58,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :deploy @deploy_to = name @environment = nil @repository_cache = 'cached-copy' @@ -282,6 +279,12 @@ class Chef ) end + # This is to support "provider :revision" without deprecation warnings. + # Do NOT copy this. + def self.provider_base + Chef::Provider::Deploy + end + def svn_force_export(arg=nil) set_or_return( :svn_force_export, diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb index e144ce2162..86a8631ba7 100644 --- a/lib/chef/resource/deploy_revision.rb +++ b/lib/chef/resource/deploy_revision.rb @@ -23,22 +23,14 @@ class Chef # deployment strategy (provider) class DeployRevision < Chef::Resource::Deploy - provides :deploy_revision + use_automatic_resource_name - def initialize(*args, &block) - super - @resource_name = :deploy_revision - end end class DeployBranch < Chef::Resource::DeployRevision - provides :deploy_branch + use_automatic_resource_name - def initialize(*args, &block) - super - @resource_name = :deploy_branch - end end end diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb index 1ab7f0d16d..ea1805353d 100644 --- a/lib/chef/resource/directory.rb +++ b/lib/chef/resource/directory.rb @@ -32,11 +32,10 @@ class Chef include Chef::Mixin::Securable - provides :directory + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :directory @path = name @action = :create @recursive = false diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb index 35a47e8a82..e0b86947f1 100644 --- a/lib/chef/resource/dpkg_package.rb +++ b/lib/chef/resource/dpkg_package.rb @@ -23,13 +23,9 @@ class Chef class Resource class DpkgPackage < Chef::Resource::Package + use_automatic_resource_name provides :dpkg_package, os: "linux" - def initialize(name, run_context=nil) - super - @resource_name = :dpkg_package - end - end end end diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index 912b683434..cdfdff54f0 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -21,6 +21,7 @@ class Chef class Resource
class DscResource < Chef::Resource
+ use_automatic_resource_name
provides :dsc_resource, os: "windows"
include Chef::DSL::Powershell
@@ -28,7 +29,6 @@ class Chef def initialize(name, run_context)
super
@properties = {}
- @resource_name = :dsc_resource
@resource = nil
@allowed_actions.push(:run)
@action = :run
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index cf96ef6b7f..4eabb92438 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -22,13 +22,13 @@ class Chef class Resource class DscScript < Chef::Resource + use_automatic_resource_name provides :dsc_script, platform: "windows" def initialize(name, run_context=nil) super @allowed_actions.push(:run) @action = :run - @resource_name = :dsc_script @imports = {} end diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb index 5286e9a289..2483b0a8b7 100644 --- a/lib/chef/resource/easy_install_package.rb +++ b/lib/chef/resource/easy_install_package.rb @@ -22,12 +22,7 @@ class Chef class Resource class EasyInstallPackage < Chef::Resource::Package - provides :easy_install_package - - def initialize(name, run_context=nil) - super - @resource_name = :easy_install_package - end + use_automatic_resource_name def easy_install_binary(arg=nil) set_or_return( diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index 2072ae5d80..d74b4feee0 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -25,11 +25,11 @@ class Chef state_attrs :value + use_automatic_resource_name provides :env, os: "windows" def initialize(name, run_context=nil) super - @resource_name = :env @key_name = name @value = nil @action = :create diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb index 75422c55a1..c6d45c7aca 100644 --- a/lib/chef/resource/erl_call.rb +++ b/lib/chef/resource/erl_call.rb @@ -23,7 +23,7 @@ require 'chef/provider/erl_call' class Chef class Resource class ErlCall < Chef::Resource - provides :erl_call + use_automatic_resource_name # erl_call : http://erlang.org/doc/man/erl_call.html @@ -31,7 +31,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :erl_call @code = "q()." # your erlang code goes here @cookie = nil # cookie of the erlang node diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index 8fc97d748f..c0263501c5 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -23,7 +23,7 @@ require 'chef/provider/execute' class Chef class Resource class Execute < Chef::Resource - provides :execute + use_automatic_resource_name identity_attr :command @@ -35,7 +35,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :execute @command = name @backup = 5 @action = "run" diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index b36fcc2135..32fd984f8c 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -47,11 +47,10 @@ class Chef # @returns [String] Checksum of the file we actually rendered attr_accessor :final_checksum - provides :file + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :file @path = name @backup = 5 @action = "create" diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index 9c8db506f8..f89e1813b9 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -29,13 +29,9 @@ class Chef class FreebsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut + use_automatic_resource_name provides :package, platform: "freebsd" - def initialize(name, run_context=nil) - super - @resource_name = :freebsd_package - end - def after_created assign_provider end diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb index 0e838ca040..5bd3a89100 100644 --- a/lib/chef/resource/gem_package.rb +++ b/lib/chef/resource/gem_package.rb @@ -22,11 +22,10 @@ class Chef class Resource class GemPackage < Chef::Resource::Package - provides :gem_package + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :gem_package @clear_sources = false end diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb index 7156873315..1229914766 100644 --- a/lib/chef/resource/git.rb +++ b/lib/chef/resource/git.rb @@ -22,11 +22,10 @@ class Chef class Resource class Git < Chef::Resource::Scm - provides :git + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :git @additional_remotes = Hash[] end diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 9e8f1309b0..64062dbe8f 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -25,11 +25,10 @@ class Chef state_attrs :members - provides :group + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :group @group_name = name @gid = nil @members = [] diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb index 73409b13ac..fe0bd89ced 100644 --- a/lib/chef/resource/homebrew_package.rb +++ b/lib/chef/resource/homebrew_package.rb @@ -25,12 +25,11 @@ class Chef class Resource class HomebrewPackage < Chef::Resource::Package - provides :homebrew_package + use_automatic_resource_name provides :package, os: "darwin" def initialize(name, run_context=nil) super - @resource_name = :homebrew_package @homebrew_user = nil end diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb index 5986ebd4a0..ea22a26456 100644 --- a/lib/chef/resource/http_request.rb +++ b/lib/chef/resource/http_request.rb @@ -23,13 +23,12 @@ require 'chef/provider/http_request' class Chef class Resource class HttpRequest < Chef::Resource - provides :http_request + use_automatic_resource_name identity_attr :url def initialize(name, run_context=nil) super - @resource_name = :http_request @message = name @url = nil @action = :get diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb index 60feba1704..18a688c2a5 100644 --- a/lib/chef/resource/ifconfig.rb +++ b/lib/chef/resource/ifconfig.rb @@ -22,7 +22,7 @@ require 'chef/resource' class Chef class Resource class Ifconfig < Chef::Resource - provides :ifconfig + use_automatic_resource_name identity_attr :device @@ -30,7 +30,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :ifconfig @target = name @action = :add @allowed_actions.push(:add, :delete, :enable, :disable) diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb index c0e699e31a..93b554eb6c 100644 --- a/lib/chef/resource/ips_package.rb +++ b/lib/chef/resource/ips_package.rb @@ -23,11 +23,11 @@ class Chef class Resource class IpsPackage < ::Chef::Resource::Package + use_automatic_resource_name provides :ips_package, os: "solaris2" def initialize(name, run_context = nil) super(name, run_context) - @resource_name = :ips_package @allowed_actions.push(:install, :remove, :upgrade) @accept_license = false end diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 30f8ec86d1..84a2b94ca1 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -25,7 +25,7 @@ class Chef class Link < Chef::Resource include Chef::Mixin::Securable - provides :link + use_automatic_resource_name identity_attr :target_file @@ -34,7 +34,6 @@ class Chef def initialize(name, run_context=nil) verify_links_supported! super - @resource_name = :link @to = nil @action = :create @link_type = :symbolic diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index 87be01aaa9..5b4081b0fe 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -23,7 +23,7 @@ require 'chef/provider/log' class Chef class Resource class Log < Chef::Resource - provides :log + use_automatic_resource_name identity_attr :message @@ -49,7 +49,6 @@ class Chef # node<Chef::Node>:: Node where resource will be used def initialize(name, run_context=nil) super - @resource_name = :log @level = :info @action = :write @allowed_actions.push(:write) diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index a42261cfc4..129fc38d6f 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -35,8 +35,6 @@ class Chef # so attributes, default action, etc. can be defined with pleasing syntax. class LWRPBase < Resource - NULL_ARG = Object.new - # Class methods class <<self @@ -55,12 +53,11 @@ class Chef # We load the class first to give it a chance to set its own name resource_class = Class.new(self) - resource_class.resource_name = resource_name + resource_class.resource_name resource_name.to_sym resource_class.run_context = run_context - resource_class.provides resource_name.to_sym resource_class.class_from_file(filename) - # Respect resource_name set inside the LWRP + # Make a useful string for the class (rather than <Class:312894723894>) resource_class.instance_eval do define_singleton_method(:to_s) do "LWRP resource #{resource_name} from cookbook #{cookbook_name}" @@ -77,16 +74,6 @@ class Chef resource_class end - def resource_name(arg = NULL_ARG) - if arg.equal?(NULL_ARG) - @resource_name - else - @resource_name = arg - end - end - - alias_method :resource_name=, :resource_name - # Define an attribute on this resource, including optional validation # parameters. def attribute(attr_name, validation_opts={}) @@ -166,16 +153,8 @@ class Chef private # Default initializer. Sets the default action and allowed actions. - def initialize(name, run_context=nil) - super(name, run_context) - - # Raise an exception if the resource_name was not defined - if self.class.resource_name.nil? - raise Chef::Exceptions::InvalidResourceSpecification, - "You must specify `resource_name'!" - end - - @resource_name = self.class.resource_name.to_sym + def initialize(*args, &block) + super @action = self.class.default_action allowed_actions.push(self.class.actions).flatten! end diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb index 879ea99cf8..29da2e6309 100644 --- a/lib/chef/resource/macosx_service.rb +++ b/lib/chef/resource/macosx_service.rb @@ -22,8 +22,9 @@ class Chef class Resource class MacosxService < Chef::Resource::Service - provides :service, os: "darwin" + use_automatic_resource_name provides :macosx_service, os: "darwin" + provides :service, os: "darwin" identity_attr :service_name @@ -31,7 +32,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :macosx_service @plist = nil @session_type = nil end diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb index 0d4e5dec65..3ccf831cf2 100644 --- a/lib/chef/resource/macports_package.rb +++ b/lib/chef/resource/macports_package.rb @@ -20,13 +20,8 @@ class Chef class Resource class MacportsPackage < Chef::Resource::Package - provides :macports_package + use_automatic_resource_name provides :package, os: "darwin" - - def initialize(name, run_context=nil) - super - @resource_name = :macports_package - end end end end diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb index 971b6c51b4..8f19410b9c 100644 --- a/lib/chef/resource/mdadm.rb +++ b/lib/chef/resource/mdadm.rb @@ -27,11 +27,10 @@ class Chef state_attrs :devices, :level, :chunk - provides :mdadm + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :mdadm @chunk = 16 @devices = [] diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index 142dec87f7..f8a0cd157b 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -27,11 +27,10 @@ class Chef state_attrs :mount_point, :device_type, :fstype, :username, :password, :domain - provides :mount + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :mount @mount_point = name @device = nil @device_type = :device diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb index e2d12ce395..be24e97bde 100644 --- a/lib/chef/resource/ohai.rb +++ b/lib/chef/resource/ohai.rb @@ -20,7 +20,7 @@ class Chef class Resource class Ohai < Chef::Resource - provides :ohai + use_automatic_resource_name identity_attr :name @@ -28,7 +28,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :ohai @name = name @allowed_actions.push(:reload) @action = :reload diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb index 20a2523e3a..1071958cd2 100644 --- a/lib/chef/resource/openbsd_package.rb +++ b/lib/chef/resource/openbsd_package.rb @@ -28,13 +28,9 @@ class Chef class OpenbsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut + use_automatic_resource_name provides :package, os: "openbsd" - def initialize(name, run_context=nil) - super - @resource_name = :openbsd_package - end - def after_created assign_provider end @@ -48,4 +44,3 @@ class Chef end end end - diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb index 5bea894a02..0f4a5359ae 100644 --- a/lib/chef/resource/package.rb +++ b/lib/chef/resource/package.rb @@ -22,7 +22,7 @@ require 'chef/resource' class Chef class Resource class Package < Chef::Resource - provides :package + use_automatic_resource_name identity_attr :package_name @@ -35,7 +35,6 @@ class Chef @candidate_version = nil @options = nil @package_name = name - @resource_name = :package @response_file = nil @response_file_variables = Hash.new @source = nil diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb index 4c45dd004f..222fb3c78e 100644 --- a/lib/chef/resource/pacman_package.rb +++ b/lib/chef/resource/pacman_package.rb @@ -22,13 +22,9 @@ class Chef class Resource class PacmanPackage < Chef::Resource::Package + use_automatic_resource_name provides :pacman_package, os: "linux" - def initialize(name, run_context=nil) - super - @resource_name = :pacman_package - end - end end end diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb index 552c96857a..0907ba71a9 100644 --- a/lib/chef/resource/paludis_package.rb +++ b/lib/chef/resource/paludis_package.rb @@ -23,11 +23,11 @@ class Chef class Resource class PaludisPackage < Chef::Resource::Package + use_automatic_resource_name provides :paludis_package, os: "linux" def initialize(name, run_context=nil) super(name, run_context) - @resource_name = :paludis_package @allowed_actions.push(:install, :remove, :upgrade) @timeout = 3600 end diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb index cb741d145a..6870f487eb 100644 --- a/lib/chef/resource/perl.rb +++ b/lib/chef/resource/perl.rb @@ -22,11 +22,10 @@ require 'chef/provider/script' class Chef class Resource class Perl < Chef::Resource::Script - provides :perl + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :perl @interpreter = "perl" end diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb index b03b69796a..009a525d22 100644 --- a/lib/chef/resource/portage_package.rb +++ b/lib/chef/resource/portage_package.rb @@ -21,11 +21,10 @@ require 'chef/resource/package' class Chef class Resource class PortagePackage < Chef::Resource::Package - provides :portage_package + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :portage_package @provider = Chef::Provider::Package::Portage end diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index 43aafe4df2..a3a24fce7f 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -21,10 +21,11 @@ class Chef class Resource class PowershellScript < Chef::Resource::WindowsScript + use_automatic_resource_name provides :powershell_script, os: "windows" def initialize(name, run_context=nil) - super(name, run_context, :powershell_script, "powershell.exe") + super(name, run_context, nil, "powershell.exe") @convert_boolean_return = false end diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb index fffd4d75f6..5c120d7d27 100644 --- a/lib/chef/resource/python.rb +++ b/lib/chef/resource/python.rb @@ -21,11 +21,10 @@ require 'chef/provider/script' class Chef class Resource class Python < Chef::Resource::Script - provides :python + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :python @interpreter = "python" end diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index 7cd53450ed..c2a4ff29e2 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -24,11 +24,10 @@ require 'chef/resource' class Chef class Resource class Reboot < Chef::Resource - provides :reboot + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :reboot @provider = Chef::Provider::Reboot @allowed_actions.push(:request_reboot, :reboot_now, :cancel) diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index cc8d05dd53..5a700e5365 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -22,7 +22,7 @@ require 'chef/digester' class Chef class Resource class RegistryKey < Chef::Resource - provides :registry_key + use_automatic_resource_name identity_attr :key state_attrs :values @@ -60,7 +60,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :registry_key @action = :create @architecture = :machine @recursive = false diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index d4108da47a..a35e0995b0 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -26,7 +26,7 @@ class Chef class RemoteDirectory < Chef::Resource::Directory include Chef::Mixin::Securable - provides :remote_directory + use_automatic_resource_name identity_attr :path @@ -34,7 +34,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :remote_directory @path = name @source = ::File.basename(name) @delete = false diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index df9fb7ad76..603151357c 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -28,11 +28,10 @@ class Chef class RemoteFile < Chef::Resource::File include Chef::Mixin::Securable - provides :remote_file + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :remote_file @action = "create" @source = [] @use_etag = true diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb index 8f9172060b..aca2a52e87 100644 --- a/lib/chef/resource/route.rb +++ b/lib/chef/resource/route.rb @@ -22,7 +22,7 @@ require 'chef/resource' class Chef class Resource class Route < Chef::Resource - provides :route + use_automatic_resource_name identity_attr :target @@ -30,7 +30,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :route @target = name @action = [:add] @allowed_actions.push(:add, :delete) diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb index f00121dd69..67a6c156d8 100644 --- a/lib/chef/resource/rpm_package.rb +++ b/lib/chef/resource/rpm_package.rb @@ -23,11 +23,11 @@ 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) super - @resource_name = :rpm_package @allow_downgrade = false end diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb index 2b7644562a..759955da42 100644 --- a/lib/chef/resource/ruby.rb +++ b/lib/chef/resource/ruby.rb @@ -22,11 +22,10 @@ require 'chef/provider/script' class Chef class Resource class Ruby < Chef::Resource::Script - provides :ruby + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :ruby @interpreter = "ruby" end diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb index 07eec5599d..e4667533f2 100644 --- a/lib/chef/resource/ruby_block.rb +++ b/lib/chef/resource/ruby_block.rb @@ -23,13 +23,12 @@ require 'chef/provider/ruby_block' class Chef class Resource class RubyBlock < Chef::Resource - provides :ruby_block + use_automatic_resource_name identity_attr :block_name def initialize(name, run_context=nil) super - @resource_name = :ruby_block @action = "run" @allowed_actions << :create << :run @block_name = name diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb index d41764d595..c97090d0a5 100644 --- a/lib/chef/resource/scm.rb +++ b/lib/chef/resource/scm.rb @@ -22,7 +22,7 @@ require 'chef/resource' class Chef class Resource class Scm < Chef::Resource - provides :scm + use_automatic_resource_name identity_attr :destination @@ -31,7 +31,6 @@ class Chef def initialize(name, run_context=nil) super @destination = name - @resource_name = :scm @enable_submodules = false @enable_checkout = true @revision = "HEAD" diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb index e2fbb29d0f..f3d3ef01f4 100644 --- a/lib/chef/resource/script.rb +++ b/lib/chef/resource/script.rb @@ -23,14 +23,13 @@ require 'chef/provider/script' class Chef class Resource class Script < Chef::Resource::Execute - provides :script + use_automatic_resource_name # Chef-13: go back to using :name as the identity attr identity_attr :command def initialize(name, run_context=nil) super - @resource_name = :script # Chef-13: the command variable should be initialized to nil @command = name @code = nil diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 47d2ab9e12..6ef203db3b 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -22,7 +22,7 @@ require 'chef/resource' class Chef class Resource class Service < Chef::Resource - provides :service + use_automatic_resource_name identity_attr :service_name @@ -30,7 +30,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :service @service_name = name @enabled = nil @running = nil diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb index 99b3b953b0..7460f0f687 100644 --- a/lib/chef/resource/smartos_package.rb +++ b/lib/chef/resource/smartos_package.rb @@ -23,15 +23,9 @@ class Chef class Resource class SmartosPackage < Chef::Resource::Package - provides :smartos_package + use_automatic_resource_name provides :package, os: "solaris2", platform_family: "smartos" - def initialize(name, run_context=nil) - super - @resource_name = :smartos_package - end - end end end - diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb index 94be4693b6..545e783b75 100644 --- a/lib/chef/resource/solaris_package.rb +++ b/lib/chef/resource/solaris_package.rb @@ -24,20 +24,13 @@ class Chef class Resource class SolarisPackage < Chef::Resource::Package - provides :solaris_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 - def initialize(name, run_context=nil) - super - @resource_name = :solaris_package - end - end end end - - diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb index e5a2e9d1a5..f1b0391a8c 100644 --- a/lib/chef/resource/subversion.rb +++ b/lib/chef/resource/subversion.rb @@ -22,13 +22,12 @@ require "chef/resource/scm" class Chef class Resource class Subversion < Chef::Resource::Scm - provides :subversion + use_automatic_resource_name def initialize(name, run_context=nil) super @svn_arguments = '--no-auth-cache' @svn_info_args = '--no-auth-cache' - @resource_name = :subversion allowed_actions << :force_export end diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb index 67a9e6a418..2c7ade6c29 100644 --- a/lib/chef/resource/template.rb +++ b/lib/chef/resource/template.rb @@ -27,14 +27,13 @@ class Chef class Template < Chef::Resource::File include Chef::Mixin::Securable - provides :template + use_automatic_resource_name attr_reader :inline_helper_blocks attr_reader :inline_helper_modules def initialize(name, run_context=nil) super - @resource_name = :template @action = "create" @source = "#{::File.basename(name)}.erb" @cookbook = nil diff --git a/lib/chef/resource/timestamped_deploy.rb b/lib/chef/resource/timestamped_deploy.rb index b2109db85c..15ac296f78 100644 --- a/lib/chef/resource/timestamped_deploy.rb +++ b/lib/chef/resource/timestamped_deploy.rb @@ -21,10 +21,7 @@ class Chef # Convenience class for using the deploy resource with the timestamped # deployment strategy (provider) class TimestampedDeploy < Chef::Resource::Deploy - provides :timestamped_deploy - def initialize(*args, &block) - super(*args, &block) - end + use_automatic_resource_name end end end diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index 7d2ec25596..b762001d4b 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -26,11 +26,10 @@ class Chef state_attrs :uid, :gid, :home - provides :user + use_automatic_resource_name def initialize(name, run_context=nil) super - @resource_name = :user @username = name @comment = nil @uid = nil diff --git a/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb index f512dc67fc..0ade9c981f 100644 --- a/lib/chef/resource/whyrun_safe_ruby_block.rb +++ b/lib/chef/resource/whyrun_safe_ruby_block.rb @@ -19,12 +19,8 @@ class Chef class Resource class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock - provides :whyrun_safe_ruby_block - def initialize(name, run_context=nil) - super - @resource_name = :whyrun_safe_ruby_block - end + use_automatic_resource_name end end diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb index d4f8ae0603..8f9944a5af 100644 --- a/lib/chef/resource/windows_package.rb +++ b/lib/chef/resource/windows_package.rb @@ -26,13 +26,13 @@ class Chef class WindowsPackage < Chef::Resource::Package include Chef::Mixin::Uris - provides :package, os: "windows" + use_automatic_resource_name provides :windows_package, os: "windows" + provides :package, os: "windows" def initialize(name, run_context=nil) super @allowed_actions.push(:install, :remove) - @resource_name = :windows_package @source ||= source(@package_name) # Unique to this resource diff --git a/lib/chef/resource/windows_script.rb b/lib/chef/resource/windows_script.rb index 1af7a48fe4..48e2b535a8 100644 --- a/lib/chef/resource/windows_script.rb +++ b/lib/chef/resource/windows_script.rb @@ -31,8 +31,8 @@ class Chef def initialize(name, run_context, resource_name, interpreter_command) super(name, run_context) @interpreter = interpreter_command - @resource_name = resource_name - @default_guard_interpreter = resource_name + @resource_name = resource_name if resource_name + @default_guard_interpreter = self.resource_name end include Chef::Mixin::WindowsArchitectureHelper diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 8090adceb0..3f62a67a82 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -25,8 +25,9 @@ class Chef # Until #1773 is resolved, you need to manually specify the windows_service resource # to use action :configure_startup and attribute startup_type - provides :service, os: "windows" + use_automatic_resource_name provides :windows_service, os: "windows" + provides :service, os: "windows" identity_attr :service_name @@ -34,7 +35,6 @@ class Chef def initialize(name, run_context=nil) super - @resource_name = :windows_service @allowed_actions.push(:configure_startup) @startup_type = :automatic @run_as_user = "" diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb index d8be8c9748..ae9c840582 100644 --- a/lib/chef/resource/yum_package.rb +++ b/lib/chef/resource/yum_package.rb @@ -23,12 +23,11 @@ class Chef class Resource class YumPackage < Chef::Resource::Package - provides :yum_package + use_automatic_resource_name provides :package, os: "linux", platform_family: [ "rhel", "fedora" ] def initialize(name, run_context=nil) super - @resource_name = :yum_package @flush_cache = { :before => false, :after => false } @allow_downgrade = false end diff --git a/lib/chef/resource_builder.rb b/lib/chef/resource_builder.rb index bb0962d128..9e9f7047a4 100644 --- a/lib/chef/resource_builder.rb +++ b/lib/chef/resource_builder.rb @@ -18,6 +18,10 @@ # NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb +require 'chef/exceptions' +require 'chef/resource' +require 'chef/log' + class Chef class ResourceBuilder attr_reader :type @@ -46,6 +50,9 @@ class Chef raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil? @resource = resource_class.new(name, run_context) + if resource.resource_name.nil? + raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?" + end resource.source_line = created_at resource.declared_type = type |