diff options
-rw-r--r-- | lib/puppet/transaction.rb | 7 | ||||
-rwxr-xr-x | spec/unit/transaction.rb | 50 |
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 4d82d3331..e9a193464 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -3,6 +3,7 @@ require 'puppet' require 'puppet/util/tagging' +require 'puppet/application' class Puppet::Transaction require 'puppet/transaction/change' @@ -26,6 +27,11 @@ class Puppet::Transaction include Puppet::Util include Puppet::Util::Tagging + # Wraps application run state check to flag need to interrupt processing + def stop_processing? + Puppet::Application.stop_requested? + end + # Add some additional times for reporting def add_times(hash) hash.each do |name, num| @@ -135,6 +141,7 @@ class Puppet::Transaction begin @sorted_resources.each do |resource| + next if stop_processing? if resource.is_a?(Puppet::Type::Component) Puppet.warning "Somehow left a component in the relationship graph" next diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index cf0b8af2d..64da12d63 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -4,6 +4,13 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/transaction' +def without_warnings + flag = $VERBOSE + $VERBOSE = nil + yield + $VERBOSE = flag +end + describe Puppet::Transaction do before do @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) @@ -293,6 +300,49 @@ describe Puppet::Transaction do @transaction.changed?.should == [@catalog.resource(names[0])] end + + describe 'when checking application run state' do + before do + without_warnings { Puppet::Application = Class.new(Puppet::Application) } + @catalog = Puppet::Resource::Catalog.new + @transaction = Puppet::Transaction.new(@catalog) + end + + after do + without_warnings { Puppet::Application = Puppet::Application.superclass } + end + + it 'should return true for :stop_processing? if Puppet::Application.stop_requested? is true' do + Puppet::Application.stubs(:stop_requested?).returns(true) + @transaction.stop_processing?.should be_true + end + + it 'should return false for :stop_processing? if Puppet::Application.stop_requested? is false' do + Puppet::Application.stubs(:stop_requested?).returns(false) + @transaction.stop_processing?.should be_false + end + + describe 'within an evaluate call' do + before do + @resource = stub 'resource', :ref => 'some_ref' + @catalog.add_resource @resource + @transaction.stubs(:prepare) + @transaction.sorted_resources = [@resource] + end + + it 'should stop processing if :stop_processing? is true' do + @transaction.expects(:stop_processing?).returns(true) + @transaction.expects(:eval_resource).never + @transaction.evaluate + end + + it 'should continue processing if :stop_processing? is false' do + @transaction.expects(:stop_processing?).returns(false) + @transaction.expects(:eval_resource).returns(nil) + @transaction.evaluate + end + end + end end describe Puppet::Transaction, " when determining tags" do |