[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Markus Roberts Markus at reality.com
Wed Jul 14 10:36:59 UTC 2010


The following commit has been merged in the upstream branch:
commit 3c0059195fb2b1255f368d98021f4a99ecd121a6
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Wed Jul 7 23:34:10 2010 -0700

    Fix for #4178 - generalize autoloading to include .rb
    
    This mostly modifies autoloading to look for files ending in either 'pp' or
    'rb' using Dir globing with {,.pp,.rb} or .{pp,rb} as appropriate.  It could
    easily be extended to add support for other formats (e.g. xml) by adding them
    to the globs (though, if this were to be done often, having a centralized list
    of supported extensions would be a good (and easy) refactor).
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/dsl/resource_api.rb b/lib/puppet/dsl/resource_api.rb
index 98e5215..5556eb8 100644
--- a/lib/puppet/dsl/resource_api.rb
+++ b/lib/puppet/dsl/resource_api.rb
@@ -44,6 +44,8 @@ class Puppet::DSL::ResourceAPI
         resource.eachparam do |param|
             instance_variable_set("@#{param.name}", param.value)
         end
+        @title = resource.title
+        @name ||= resource.title
     end
 
     def create_resource(type, names, arguments = nil)
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 1ea3df0..995262d 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -121,17 +121,12 @@ class Puppet::Module
     end
 
     # Return the list of manifests matching the given glob pattern,
-    # defaulting to 'init.pp' for empty modules.
+    # defaulting to 'init.{pp,rb}' for empty modules.
     def match_manifests(rest)
-        return find_init_manifest unless rest # Use init.pp
-
-        rest ||= "init.pp"
-        full_path = File::join(path, MANIFESTS, rest)
-        result = Dir.glob(full_path).reject { |f| FileTest.directory?(f) }
-        if result.size == 0 and rest !~ /\.pp$/
-            result = Dir.glob(full_path + ".pp")
-        end
-        result.flatten.compact
+        pat = File.join(path, MANIFESTS, rest || 'init')
+        Dir.
+            glob(pat + (File.extname(pat).empty? ? '.{pp,rb}' : '')).
+            reject { |f| FileTest.directory?(f) }
     end
 
     def metadata_file
@@ -190,11 +185,6 @@ class Puppet::Module
 
     private
 
-    def find_init_manifest
-        return [] unless file = manifest("init.pp")
-        return [file]
-    end
-
     def subpath(type)
         return File.join(path, type) unless type.to_s == "plugins"
 
diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb
index 37a7265..aad7469 100644
--- a/lib/puppet/parser/files.rb
+++ b/lib/puppet/parser/files.rb
@@ -24,11 +24,7 @@ module Puppet::Parser::Files
             # Than that would be a "no."
         end
         abspat = File::expand_path(start, cwd)
-        files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) }
-        if files.size == 0
-            files = Dir.glob(abspat + ".pp").reject { |f| FileTest.directory?(f) }
-        end
-        return [nil, files]
+        return [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{,.pp,.rb}' : '' )).reject { |f| FileTest.directory?(f) }]
     end
 
     # Find the concrete file denoted by +file+. If +file+ is absolute,
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 393211e..3b96e7e 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -351,7 +351,8 @@ class Puppet::Resource
     end
 
     def find_resource_type(type)
-        find_builtin_resource_type(type) || find_defined_resource_type(type)
+        # It still works fine without the type == 'class' short-cut, but it is a lot slower.
+        find_builtin_resource_type(type) || find_defined_resource_type(type) unless type.to_s.downcase == 'class'
     end
 
     def find_builtin_resource_type(type)
@@ -432,18 +433,12 @@ class Puppet::Resource
     end
 
     def resolve_type
-        type = munge_type_name(@unresolved_type)
-
-        case type
+        case type = munge_type_name(@unresolved_type)
         when "Class", "Node";
-            return type
+            type
         else
             # Otherwise, some kind of builtin or defined resource type
-            return munge_type_name(if r = find_resource_type(type)
-                r.name
-            else
-                type
-            end)
+            munge_type_name( (r = find_resource_type(type)) ? r.name : type)
         end
     end
 
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index 85cc841..fcc5e60 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -401,46 +401,47 @@ describe Puppet::Module, "when finding matching manifests" do
     before do
         @mod = Puppet::Module.new("mymod")
         @mod.stubs(:path).returns "/a"
+        @pq_glob_with_extension = "yay/*.xx"
+        @fq_glob_with_extension = "/a/manifests/" + @pq_glob_with_extension
     end
 
     it "should return all manifests matching the glob pattern" do
-        Dir.expects(:glob).with("/a/manifests/yay/*.pp").returns(%w{foo bar})
+        Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{foo bar})
         FileTest.stubs(:directory?).returns false
 
-        @mod.match_manifests("yay/*.pp").should == %w{foo bar}
+        @mod.match_manifests(@pq_glob_with_extension).should == %w{foo bar}
     end
 
     it "should not return directories" do
-        Dir.expects(:glob).with("/a/manifests/yay/*.pp").returns(%w{foo bar})
+        Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{foo bar})
 
         FileTest.expects(:directory?).with("foo").returns false
         FileTest.expects(:directory?).with("bar").returns true
-        @mod.match_manifests("yay/*.pp").should == %w{foo}
+        @mod.match_manifests(@pq_glob_with_extension).should == %w{foo}
     end
 
-    it "should default to the 'init.pp' file if no glob pattern is specified" do
-        FileTest.stubs(:exist?).returns true
+    it "should default to the 'init' file if no glob pattern is specified" do
+        Dir.expects(:glob).with("/a/manifests/init.{pp,rb}").returns(%w{/a/manifests/init.pp})
 
         @mod.match_manifests(nil).should == %w{/a/manifests/init.pp}
     end
 
     it "should return all manifests matching the glob pattern in all existing paths" do
-        Dir.expects(:glob).with("/a/manifests/yay/*.pp").returns(%w{a b})
+        Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{a b})
 
-        @mod.match_manifests("yay/*.pp").should == %w{a b}
+        @mod.match_manifests(@pq_glob_with_extension).should == %w{a b}
     end
 
-    it "should match the glob pattern plus '.pp' if no results are found" do
-        Dir.expects(:glob).with("/a/manifests/yay/foo").returns([])
-        Dir.expects(:glob).with("/a/manifests/yay/foo.pp").returns(%w{yay})
+    it "should match the glob pattern plus '.{pp,rb}' if no extention is specified" do
+        Dir.expects(:glob).with("/a/manifests/yay/foo.{pp,rb}").returns(%w{yay})
 
         @mod.match_manifests("yay/foo").should == %w{yay}
     end
 
     it "should return an empty array if no manifests matched" do
-        Dir.expects(:glob).with("/a/manifests/yay/*.pp").returns([])
+        Dir.expects(:glob).with(@fq_glob_with_extension).returns([])
 
-        @mod.match_manifests("yay/*.pp").should == []
+        @mod.match_manifests(@pq_glob_with_extension).should == []
     end
 end
 
diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb
index 8921534..df96c0e 100644
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -154,7 +154,7 @@ describe Puppet::Parser::Files do
 
         it "should match against provided fully qualified patterns" do
             pattern = @basepath + "/fully/qualified/pattern/*"
-            Dir.expects(:glob).with(pattern).returns(%w{my file list})
+            Dir.expects(:glob).with(pattern+'{,.pp,.rb}').returns(%w{my file list})
             Puppet::Parser::Files.find_manifests(pattern)[1].should == %w{my file list}
         end
 
@@ -168,7 +168,7 @@ describe Puppet::Parser::Files do
             pattern = @basepath + "/fully/qualified/pattern/*"
             file = @basepath + "/my/file"
             dir = @basepath + "/my/directory"
-            Dir.expects(:glob).with(pattern).returns([file, dir])
+            Dir.expects(:glob).with(pattern+'{,.pp,.rb}').returns([file, dir])
             FileTest.expects(:directory?).with(file).returns(false)
             FileTest.expects(:directory?).with(dir).returns(true)
             Puppet::Parser::Files.find_manifests(pattern)[1].should == [file]

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list