[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:31:29 UTC 2010


The following commit has been merged in the upstream branch:
commit ba2a3afb45199e3b85db03a1bb54a925bffce08f
Author: Ethan Rowe <ethan at endpoint.com>
Date:   Fri Jul 31 15:26:37 2009 -0400

    Fix 2239 (step five): introduce new Puppet::Transaction#stop_processing? flag and associated check thereof within the resource evaluation code.  This should allow for the transaction to bail out of its processing if it finds that a stop has been requested, based on the state of Puppet::Application.stop_requested?.

diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 4d82d33..e9a1934 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 cf0b8af..64da12d 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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list