summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2017-04-05 11:56:25 -0700
committerGitHub <noreply@github.com>2017-04-05 11:56:25 -0700
commite85e77f24054df64ccd412cc9cedb9cba641706c (patch)
tree2cfff8b251b6f278f15911ae573cb132b92b7394
parentf147f49999500379cc9200c9163631445be3a3ff (diff)
parent737bdca4a68c8abf66cec82bb7d1bb360a7ab18e (diff)
downloadchef-e85e77f24054df64ccd412cc9cedb9cba641706c.tar.gz
Merge pull request #6013 from coderanger/always-inline
Remove use_inline_resources
-rw-r--r--RELEASE_NOTES.md6
-rw-r--r--lib/chef/deprecated.rb10
-rw-r--r--lib/chef/provider.rb120
-rw-r--r--lib/chef/provider/apt_repository.rb2
-rw-r--r--lib/chef/provider/apt_update.rb2
-rw-r--r--lib/chef/provider/lwrp_base.rb7
-rw-r--r--lib/chef/provider/ohai.rb2
-rw-r--r--lib/chef/provider/package.rb2
-rw-r--r--lib/chef/provider/package/cab.rb1
-rw-r--r--lib/chef/provider/package/msu.rb1
-rw-r--r--lib/chef/provider/yum_repository.rb2
-rw-r--r--lib/chef/resource/action_class.rb2
-rw-r--r--spec/data/lwrp/providers/buck_passer.rb2
-rw-r--r--spec/data/lwrp/providers/buck_passer_2.rb2
-rw-r--r--spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb2
-rw-r--r--spec/data/lwrp/providers/inline_compiler.rb2
-rw-r--r--spec/integration/recipes/lwrp_inline_resources_spec.rb18
-rw-r--r--spec/unit/lwrp_spec.rb2
-rw-r--r--spec/unit/provider_spec.rb7
19 files changed, 75 insertions, 117 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 0a34e3c17a..b16550b8e6 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -263,3 +263,9 @@ Please use `knife cookbook site install` instead.
Rather than `attributes/default.rb`, cookbooks can now use `attributes.rb` in
the root of the cookbook. Similarly for a single default recipe, cookbooks can
use `recipe.rb` in the root of the cookbook.
+
+### `use_inline_resources` is always enabled
+
+The `use_inline_resources` provider mode is always enabled when using the
+`action :name do ... end` syntax. You can remove the `use_inline_resources`
+line.
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
diff --git a/spec/data/lwrp/providers/buck_passer.rb b/spec/data/lwrp/providers/buck_passer.rb
index 2bbca07bf7..0bbd413867 100644
--- a/spec/data/lwrp/providers/buck_passer.rb
+++ b/spec/data/lwrp/providers/buck_passer.rb
@@ -10,7 +10,7 @@ def without_deprecation_warnings(&block)
end
end
-action :pass_buck do
+def action_pass_buck
lwrp_foo :prepared_thumbs do
action :prepare_thumbs
# We know there will be a deprecation error here; head it off
diff --git a/spec/data/lwrp/providers/buck_passer_2.rb b/spec/data/lwrp/providers/buck_passer_2.rb
index c3bab7266f..980506c671 100644
--- a/spec/data/lwrp/providers/buck_passer_2.rb
+++ b/spec/data/lwrp/providers/buck_passer_2.rb
@@ -8,7 +8,7 @@ def without_deprecation_warnings(&block)
end
end
-action :pass_buck do
+def action_pass_buck
lwrp_bar :prepared_eyes do
action :prepare_eyes
# We know there will be a deprecation error here; head it off
diff --git a/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb b/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb
index 77c1111ff5..d6996da55e 100644
--- a/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb
+++ b/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb
@@ -13,7 +13,7 @@ def without_deprecation_warnings(&block)
end
end
-action :twiddle_thumbs do
+def action_twiddle_thumbs
@enclosed_resource = lwrp_foo :foo do
monkey generate_new_name(new_resource.monkey){ 'the monkey' }
# We know there will be a deprecation error here; head it off
diff --git a/spec/data/lwrp/providers/inline_compiler.rb b/spec/data/lwrp/providers/inline_compiler.rb
index 2535276b24..91a80b32af 100644
--- a/spec/data/lwrp/providers/inline_compiler.rb
+++ b/spec/data/lwrp/providers/inline_compiler.rb
@@ -1,6 +1,4 @@
-use_inline_resources
-
action :test do
ruby_block "interior-ruby-block-1" do
diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb
index 65931d4764..54ce94f263 100644
--- a/spec/integration/recipes/lwrp_inline_resources_spec.rb
+++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb
@@ -19,14 +19,13 @@ describe "LWRPs with inline resources" do
let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" }
context "with a use_inline_resources provider with 'def action_a' instead of action :a" do
- class LwrpInlineResourcesTest < Chef::Resource::LWRPBase
+ class LwrpInlineResourcesTest < Chef::Resource
resource_name :lwrp_inline_resources_test
- actions :a, :nothing
+ allowed_actions :a, :nothing
default_action :a
property :ran_a
class Provider < Chef::Provider::LWRPBase
provides :lwrp_inline_resources_test
- use_inline_resources
def action_a
r = new_resource
ruby_block "run a" do
@@ -46,10 +45,10 @@ describe "LWRPs with inline resources" do
end
context "with an inline resource with a property that shadows the enclosing provider's property" do
- class LwrpShadowedPropertyTest < Chef::Resource::LWRPBase
+ class LwrpShadowedPropertyTest < Chef::Resource
PATH = ::File.join(Dir.tmpdir, "shadow-property.txt")
use_automatic_resource_name
- actions :fiddle
+ allowed_actions :fiddle
property :content
action :fiddle do
file PATH do
@@ -73,16 +72,14 @@ describe "LWRPs with inline resources" do
end
context "with an inline_resources provider with two actions, one calling the other" do
- class LwrpInlineResourcesTest2 < Chef::Resource::LWRPBase
+ class LwrpInlineResourcesTest2 < Chef::Resource
resource_name :lwrp_inline_resources_test2
- actions :a, :b, :nothing
+ allowed_actions :a, :b, :nothing
default_action :b
property :ran_a
property :ran_b
class Provider < Chef::Provider::LWRPBase
provides :lwrp_inline_resources_test2
- use_inline_resources
-
action :a do
r = new_resource
ruby_block "run a" do
@@ -133,8 +130,7 @@ describe "LWRPs with inline resources" do
default_action :create
EOM
file "providers/my_machine.rb", <<-EOM
- use_inline_resources
- action :create do
+ action :create do
x_do_nothing 'a'
x_do_nothing 'b'
end
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 353376aa77..75ebbb8f02 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -644,8 +644,6 @@ describe "LWRP" do
end
class MyAwesomeProvider < Chef::Provider::LWRPBase
- use_inline_resources
-
provides :my_awesome_resource
action :create do
diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb
index f252d3177d..6eb2bb9303 100644
--- a/spec/unit/provider_spec.rb
+++ b/spec/unit/provider_spec.rb
@@ -195,4 +195,11 @@ describe Chef::Provider do
end
end
+ context "when using use_inline_resources" do
+ it "should log a deprecation warning" do
+ pending Chef::VERSION.start_with?("13.6")
+ expect(Chef).to receive(:deprecated).with(:use_inline_resources, kind_of(String))
+ Class.new(described_class) { use_inline_resources }
+ end
+ end
end