[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. puppet-0.24.5-rc3-1601-gf8c1b08

Jesse Wolfe jes5199 at gmail.com
Fri Jan 15 09:08:43 UTC 2010


The following commit has been merged in the upstream branch:
commit 0a7e212cb824a3a13bc00abf2e69aa3852c6c4d9
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Fri Jan 8 17:35:51 2010 -0800

    Fix #2887 'service' tests paths too early
    
    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 <jes5199 at gmail.com>

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..32bfaa2 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 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)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list