summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-06-16 13:11:26 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-06-26 11:38:02 +1000
commit5680cd5029c8b3a2cf5a2a3b10df6acf7a9fc870 (patch)
tree4b760295be6d48cdc4f5febfcbfe99454e761f72
parent603b9cf1a435f6662db39be66f91527a8e20c112 (diff)
downloadpuppet-5680cd5029c8b3a2cf5a2a3b10df6acf7a9fc870.tar.gz
puppet-5680cd5029c8b3a2cf5a2a3b10df6acf7a9fc870.tar.xz
puppet-5680cd5029c8b3a2cf5a2a3b10df6acf7a9fc870.zip
Fixing #2197 - daemontools tests now pass
This actually involved a bit of rewriting of the code, but the code's simpler now, too. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/provider/service/daemontools.rb54
-rw-r--r--spec/unit/provider/service/daemontools.rb51
2 files changed, 74 insertions, 31 deletions
diff --git a/lib/puppet/provider/service/daemontools.rb b/lib/puppet/provider/service/daemontools.rb
index 63666e149..f6eb5099f 100644
--- a/lib/puppet/provider/service/daemontools.rb
+++ b/lib/puppet/provider/service/daemontools.rb
@@ -129,14 +129,6 @@ Puppet::Type.type(:service).provide :daemontools, :parent => :base do
[command(:svc), "-u", self.service ]
end
- def stopcmd
- [command(:svc), "-d", self.service ]
- end
-
- def restartcmd
- [ command(:svc), "-t", self.service]
- end
-
def setupservice
begin
if resource[:manifest]
@@ -161,23 +153,49 @@ Puppet::Type.type(:service).provide :daemontools, :parent => :base do
def enable
begin
- if ! FileTest.directory?(self.daemon)
- Puppet.notice "No daemon dir, calling setupservice for %s" % resource[:name]
- self.setupservice
- end
- if self.daemon
- if ! FileTest.symlink?(self.service)
- Puppet.notice "Enabling %s: linking %s -> %s" % [ self.service, self.daemon, self.service ]
- File.symlink(self.daemon, self.service)
+ if ! FileTest.directory?(self.daemon)
+ Puppet.notice "No daemon dir, calling setupservice for %s" % resource[:name]
+ self.setupservice
+ end
+ if self.daemon
+ if ! FileTest.symlink?(self.service)
+ Puppet.notice "Enabling %s: linking %s -> %s" % [ self.service, self.daemon, self.service ]
+ File.symlink(self.daemon, self.service)
+ end
end
- end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error.new( "No daemon directory found for %s" % self.service )
end
end
def disable
+ begin
+ if ! FileTest.directory?(self.daemon)
+ Puppet.notice "No daemon dir, calling setupservice for %s" % resource[:name]
+ self.setupservice
+ end
+ if self.daemon
+ if FileTest.symlink?(self.service)
+ Puppet.notice "Disabling %s: removing link %s -> %s" % [ self.service, self.daemon, self.service ]
+ File.unlink(self.service)
+ end
+ end
+ rescue Puppet::ExecutionFailure => detail
+ raise Puppet::Error.new( "No daemon directory found for %s" % self.service )
+ end
self.stop
end
-end
+ def restart
+ svc "-t", self.service
+ end
+
+ def start
+ enable unless enabled?
+ svc "-u", self.service
+ end
+
+ def stop
+ svc "-d", self.service
+ end
+end
diff --git a/spec/unit/provider/service/daemontools.rb b/spec/unit/provider/service/daemontools.rb
index 2e9abaca8..4156afb1f 100644
--- a/spec/unit/provider/service/daemontools.rb
+++ b/spec/unit/provider/service/daemontools.rb
@@ -30,11 +30,17 @@ describe provider_class do
@resource.stubs(:[]).with(:path).returns @daemondir
@resource.stubs(:ref).returns "Service[myservice]"
- @provider.stubs(:resource).returns @resource
+ @provider.resource = @resource
+
+ @provider.stubs(:command).with(:svc).returns "svc"
+ @provider.stubs(:command).with(:svstat).returns "svstat"
+
+ @provider.stubs(:svc)
+ @provider.stubs(:svstat)
end
- it "should have a restartcmd method" do
- @provider.should respond_to(:restartcmd)
+ it "should have a restart method" do
+ @provider.should respond_to(:restart)
end
it "should have a start method" do
@@ -58,19 +64,40 @@ describe provider_class do
end
describe "when starting" do
- it "should call enable" do
+ it "should use 'svc' to start the service" do
+ @provider.stubs(:enabled?).returns true
+ @provider.expects(:svc).with("-u", "/etc/service/myservice")
+
+ @provider.start
+ end
+
+ it "should enable the service if it is not enabled" do
+ @provider.stubs(:svc)
+
+ @provider.expects(:enabled?).returns false
@provider.expects(:enable)
+
@provider.start
end
end
describe "when stopping" do
- it "should call disable" do
- @provider.expects(:disable)
+ it "should use 'svc' to stop the service" do
+ @provider.stubs(:disable)
+ @provider.expects(:svc).with("-d", "/etc/service/myservice")
+
@provider.stop
end
end
+ describe "when restarting" do
+ it "should use 'svc' to restart the service" do
+ @provider.expects(:svc).with("-t", "/etc/service/myservice")
+
+ @provider.restart
+ end
+ end
+
describe "when enabling" do
it "should create a symlink between daemon dir and service dir" do
FileTest.stubs(:symlink?).returns(false)
@@ -80,21 +107,19 @@ describe provider_class do
end
describe "when disabling" do
- it "should stop and then remove the symlink between daemon dir and service dir" do
+ it "should remove the symlink between daemon dir and service dir" do
FileTest.stubs(:directory?).returns(false)
FileTest.stubs(:symlink?).returns(true)
- File.expects(:unlink).with(File.join(@servicedir,"myservice")).returns(0)
+ File.expects(:unlink).with(File.join(@servicedir,"myservice"))
@provider.stubs(:texecute).returns("")
@provider.disable
end
- end
- describe "when disabling" do
- it "should also call 'svc -dx /etc/service/myservice'" do
+ it "should stop the service" do
FileTest.stubs(:directory?).returns(false)
FileTest.stubs(:symlink?).returns(true)
- File.expects(:unlink).with(File.join(@servicedir,"myservice")).returns(0)
- @provider.expects(:texecute).with("stop", [nil, '-dx', File.join(@servicedir,"myservice")]).returns ""
+ File.stubs(:unlink)
+ @provider.expects(:stop)
@provider.disable
end
end