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

James Turnbull james at lovedthanlost.net
Tue Oct 27 17:05:41 UTC 2009


The following commit has been merged in the upstream branch:
commit af57483e618ace39c0d4540fd0f8479f5430f0ef
Author: Luke Kanies <luke at madstop.com>
Date:   Sat Sep 19 21:56:05 2009 -0700

    Fixing #2632 - 'require' works for 0.25 clients
    
    I couldn't find a way to make it compatible with
    earlier clients, so the docs specify that
    it doesn't work with them, and it helpfully fails.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb
index 7d73831..3a2032d 100644
--- a/lib/puppet/parser/functions/require.rb
+++ b/lib/puppet/parser/functions/require.rb
@@ -23,12 +23,24 @@ class depends on the required class.
        file { '/foo': notify => Service[foo] }
     }
 
+Note that this function only works with clients 0.25 and later, and it will
+fail if used with earlier clients.
+
 ") do |vals|
-        send(:function_include, vals)
+    send(:function_include, vals)
+    if resource.metaparam_compatibility_mode?
+        warning "The 'require' function is only compatible with clients at 0.25 and above; including class but not adding dependency"
+    else
         vals = [vals] unless vals.is_a?(Array)
 
-        # add a relation from ourselves to each required klass
         vals.each do |klass|
-            compiler.catalog.add_edge(resource, findresource(:class, klass))
+            # This is a bit hackish, in some ways, but it's the only way
+            # to configure a dependency that will make it to the client.
+            # The 'obvious' way is just to add an edge in the catalog,
+            # but that is considered a containment edge, not a dependency
+            # edge, so it usually gets lost on the client.
+            ref = Puppet::Parser::Resource::Reference.new(:type => :class, :title => klass)
+            resource.set_parameter(:require, ref)
         end
+    end
 end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 29b1fb1..b8aaf27 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -175,6 +175,11 @@ class Puppet::Parser::Resource
         end
     end
 
+    # Unless we're running >= 0.25, we're in compat mode.
+    def metaparam_compatibility_mode?
+        ! (catalog and version = catalog.client_version and version = version.split(".") and version[0] == "0" and version[1].to_i >= 25)
+    end
+
     # Return the resource name, or the title if no name
     # was specified.
     def name
@@ -335,11 +340,6 @@ class Puppet::Parser::Resource
         end
     end
 
-    # Unless we're running >= 0.25, we're in compat mode.
-    def metaparam_compatibility_mode?
-        ! (catalog and version = catalog.client_version and version = version.split(".") and version[0] == "0" and version[1].to_i >= 25)
-    end
-
     def add_scope_tags
         if scope_resource = scope.resource
             tag(*scope_resource.tags)
diff --git a/spec/integration/parser/functions/require.rb b/spec/integration/parser/functions/require.rb
index 79ba13d..960594b 100755
--- a/spec/integration/parser/functions/require.rb
+++ b/spec/integration/parser/functions/require.rb
@@ -10,6 +10,7 @@ describe "the require function" do
         @compiler = Puppet::Parser::Compiler.new(@node, @parser)
 
         @compiler.send(:evaluate_main)
+        @compiler.catalog.client_version = "0.25"
         @scope = @compiler.topscope
         # preload our functions
         Puppet::Parser::Functions.function(:include)
@@ -20,10 +21,11 @@ describe "the require function" do
         @parser.newclass("requiredclass")
 
         @scope.function_require("requiredclass")
-
-        @compiler.catalog.edge?(@scope.resource, at compiler.findresource(:class,"requiredclass")).should be_true
+        @scope.resource["require"].should_not be_nil
+        ref = @scope.resource["require"]
+        ref.type.should == "Class"
+        ref.title.should == "requiredclass"
     end
-
 end
 
 describe "the include function" do
diff --git a/spec/unit/parser/functions/require.rb b/spec/unit/parser/functions/require.rb
index 67a5bae..24c9ecc 100755
--- a/spec/unit/parser/functions/require.rb
+++ b/spec/unit/parser/functions/require.rb
@@ -7,8 +7,10 @@ describe "the require function" do
     before :each do
         @catalog = stub 'catalog'
         @compiler = stub 'compiler', :catalog => @catalog
+
+        @resource = stub 'resource', :set_parameter => nil, :metaparam_compatibility_mode? => false
         @scope = Puppet::Parser::Scope.new()
-        @scope.stubs(:resource).returns("ourselves")
+        @scope.stubs(:resource).returns @resource
         @scope.stubs(:findresource)
         @scope.stubs(:compiler).returns(@compiler)
     end
@@ -18,19 +20,23 @@ describe "the require function" do
     end
 
     it "should delegate to the 'include' puppet function" do
-        @catalog.stubs(:add_edge)
         @scope.expects(:function_include).with("myclass")
 
         @scope.function_require("myclass")
     end
 
-    it "should add a catalog edge from our parent resource to the included one" do
-        @scope.stubs(:function_include).with("myclass")
-        @scope.stubs(:findresource).with(:class, "myclass").returns("includedclass")
+    it "should set the 'require' prarameter on the resource to a resource reference" do
+        @resource.expects(:set_parameter).with { |name, value| name == :require and value.is_a?(Puppet::Parser::Resource::Reference) }
+        @scope.stubs(:function_include)
+        @scope.function_require("myclass")
+    end
 
-        @catalog.expects(:add_edge).with("ourselves","includedclass")
+    it "should include the class but not add a dependency if used on a client not at least version 0.25" do
+        @resource.expects(:metaparam_compatibility_mode?).returns true
+        @scope.expects(:warning)
+        @resource.expects(:set_parameter).never
+        @scope.expects(:function_include)
 
         @scope.function_require("myclass")
     end
-
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list