diff options
-rwxr-xr-x | lib/puppet/daemon.rb | 12 | ||||
-rwxr-xr-x | spec/unit/daemon.rb | 47 |
2 files changed, 36 insertions, 23 deletions
diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index 0f538fe44..b6dbf2665 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -1,6 +1,7 @@ require 'puppet' require 'puppet/util/pidlock' require 'puppet/external/event-loop' +require 'puppet/application' # A module that handles operations common to all daemons. This is included # into the Server and Client base classes. @@ -83,11 +84,8 @@ class Puppet::Daemon end def restart - if agent and agent.running? - agent.configure_delayed_restart - else - reexec - end + Puppet::Application.restart! + reexec unless agent and agent.running? end def reopen_logs @@ -107,9 +105,9 @@ class Puppet::Daemon # Stop everything def stop(args = {:exit => true}) - server.stop if server + Puppet::Application.stop! - agent.stop if agent + server.stop if server remove_pidfile() diff --git a/spec/unit/daemon.rb b/spec/unit/daemon.rb index 960d79d50..1bf8f5692 100755 --- a/spec/unit/daemon.rb +++ b/spec/unit/daemon.rb @@ -3,6 +3,13 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/daemon' +def without_warnings + flag = $VERBOSE + $VERBOSE = nil + yield + $VERBOSE = flag +end + describe Puppet::Daemon do before do @daemon = Puppet::Daemon.new @@ -86,6 +93,14 @@ describe Puppet::Daemon do @daemon.stubs(:remove_pidfile) @daemon.stubs(:exit) Puppet::Util::Log.stubs(:close_all) + # to make the global safe to mock, set it to a subclass of itself, + # then restore it in an after pass + without_warnings { Puppet::Application = Class.new(Puppet::Application) } + end + + after do + # restore from the superclass so we lose the stub garbage + without_warnings { Puppet::Application = Puppet::Application.superclass } end it "should stop its server if one is configured" do @@ -96,11 +111,8 @@ describe Puppet::Daemon do @daemon.stop end - it "should stop its agent if one is configured" do - agent = mock 'agent' - agent.expects(:stop) - @daemon.stubs(:agent).returns agent - + it 'should request a stop from Puppet::Application' do + Puppet::Application.expects(:stop!) @daemon.stop end @@ -236,28 +248,31 @@ describe Puppet::Daemon do end describe "when restarting" do - it "should reexec itself if no agent is available" do - @daemon.expects(:reexec) + before do + without_warnings { Puppet::Application = Class.new(Puppet::Application) } + end + after do + without_warnings { Puppet::Application = Puppet::Application.superclass } + end + + it 'should set Puppet::Application.restart!' do + Puppet::Application.expects(:restart!) + @daemon.stubs(:reexec) @daemon.restart end - it "should reexec itself if the agent is not running" do - agent = mock 'agent' - agent.expects(:running?).returns false - @daemon.stubs(:agent).returns agent + it "should reexec itself if no agent is available" do @daemon.expects(:reexec) @daemon.restart end - it "should configure the agent for later restart if the agent is running" do + it "should reexec itself if the agent is not running" do agent = mock 'agent' - agent.expects(:running?).returns true + agent.expects(:running?).returns false @daemon.stubs(:agent).returns agent - @daemon.expects(:reexec).never - - agent.expects(:configure_delayed_restart) + @daemon.expects(:reexec) @daemon.restart end |