diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-05 14:50:06 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-02-06 18:08:43 -0600 |
commit | c7d178d04f324c010de1552083a954bb4b02217d (patch) | |
tree | c52cd50e351f8f8239666510609242401a560248 | |
parent | c0fcb2137e66af8ba60a959faa221034c6832b69 (diff) | |
download | puppet-c7d178d04f324c010de1552083a954bb4b02217d.tar.gz puppet-c7d178d04f324c010de1552083a954bb4b02217d.tar.xz puppet-c7d178d04f324c010de1552083a954bb4b02217d.zip |
The Agent now uses its lockfile to determine running state
This makes it so we can easily create and use lots
of agent instances, rather than having a single
global instance with shared state.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/agent.rb | 7 | ||||
-rwxr-xr-x | spec/unit/agent.rb | 21 |
2 files changed, 16 insertions, 12 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb index e7d40f68c..438b668a6 100644 --- a/lib/puppet/agent.rb +++ b/lib/puppet/agent.rb @@ -37,7 +37,7 @@ class Puppet::Agent # Perform a run with our client. def run - if client + if running? Puppet.notice "Run of %s already in progress; skipping" % client_class return end @@ -56,11 +56,6 @@ class Puppet::Agent end end - # If the client instance is set, we're mid-run. - def running? - ! client.nil? - end - def stop if self.stopping? Puppet.notice "Already in shutdown" diff --git a/spec/unit/agent.rb b/spec/unit/agent.rb index 03136c484..da1cadea5 100755 --- a/spec/unit/agent.rb +++ b/spec/unit/agent.rb @@ -37,6 +37,7 @@ describe Puppet::Agent do client.expects(:run) + @agent.stubs(:running?).returns false @agent.run end @@ -45,23 +46,29 @@ describe Puppet::Agent do @agent.lockfile_path.should == "/my/lock" end - it "should be considered running if a client instance is available" do - client = AgentTestClient.new - AgentTestClient.expects(:new).returns client + it "should be considered running if the lock file is locked" do + lockfile = mock 'lockfile' - client.expects(:run).with { @agent.should be_running } - @agent.run + @agent.expects(:lockfile).returns lockfile + lockfile.expects(:locked?).returns true + + @agent.should be_running end describe "when being run" do + before do + @agent.stubs(:running?).returns false + end + it "should splay" do @agent.expects(:splay) + @agent.stubs(:running?).returns false @agent.run end it "should do nothing if already running" do - @agent.expects(:client).returns "eh" + @agent.expects(:running?).returns true AgentTestClient.expects(:new).never @agent.run end @@ -205,6 +212,8 @@ describe Puppet::Agent do it "should run within the block passed to the timer" do timer = stub 'timer', :sound_alarm => nil EventLoop::Timer.expects(:new).returns(timer).yields + @agent.expects(:run) + @agent.start end end |