summaryrefslogtreecommitdiff
path: root/chef
diff options
context:
space:
mode:
authorKris Rasmussen <kristopher.rasmussen@gmail.com>2009-12-31 01:07:17 -0800
committerAdam Jacob <adam@opscode.com>2010-01-04 12:15:39 -0800
commite8790be2e57d386728f3014c12be2aff9c98414f (patch)
tree10479f50a9a0a188482b6d982f7c2ea9b376fb36 /chef
parent7ec4f6a10170eaaa6cc818a74550395d24af44e1 (diff)
downloadchef-e8790be2e57d386728f3014c12be2aff9c98414f.tar.gz
Execute delayed actions in order, Fixes CHEF-837
This new spec fails without the corresponding runner changes.
Diffstat (limited to 'chef')
-rw-r--r--chef/lib/chef/runner.rb15
-rw-r--r--chef/spec/unit/runner_spec.rb15
2 files changed, 20 insertions, 10 deletions
diff --git a/chef/lib/chef/runner.rb b/chef/lib/chef/runner.rb
index 03e5106b7a..b39625329d 100644
--- a/chef/lib/chef/runner.rb
+++ b/chef/lib/chef/runner.rb
@@ -71,7 +71,10 @@ class Chef
if resource.actions[action].has_key?(:delayed)
resource.actions[action][:delayed].each do |r|
@delayed_actions[r] = Hash.new unless @delayed_actions.has_key?(r)
- @delayed_actions[r][action] = Array.new unless @delayed_actions[r].has_key?(action)
+ unless @delayed_actions[r].has_key?(action)
+ @ordered_delayed_actions << [r, action]
+ @delayed_actions[r][action] = Array.new
+ end
@delayed_actions[r][action] << lambda {
Chef::Log.info("#{resource} sending #{action} action to #{r} (delayed)")
}
@@ -84,6 +87,7 @@ class Chef
def converge
@delayed_actions = Hash.new
+ @ordered_delayed_actions = []
@collection.execute_each_resource do |resource|
begin
@@ -117,11 +121,10 @@ class Chef
end
# Run all our :delayed actions
- @delayed_actions.each do |resource, action_hash|
- action_hash.each do |action, log_array|
- log_array.each { |l| l.call } # Call each log message
- run_action(resource, action)
- end
+ @ordered_delayed_actions.each do |resource, action|
+ log_array = @delayed_actions[resource][action]
+ log_array.each { |l| l.call } # Call each log message
+ run_action(resource, action)
end
true
diff --git a/chef/spec/unit/runner_spec.rb b/chef/spec/unit/runner_spec.rb
index c1400af22f..c7ce79e9d8 100644
--- a/chef/spec/unit/runner_spec.rb
+++ b/chef/spec/unit/runner_spec.rb
@@ -25,7 +25,7 @@ describe Chef::Runner do
@node.platform "mac_os_x"
@node.platform_version "10.5.1"
@collection = Chef::ResourceCollection.new()
- @collection << Chef::Resource::Cat.new("loulou", @collection)
+ @collection << Chef::Resource::Cat.new("loulou1", @collection)
Chef::Platform.set(
:resource => :cat,
:provider => Chef::Provider::SnakeOil
@@ -155,17 +155,24 @@ describe Chef::Runner do
@runner.converge
end
- it "should collapse delayed actions on changed resources" do
+ it "should collapse delayed actions on changed resources and execute them in the order they were encountered" do
Chef::Platform.stub!(:find_provider_for_node).and_return(Chef::Provider::SnakeOil)
provider = Chef::Provider::SnakeOil.new(@node, @collection[0])
- Chef::Provider::SnakeOil.stub!(:new).and_return(provider)
+ Chef::Provider::SnakeOil.stub!(:new).and_return(provider)
cat = Chef::Resource::Cat.new("peanut", @collection)
cat.notifies :buy, @collection[0], :delayed
cat.updated = true
@collection << cat
@collection << cat
- provider.should_receive(:action_buy).once.and_return(true)
+ cat2 = Chef::Resource::Cat.new("snickers", @collection)
+ cat2.notifies :pur, @collection[1], :delayed
+ cat2.notifies :pur, @collection[1], :delayed
+ cat2.updated = true
+ @collection << cat2
+ provider.should_receive(:action_buy).once.ordered
+ provider.should_receive(:action_pur).once.ordered
@runner.converge
end
+
end