[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:28 UTC 2010


The following commit has been merged in the upstream branch:
commit 82f852a994b3b9b7f487e639d13a6bf2a7dac5b4
Author: Ethan Rowe <ethan at endpoint.com>
Date:   Thu Jul 30 15:06:04 2009 -0400

    Fix 2239 (step three): Refactored Puppet::Agent to base starting/restarting behaviors and predicates on new run-status interface of Puppet::Application.

diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index f712bbd..f073055 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -1,5 +1,6 @@
 require 'sync'
 require 'puppet/external/event-loop'
+require 'puppet/application'
 
 # A general class for triggering a run of another
 # class.
@@ -9,12 +10,7 @@ class Puppet::Agent
 
     require 'puppet/agent/runner'
 
-    attr_reader :client_class, :client, :needing_restart, :splayed
-    attr_accessor :stopping
-
-    def configure_delayed_restart
-        @needing_restart = true
-    end
+    attr_reader :client_class, :client, :splayed
 
     # Just so we can specify that we are "the" instance.
     def initialize(client_class)
@@ -28,13 +24,7 @@ class Puppet::Agent
     end
 
     def needing_restart?
-        @needing_restart
-    end
-
-    def restart
-        configure_delayed_restart and return if running?
-        Process.kill(:HUP, $$)
-        @needing_restart = false
+        Puppet::Application.restart_requested?
     end
 
     # Perform a run with our client.
@@ -43,45 +33,25 @@ class Puppet::Agent
             Puppet.notice "Run of %s already in progress; skipping" % client_class
             return
         end
-        if stopping?
-            Puppet.notice "In shutdown progress; skipping run"
-            return
-        end
-        splay
         result = nil
-        with_client do |client|
-            begin
-                sync.synchronize { lock { result = client.run(*args) } }
-            rescue SystemExit,NoMemoryError
-                raise
-            rescue Exception => detail
-                puts detail.backtrace if Puppet[:trace]
-                Puppet.err "Could not run %s: %s" % [client_class, detail]
+        block_run = Puppet::Application.controlled_run do
+            splay
+            with_client do |client|
+                begin
+                    sync.synchronize { lock { result = client.run(*args) } }
+                rescue => detail
+                    puts detail.backtrace if Puppet[:trace]
+                    Puppet.err "Could not run %s: %s" % [client_class, detail]
+                end
             end
+            true
         end
+        Puppet.notice "Shutdown/restart in progress; skipping run" unless block_run
         result
     end
 
-    def stop
-        if self.stopping?
-            Puppet.notice "Already in shutdown"
-            return
-        end
-        self.stopping = true
-        if client and client.respond_to?(:stop)
-            begin
-                client.stop
-            rescue
-                puts detail.backtrace if Puppet[:trace]
-                Puppet.err "Could not stop %s: %s" % [client_class, detail]
-            end
-        end
-    ensure
-        self.stopping = false
-    end
-
     def stopping?
-        stopping
+        Puppet::Application.stop_requested?
     end
 
     # Have we splayed already?
diff --git a/spec/unit/agent.rb b/spec/unit/agent.rb
index c133ca9..0a7fd57 100755
--- a/spec/unit/agent.rb
+++ b/spec/unit/agent.rb
@@ -15,12 +15,35 @@ class AgentTestClient
     end
 end
 
+def without_warnings
+    flag = $VERBOSE
+    $VERBOSE = nil
+    yield
+    $VERBOSE = flag
+end
+
 describe Puppet::Agent do
     before do
         @agent = Puppet::Agent.new(AgentTestClient)
 
         # So we don't actually try to hit the filesystem.
         @agent.stubs(:lock).yields
+
+        # make Puppet::Application safe for stubbing; restore in an :after block; silence warnings for this.
+        without_warnings { Puppet::Application = Class.new(Puppet::Application) }
+        Puppet::Application.stubs(:clear?).returns(true)
+        Puppet::Application.class_eval do
+            class << self
+                def controlled_run(&block)
+                    block.call
+                end
+            end
+        end
+    end
+
+    after do
+        # restore Puppet::Application from stub-safe subclass, and silence warnings
+        without_warnings { Puppet::Application = Puppet::Application.superclass }
     end
 
     it "should set its client class at initialization" do
@@ -73,9 +96,10 @@ describe Puppet::Agent do
             @agent.run
         end
 
-        it "should do nothing if it is in the process of stopping" do
-            @agent.expects(:stopping?).returns true
-            AgentTestClient.expects(:new).never
+        it "should use Puppet::Application.controlled_run to manage process state behavior" do
+            calls = sequence('calls')
+            Puppet::Application.expects(:controlled_run).yields().in_sequence(calls)
+            AgentTestClient.expects(:new).once.in_sequence(calls)
             @agent.run
         end
 
@@ -170,27 +194,56 @@ describe Puppet::Agent do
         end
     end
 
-    describe "when stopping" do
-        it "should do nothing if already stopping" do
-            @agent.expects(:stopping?).returns true
-            @agent.stop
+    describe "when checking execution state" do
+        describe 'with regular run status' do
+            before :each do
+                Puppet::Application.stubs(:restart_requested?).returns(false)
+                Puppet::Application.stubs(:stop_requested?).returns(false)
+                Puppet::Application.stubs(:interrupted?).returns(false)
+                Puppet::Application.stubs(:clear?).returns(true)
+            end
+
+            it 'should be false for :stopping?' do
+                @agent.stopping?.should be_false
+            end
+
+            it 'should be false for :needing_restart?' do
+                @agent.needing_restart?.should be_false
+            end
         end
 
-        it "should stop the client if one is available and it responds to 'stop'" do
-            client = AgentTestClient.new
-
-            @agent.stubs(:client).returns client
-            client.expects(:stop)
-            @agent.stop
+        describe 'with a stop requested' do
+            before :each do
+                Puppet::Application.stubs(:clear?).returns(false)
+                Puppet::Application.stubs(:restart_requested?).returns(false)
+                Puppet::Application.stubs(:stop_requested?).returns(true)
+                Puppet::Application.stubs(:interrupted?).returns(true)
+            end
+
+            it 'should be true for :stopping?' do
+                @agent.stopping?.should be_true
+            end
+
+            it 'should be false for :needing_restart?' do
+                @agent.needing_restart?.should be_false
+            end
         end
 
-        it "should mark itself as stopping while waiting for the client to stop" do
-            client = AgentTestClient.new
-
-            @agent.stubs(:client).returns client
-            client.expects(:stop).with { @agent.should be_stopping; true }
-
-            @agent.stop
+        describe 'with a restart requested' do
+            before :each do
+                Puppet::Application.stubs(:clear?).returns(false)
+                Puppet::Application.stubs(:restart_requested?).returns(true)
+                Puppet::Application.stubs(:stop_requested?).returns(false)
+                Puppet::Application.stubs(:interrupted?).returns(true)
+            end
+
+            it 'should be false for :stopping?' do
+                @agent.stopping?.should be_false
+            end
+
+            it 'should be true for :needing_restart?' do
+                @agent.needing_restart?.should be_true
+            end
         end
     end
 
@@ -225,35 +278,4 @@ describe Puppet::Agent do
             @agent.start
         end
     end
-
-    describe "when restarting" do
-        it "should configure itself for a delayed restart if currently running" do
-            @agent.expects(:running?).returns true
-
-            @agent.restart
-
-            @agent.should be_needing_restart
-        end
-
-        it "should hup itself if not running" do
-            @agent.expects(:running?).returns false
-
-            Process.expects(:kill).with(:HUP, $$)
-
-            @agent.restart
-        end
-
-        it "should turn off the needing_restart switch" do
-            @agent.expects(:running?).times(2).returns(true).then.returns false
-
-            Process.stubs(:kill)
-
-            # First call sets up the switch
-            @agent.restart
-
-            # Second call should disable it
-            @agent.restart
-            @agent.should_not be_needing_restart
-        end
-    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list