[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:21:18 UTC 2009


The following commit has been merged in the master branch:
commit 253d4df1f49e1516a111557b98b29509c39b41e0
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sun Oct 5 17:11:22 2008 +0200

    Fix regression when templatedir doesn't exist.
    
    When searching for a module template and if the default templatedir is
    inexistant, puppet was raising an error without trying the modules templates
    directories.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/CHANGELOG b/CHANGELOG
index d181d7e..e05a960 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,7 @@
 0.24.x
+    Fixed #1637 - With an inexistant (global) templatedir, modules 
+    can't access their templates
+
     Fixed #1202 - Collection attribute matching doesn't parse arrays
 
     Fixed #1473 - Puppetd stops with error after puppetmasterd 
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index b34f2f8..9385812 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -73,17 +73,23 @@ class Puppet::Module
         end
 
         template_paths = templatepath(environment)
-        default_template_path = File::join(template_paths.first, template)
+        if template_paths
+            # If we can find the template in :templatedir, we return that.
+            td_file = template_paths.collect { |path|
+                File::join(path, template)
+            }.find { |f| File.exists?(f) }
 
-        # If we can find the template in :templatedir, we return that.
-        td_file = template_paths.collect { |path|
-            File::join(path, template)
-        }.find { |f| File.exists?(f) }
-
-        return td_file unless td_file == nil
+            return td_file unless td_file == nil
+        end
 
         td_file = find_template_for_module(template, environment)
-        td_file ||= default_template_path
+
+        # check in the default template dir, if there is one
+        if td_file.nil?
+            raise Puppet::Error, "No valid template directory found, please check templatedir settings" if template_paths.nil?
+            td_file = File::join(template_paths.first, template)
+        end
+        td_file
     end
 
     def self.find_template_for_module(template, environment = nil)
diff --git a/spec/unit/module.rb b/spec/unit/module.rb
index 4d66550..a6608fc 100755
--- a/spec/unit/module.rb
+++ b/spec/unit/module.rb
@@ -89,6 +89,19 @@ describe Puppet::Module, " when searching for templates" do
         Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
     end
 
+    it "should raise an error if no valid templatedir exists" do
+        Puppet::Module.stubs(:templatepath).with(nil).returns(nil)
+        lambda { Puppet::Module.find_template("mytemplate") }.should raise_error
+    end
+
+    it "should not raise an error if no valid templatedir exists and the template exists in a module" do
+        Puppet::Module.stubs(:templatepath).with(nil).returns(nil)
+        Puppet[:modulepath] = "/one:/two"
+        File.stubs(:directory?).returns(true)
+        File.stubs(:exists?).returns(true)
+        Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
+    end
+
     it "should use the main templatedir if no module is found" do
         Puppet::Module.stubs(:templatepath).with(nil).returns(["/my/templates"])
         Puppet::Module.expects(:find).with("mymod", nil).returns(nil)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list