diff options
| -rwxr-xr-x | lib/puppet/provider/service/init.rb | 20 | ||||
| -rw-r--r-- | lib/puppet/type/service.rb | 15 | ||||
| -rwxr-xr-x | spec/unit/provider/service/init.rb | 17 | ||||
| -rwxr-xr-x | spec/unit/type/service.rb | 14 |
4 files changed, 35 insertions, 31 deletions
diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 965773d96..c05a32677 100755 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -70,8 +70,23 @@ Puppet::Type.type(:service).provide :init, :parent => :base do @initscript ||= self.search(@resource[:name]) end + def paths + @paths ||= @resource[:path].find_all do |path| + if File.directory?(path) + true + else + if File.exist?(path) and ! File.directory?(path) + self.debug "Search path #{path} is not a directory" + else + self.debug "Search path #{path} does not exist" + end + false + end + end + end + def search(name) - @resource[:path].each { |path| + paths.each { |path| fqname = File.join(path,name) begin stat = File.stat(fqname) @@ -84,7 +99,8 @@ Puppet::Type.type(:service).provide :init, :parent => :base do # if we've gotten this far, we found a valid script return fqname } - @resource[:path].each { |path| + + paths.each { |path| fqname_sh = File.join(path,"#{name}.sh") begin stat = File.stat(fqname_sh) diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 04fd9042c..d2ba82afd 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -115,20 +115,7 @@ module Puppet value = [value] unless value.is_a?(Array) # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] # It affects stand-alone blocks, too. - paths = value.flatten.collect { |p| x = p.split(":") }.flatten.find_all do |path| - if FileTest.directory?(path) - true - else - if FileTest.exist?(path) and ! FileTest.directory?(path) - @resource.debug "Search path %s is not a directory" % [path] - else - @resource.debug("Search path %s does not exist" % [path]) - end - false - end - end - - paths + paths = value.flatten.collect { |p| x = p.split(":") }.flatten end defaultto { provider.class.defpath if provider.class.respond_to?(:defpath) } diff --git a/spec/unit/provider/service/init.rb b/spec/unit/provider/service/init.rb index 0bfeb9a18..32bfaa204 100755 --- a/spec/unit/provider/service/init.rb +++ b/spec/unit/provider/service/init.rb @@ -16,12 +16,26 @@ describe provider_class do # @resource.stubs(:[]).with(:ensure).returns :enabled @resource.stubs(:[]).with(:path).returns ["/service/path","/alt/service/path"] # @resource.stubs(:ref).returns "Service[myservice]" + File.stubs(:directory?).returns(true) @provider = provider_class.new @provider.resource = @resource end - describe "when serching for the init script" do + + describe "when searching for the init script" do + it "should discard paths that do not exist" do + File.stubs(:exist?).returns(false) + File.stubs(:directory?).returns(false) + @provider.paths.should be_empty + end + + it "should discard paths that are not directories" do + File.stubs(:exist?).returns(true) + File.stubs(:directory?).returns(false) + @provider.paths.should be_empty + end + it "should be able to find the init script in the service path" do File.expects(:stat).with("/service/path/myservice").returns true @provider.initscript.should == "/service/path/myservice" @@ -102,5 +116,6 @@ describe provider_class do @provider.restart end end + end end diff --git a/spec/unit/type/service.rb b/spec/unit/type/service.rb index 5e9d3b37f..f09ed98b9 100755 --- a/spec/unit/type/service.rb +++ b/spec/unit/type/service.rb @@ -88,20 +88,6 @@ describe Puppet::Type.type(:service), "when validating attribute values" do svc.should(:enable).should be_nil end - it "should discard paths that do not exist" do - FileTest.stubs(:exist?).returns(false) - FileTest.stubs(:directory?).returns(false) - svc = Puppet::Type.type(:service).new(:name => "yay", :path => "/one/two") - svc[:path].should be_empty - end - - it "should discard paths that are not directories" do - FileTest.stubs(:exist?).returns(true) - FileTest.stubs(:directory?).returns(false) - svc = Puppet::Type.type(:service).new(:name => "yay", :path => "/one/two") - svc[:path].should be_empty - end - it "should split paths on ':'" do FileTest.stubs(:exist?).returns(true) FileTest.stubs(:directory?).returns(true) |
