summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-02-05 14:50:06 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:43 -0600
commitc7d178d04f324c010de1552083a954bb4b02217d (patch)
treec52cd50e351f8f8239666510609242401a560248
parentc0fcb2137e66af8ba60a959faa221034c6832b69 (diff)
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.rb7
-rwxr-xr-xspec/unit/agent.rb21
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