[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 edbe9b6a988932c4b91dd194bc00ca201626d0ae
Author: Ethan Rowe <ethan at endpoint.com>
Date: Thu Jul 30 14:09:26 2009 -0400
Fix 2239 (step two): introduce Puppet::Application.controlled_run method to provide simple status-restricted execution of a passed in block; this can replace the process status checks and properly handle delayed restart behavior for Puppet::Agent.
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 83f90a1..a80f422 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -160,6 +160,18 @@ class Puppet::Application
def clear?
run_status.nil?
end
+
+ # Only executes the given block if the run status of Puppet::Application is clear (no restarts, stops,
+ # etc. requested).
+ # Upon block execution, checks the run status again; if a restart has been requested during the block's
+ # execution, then controlled_run will send a new HUP signal to the current process.
+ # Thus, long-running background processes can potentially finish their work before a restart.
+ def controlled_run(&block)
+ return unless clear?
+ result = block.call
+ Process.kill(:HUP, $$) if restart_requested?
+ result
+ end
end
attr_reader :options, :opt_parser
diff --git a/spec/unit/application.rb b/spec/unit/application.rb
index cc8f791..87a9009 100755
--- a/spec/unit/application.rb
+++ b/spec/unit/application.rb
@@ -125,14 +125,42 @@ describe Puppet::Application do
end
end
- describe 'when working with class-level run status properties' do
- it 'should set run status and predicate appropriately on stop!' do
+ describe 'when performing a controlled_run' do
+ it 'should not execute block if not :clear?' do
+ Puppet::Application.run_status = :stop_requested
+ target = mock 'target'
+ target.expects(:some_method).never
+ Puppet::Application.controlled_run do
+ target.some_method
+ end
end
- it 'should set run status and predicate appropriately on restart!' do
+ it 'should execute block if :clear?' do
+ Puppet::Application.run_status = nil
+ target = mock 'target'
+ target.expects(:some_method).once
+ Puppet::Application.controlled_run do
+ target.some_method
+ end
end
+ it 'should signal process with HUP after block if restart requested during block execution' do
+ Puppet::Application.run_status = nil
+ target = mock 'target'
+ target.expects(:some_method).once
+ old_handler = trap('HUP') { target.some_method }
+ begin
+ Puppet::Application.controlled_run do
+ Puppet::Application.run_status = :restart_requested
+ end
+ ensure
+ trap('HUP', old_handler)
+ end
+ end
+ after :each do
+ Puppet::Application.run_status = nil
+ end
end
describe "when parsing command-line options" do
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list