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


The following commit has been merged in the upstream branch:
commit 2cf647c34f5e71fc30fccb2de0c5acef5799b924
Author: Ethan Rowe <ethan at endpoint.com>
Date:   Thu Jul 30 01:17:01 2009 -0400

    Fix 2239 (step one): introduce global settings represeting application run state with methods for
    setting the state and appropriately-named predicates for querying state, all in the Puppet::Application
    class itself.  To be used by Puppet::Daemon and Puppet::Agent and Puppet::Transaction for better response
    to TERM, INT, HUP.

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 8597bd6..83f90a1 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -5,6 +5,7 @@ require 'optparse'
 # * setting up options
 # * setting up logs
 # * choosing what to run
+# * representing execution status
 #
 # === Usage
 # The application is a Puppet::Application object that register itself in the list
@@ -86,6 +87,31 @@ require 'optparse'
 # to be run.
 # If it doesn't exist, it defaults to execute the +main+ command if defined.
 #
+# === Execution state
+# The class attributes/methods of Puppet::Application serve as a global place to set and query the execution
+# status of the application: stopping, restarting, etc.  The setting of the application status does not directly
+# aftect its running status; it's assumed that the various components within the application will consult these
+# settings appropriately and affect their own processing accordingly.  Control operations (signal handlers and
+# the like) should set the status appropriately to indicate to the overall system that it's the process of
+# stopping or restarting (or just running as usual).
+#
+# So, if something in your application needs to stop the process, for some reason, you might consider:
+#
+#  def stop_me!
+#      # indicate that we're stopping
+#      Puppet::Application.stop!
+#      # ...do stuff...
+#  end
+#
+# And, if you have some component that involves a long-running process, you might want to consider:
+#
+#  def my_long_process(giant_list_to_munge)
+#      giant_list_to_munge.collect do |member|
+#          # bail if we're stopping
+#          return if Puppet::Application.stop_requested?
+#          process_member(member)
+#      end
+#  end
 class Puppet::Application
     include Puppet::Util
 
@@ -96,6 +122,44 @@ class Puppet::Application
 
     class << self
         include Puppet::Util
+
+        attr_accessor :run_status
+
+        def clear!
+            self.run_status = nil
+        end
+
+        def stop!
+            self.run_status = :stop_requested
+        end
+
+        def restart!
+            self.run_status = :restart_requested
+        end
+
+        # Indicates that Puppet::Application.restart! has been invoked and components should
+        # do what is necessary to facilitate a restart.
+        def restart_requested?
+            :restart_requested == run_status
+        end
+
+        # Indicates that Puppet::Application.stop! has been invoked and components should do what is necessary
+        # for a clean stop.
+        def stop_requested?
+            :stop_requested == run_status
+        end
+
+        # Indicates that one of stop! or start! was invoked on Puppet::Application, and some kind of process
+        # shutdown/short-circuit may be necessary.
+        def interrupted?
+            [:restart_requested, :stop_requested].include? run_status
+        end
+
+        # Indicates that Puppet::Application believes that it's in usual running mode (no stop/restart request
+        # currently active).
+        def clear?
+            run_status.nil?
+        end
     end
 
     attr_reader :options, :opt_parser
diff --git a/spec/unit/application.rb b/spec/unit/application.rb
index c087373..cc8f791 100755
--- a/spec/unit/application.rb
+++ b/spec/unit/application.rb
@@ -36,6 +36,105 @@ describe Puppet::Application do
         @app.get_command.should == :main
     end
 
+    describe 'when invoking clear!' do
+        before :each do
+            Puppet::Application.run_status = :stop_requested
+            Puppet::Application.clear!
+        end
+
+        it 'should have nil run_status' do
+            Puppet::Application.run_status.should be_nil
+        end
+
+        it 'should return false for restart_requested?' do
+            Puppet::Application.restart_requested?.should be_false
+        end
+
+        it 'should return false for stop_requested?' do
+            Puppet::Application.stop_requested?.should be_false
+        end
+
+        it 'should return false for interrupted?' do
+            Puppet::Application.interrupted?.should be_false
+        end
+
+        it 'should return true for clear?' do
+            Puppet::Application.clear?.should be_true
+        end
+    end
+
+    describe 'after invoking stop!' do
+        before :each do
+            Puppet::Application.run_status = nil
+            Puppet::Application.stop!
+        end
+
+        after :each do
+            Puppet::Application.run_status = nil
+        end
+
+        it 'should have run_status of :stop_requested' do
+            Puppet::Application.run_status.should == :stop_requested
+        end
+
+        it 'should return true for stop_requested?' do
+            Puppet::Application.stop_requested?.should be_true
+        end
+
+        it 'should return false for restart_requested?' do
+            Puppet::Application.restart_requested?.should be_false
+        end
+
+        it 'should return true for interrupted?' do
+            Puppet::Application.interrupted?.should be_true
+        end
+
+        it 'should return false for clear?' do
+            Puppet::Application.clear?.should be_false
+        end
+    end
+
+    describe 'when invoking restart!' do
+        before :each do
+            Puppet::Application.run_status = nil
+            Puppet::Application.restart!
+        end
+
+        after :each do
+            Puppet::Application.run_status = nil
+        end
+
+        it 'should have run_status of :restart_requested' do
+            Puppet::Application.run_status.should == :restart_requested
+        end
+
+        it 'should return true for restart_requested?' do
+            Puppet::Application.restart_requested?.should be_true
+        end
+
+        it 'should return false for stop_requested?' do
+            Puppet::Application.stop_requested?.should be_false
+        end
+
+        it 'should return true for interrupted?' do
+            Puppet::Application.interrupted?.should be_true
+        end
+
+        it 'should return false for clear?' do
+            Puppet::Application.clear?.should be_false
+        end
+    end
+
+    describe 'when working with class-level run status properties' do
+        it 'should set run status and predicate appropriately on stop!' do
+        end
+
+        it 'should set run status and predicate appropriately on restart!' do
+        end
+
+
+    end
+
     describe "when parsing command-line options" do
 
         before :each do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list