diff options
author | Augusto Becciu <augusto@becciu.org> | 2010-12-04 16:48:09 -0300 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2012-03-16 14:00:00 -0700 |
commit | 8b9feb90bf259b6954b25b7c9c56655b957e3f69 (patch) | |
tree | b7ec8713a67cee49cc008d0be4bae52712801020 | |
parent | 19a96f01fdbe559a8a97d4ba916a2f2c5d3f2854 (diff) | |
download | chef-8b9feb90bf259b6954b25b7c9c56655b957e3f69.tar.gz |
resolve notification references for second time on run_action to handle the case where resources are defined lazily in a ruby_block.
-rw-r--r-- | chef/lib/chef/runner.rb | 4 | ||||
-rw-r--r-- | chef/spec/unit/runner_spec.rb | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/chef/lib/chef/runner.rb b/chef/lib/chef/runner.rb index 9ff775e1b2..b7a5bceadc 100644 --- a/chef/lib/chef/runner.rb +++ b/chef/lib/chef/runner.rb @@ -42,6 +42,10 @@ class Chef # Determine the appropriate provider for the given resource, then # execute it. def run_action(resource, action) + # Try to resolve lazy/forward references in notifications again to handle + # the case where the resource was defined lazily (ie. in a ruby_block) + resource.resolve_notification_references + resource.run_action(action) # Execute any immediate and queue up any delayed notifications diff --git a/chef/spec/unit/runner_spec.rb b/chef/spec/unit/runner_spec.rb index f0e94f3c5a..a3014b04ef 100644 --- a/chef/spec/unit/runner_spec.rb +++ b/chef/spec/unit/runner_spec.rb @@ -280,5 +280,23 @@ describe Chef::Runner do not_if_called_times.should == 2 end + it "should resolve resource references in notifications when resources are defined lazily" do + @first_resource.action = :nothing + + lazy_resources = lambda { + last_resource = Chef::Resource::Cat.new("peanut", @run_context) + @run_context.resource_collection << last_resource + last_resource.notifies(:purr, @first_resource.to_s, :delayed) + last_resource.action = :purr + } + second_resource = Chef::Resource::RubyBlock.new("myblock", @run_context) + @run_context.resource_collection << second_resource + second_resource.block { lazy_resources.call } + + @runner.converge + + @first_resource.should be_updated + end + end |