The 'service' type was testing to see if init script directories exist too early, causing failures if you expected to be able to create those directories via puppet. This patch moves that logic into the 'init' provider.
Signed-off-by: Jesse Wolfe <[email protected]> --- lib/puppet/provider/service/init.rb | 20 ++++++++++++++++++-- lib/puppet/type/service.rb | 15 +-------------- spec/unit/provider/service/init.rb | 15 +++++++++++++++ spec/unit/type/service.rb | 14 -------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 965773d..c05a326 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 04fd904..d2ba82a 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 0bfeb9a..b08f965 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 + 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 5e9d3b3..f09ed98 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) -- 1.6.5
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
