diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/deprecated.rb | 10 | ||||
-rw-r--r-- | lib/chef/provider.rb | 120 | ||||
-rw-r--r-- | lib/chef/provider/apt_repository.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/apt_update.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/lwrp_base.rb | 7 | ||||
-rw-r--r-- | lib/chef/provider/ohai.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/cab.rb | 1 | ||||
-rw-r--r-- | lib/chef/provider/package/msu.rb | 1 | ||||
-rw-r--r-- | lib/chef/provider/yum_repository.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource/action_class.rb | 2 |
11 files changed, 52 insertions, 99 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb index d4db0813c7..04ecfe5a6e 100644 --- a/lib/chef/deprecated.rb +++ b/lib/chef/deprecated.rb @@ -228,6 +228,16 @@ class Chef end end + class UseInlineResources < Base + def id + 17 + end + + def target + "use_inline_resources.html" + end + end + # id 3694 was deleted class Generic < Base diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index ce2f431fec..c7048d50e5 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -51,6 +51,32 @@ class Chef true end + # Defines an action method on the provider, running the block to compile the + # resources, converging them, and then checking if any were updated (and + # updating new-resource if so) + # + # @since 13.0 + # @param name [String, Symbol] Name of the action to define. + # @param block [Proc] Body of the action. + # @return [void] + def self.action(name, &block) + # We need the block directly in a method so that `super` works. + define_method("compile_action_#{name}", &block) + class_eval <<-EOM + def action_#{name} + compile_and_converge_action { compile_action_#{name} } + end + EOM + end + + # Deprecation stub for the old use_inline_resources mode. + # + # @return [void] + def self.use_inline_resources + # Uncomment this in Chef 13.6. + # Chef.deprecated(:use_inline_resources, "The use_inline_resources mode is no longer optional and the line enabling it can be removed") + end + #-- # TODO: this should be a reader, and the action should be passed in the # constructor; however, many/most subclasses override the constructor so @@ -176,6 +202,22 @@ class Chef converge_actions.add_action(descriptions, &block) end + # Create a child run_context, compile the block, and converge it. + # + # @api private + def compile_and_converge_action(&block) + old_run_context = run_context + @run_context = run_context.create_child + return_value = instance_eval(&block) + Chef::Runner.new(run_context).converge + return_value + ensure + if run_context.resource_collection.any? { |r| r.updated? } + new_resource.updated_by_last_action(true) + end + @run_context = old_run_context + end + # # Handle patchy convergence safely. # @@ -326,84 +368,6 @@ class Chef end end - # Enables inline evaluation of resources in provider actions. - # - # Without this option, any resources declared inside the Provider are added - # to the resource collection after the current position at the time the - # action is executed. Because they are added to the primary resource - # collection for the chef run, they can notify other resources outside - # the Provider, and potentially be notified by resources outside the Provider - # (but this is complicated by the fact that they don't exist until the - # provider executes). In this mode, it is impossible to correctly set the - # updated_by_last_action flag on the parent Provider resource, since it - # executes and returns before its component resources are run. - # - # With this option enabled, each action creates a temporary run_context - # with its own resource collection, evaluates the action's code in that - # context, and then converges the resources created. If any resources - # were updated, then this provider's new_resource will be marked updated. - # - # In this mode, resources created within the Provider cannot interact with - # external resources via notifies, though notifications to other - # resources within the Provider will work. Delayed notifications are executed - # at the conclusion of the provider's action, *not* at the end of the - # main chef run. - # - # This mode of evaluation is experimental, but is believed to be a better - # set of tradeoffs than the append-after mode, so it will likely become - # the default in a future major release of Chef. - # - def self.use_inline_resources - extend InlineResources::ClassMethods - include InlineResources - end - - # Chef::Provider::InlineResources - # Implementation of inline resource convergence for providers. See - # Provider.use_inline_resources for a longer explanation. - # - # This code is restricted to a module so that it can be selectively - # applied to providers on an opt-in basis. - # - # @api private - module InlineResources - - # Create a child run_context, compile the block, and converge it. - # - # @api private - def compile_and_converge_action(&block) - old_run_context = run_context - @run_context = run_context.create_child - return_value = instance_eval(&block) - Chef::Runner.new(run_context).converge - return_value - ensure - if run_context.resource_collection.any? { |r| r.updated? } - new_resource.updated_by_last_action(true) - end - @run_context = old_run_context - end - - # Class methods for InlineResources. Overrides the `action` DSL method - # with one that enables inline resource convergence. - # - # @api private - module ClassMethods - # Defines an action method on the provider, running the block to - # compile the resources, converging them, and then checking if any - # were updated (and updating new-resource if so) - def action(name, &block) - # We need the block directly in a method so that `super` works - define_method("compile_action_#{name}", &block) - class_eval <<-EOM - def action_#{name} - compile_and_converge_action { compile_action_#{name} } - end - EOM - end - end - end - protected def converge_actions diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb index 2c72849d1c..541f733e7b 100644 --- a/lib/chef/provider/apt_repository.rb +++ b/lib/chef/provider/apt_repository.rb @@ -26,8 +26,6 @@ require "chef/provider/noop" class Chef class Provider class AptRepository < Chef::Provider - use_inline_resources - include Chef::Mixin::ShellOut extend Chef::Mixin::Which diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb index 135bd64035..670f3ad7f6 100644 --- a/lib/chef/provider/apt_update.rb +++ b/lib/chef/provider/apt_update.rb @@ -23,8 +23,6 @@ require "chef/mixin/which" class Chef class Provider class AptUpdate < Chef::Provider - use_inline_resources - extend Chef::Mixin::Which provides :apt_update do diff --git a/lib/chef/provider/lwrp_base.rb b/lib/chef/provider/lwrp_base.rb index 1340b55ae4..09f90b7403 100644 --- a/lib/chef/provider/lwrp_base.rb +++ b/lib/chef/provider/lwrp_base.rb @@ -78,13 +78,6 @@ class Chef provider_class end - # DSL for defining a provider's actions. - def action(name, &block) - define_method("action_#{name}") do - instance_eval(&block) - end - end - protected def loaded_lwrps diff --git a/lib/chef/provider/ohai.rb b/lib/chef/provider/ohai.rb index 0c2397cee5..42fc450271 100644 --- a/lib/chef/provider/ohai.rb +++ b/lib/chef/provider/ohai.rb @@ -21,8 +21,6 @@ require "ohai" class Chef class Provider class Ohai < Chef::Provider - use_inline_resources - provides :ohai def load_current_resource diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index c8a1b06a55..65dda05f85 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -30,8 +30,6 @@ class Chef include Chef::Mixin::ShellOut extend Chef::Mixin::SubclassDirective - use_inline_resources - # subclasses declare this if they want all their arguments as arrays of packages and names subclass_directive :use_multipackage_api # subclasses declare this if they want sources (filenames) pulled from their package names diff --git a/lib/chef/provider/package/cab.rb b/lib/chef/provider/package/cab.rb index d6e989eb72..3a8cc507f9 100644 --- a/lib/chef/provider/package/cab.rb +++ b/lib/chef/provider/package/cab.rb @@ -26,7 +26,6 @@ class Chef class Provider class Package class Cab < Chef::Provider::Package - use_inline_resources include Chef::Mixin::ShellOut include Chef::Mixin::Uris include Chef::Mixin::Checksum diff --git a/lib/chef/provider/package/msu.rb b/lib/chef/provider/package/msu.rb index fe4a11461f..15e18feba4 100644 --- a/lib/chef/provider/package/msu.rb +++ b/lib/chef/provider/package/msu.rb @@ -32,7 +32,6 @@ class Chef class Provider class Package class Msu < Chef::Provider::Package - use_inline_resources include Chef::Mixin::ShellOut include Chef::Mixin::Uris include Chef::Mixin::Checksum diff --git a/lib/chef/provider/yum_repository.rb b/lib/chef/provider/yum_repository.rb index bcba8e676d..a5d3c2bc39 100644 --- a/lib/chef/provider/yum_repository.rb +++ b/lib/chef/provider/yum_repository.rb @@ -26,8 +26,6 @@ require "chef/provider/noop" class Chef class Provider class YumRepository < Chef::Provider - use_inline_resources - extend Chef::Mixin::Which provides :yum_repository do diff --git a/lib/chef/resource/action_class.rb b/lib/chef/resource/action_class.rb index d2d74b47e2..dce3be3244 100644 --- a/lib/chef/resource/action_class.rb +++ b/lib/chef/resource/action_class.rb @@ -64,8 +64,6 @@ class Chef @current_resource = current_resource end - use_inline_resources - # XXX: remove in Chef-14 def self.include_resource_dsl? true |