[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:06:02 UTC 2009


The following commit has been merged in the upstream branch:
commit f59f8054dc0d1c86169b954fab96df650f38dd23
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Fri Oct 16 23:45:02 2009 -0700

    Bug #1900 Parsing of quoted $ in stdin
    
    When code comes in via STDIN or --code ,
    Puppet::Util::Settings interpolates $values in the code,
    which is probably never the intended behavior.
    
    This is the least destructive fix I could think of:
    have Puppet::Parser::Interpreter ask for the uninterpolated value.
    
    More general fixes could be to:
      a) Add an escape character to Settings's interpolator, and escape STDIN
      b) Add a mechanism to Settings to mark some values as uninterpolated
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 2e89240..bc0ae4f 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -62,7 +62,7 @@ class Puppet::Parser::Interpreter
     def create_parser(environment)
         begin
             parser = Puppet::Parser::Parser.new(:environment => environment)
-            if code = Puppet.settings.value(:code, environment) and code != ""
+            if code = Puppet.settings.uninterpolated_value(:code, environment) and code != ""
                 parser.string = code
             else
                 file = Puppet.settings.value(:manifest, environment)
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 3e3bc7f..e80c7cc 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -653,6 +653,30 @@ Generated on #{Time.now}.
         @config.has_key?(param)
     end
 
+    def uninterpolated_value(param, environment = nil)
+        param = param.to_sym
+        environment = environment.to_sym if environment
+
+        # See if we can find it within our searchable list of values
+        val = catch :foundval do
+            each_source(environment) do |source|
+                # Look for the value.  We have to test the hash for whether
+                # it exists, because the value might be false.
+                @sync.synchronize do
+                    if @values[source].include?(param)
+                        throw :foundval, @values[source][param]
+                    end
+                end
+            end
+            throw :foundval, nil
+        end
+        
+        # If we didn't get a value, use the default
+        val = @config[param].default if val.nil?
+
+        return val
+    end
+
     # Find the correct value using our search path.  Optionally accept an environment
     # in which to search before the other configuration sections.
     def value(param, environment = nil)
@@ -672,22 +696,7 @@ Generated on #{Time.now}.
             return cached
         end
 
-        # See if we can find it within our searchable list of values
-        val = catch :foundval do
-            each_source(environment) do |source|
-                # Look for the value.  We have to test the hash for whether
-                # it exists, because the value might be false.
-                @sync.synchronize do
-                    if @values[source].include?(param)
-                        throw :foundval, @values[source][param]
-                    end
-                end
-            end
-            throw :foundval, nil
-        end
-
-        # If we didn't get a value, use the default
-        val = @config[param].default if val.nil?
+        val = uninterpolated_value(param, environment)
 
         # Convert it if necessary
         val = convert(val, environment)
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb
index f06186a..182f3da 100755
--- a/spec/unit/parser/interpreter.rb
+++ b/spec/unit/parser/interpreter.rb
@@ -10,7 +10,7 @@ describe Puppet::Parser::Interpreter do
 
     describe "when creating parser instances" do
         it "should create a parser with code if there is code defined in the :code setting" do
-            Puppet.settings.stubs(:value).with(:code, :myenv).returns("mycode")
+            Puppet.settings.stubs(:uninterpolated_value).with(:code, :myenv).returns("mycode")
             @parser.expects(:string=).with("mycode")
             @parser.expects(:parse)
             Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser)
@@ -18,7 +18,7 @@ describe Puppet::Parser::Interpreter do
         end
 
         it "should create a parser with the main manifest when the code setting is an empty string" do
-            Puppet.settings.stubs(:value).with(:code, :myenv).returns("")
+            Puppet.settings.stubs(:uninterpolated_value).with(:code, :myenv).returns("")
             Puppet.settings.stubs(:value).with(:manifest, :myenv).returns("/my/file")
             @parser.expects(:parse)
             @parser.expects(:file=).with("/my/file")
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index ae8aaac..aa2101f 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -200,6 +200,12 @@ describe Puppet::Util::Settings do
             @settings[:four].should == "ONE TWO ONE ONE TWO THREE FOUR"
         end
 
+        it "should provide a method for returning uninterpolated values" do
+            @settings[:two] = "$one tw0"
+            @settings.uninterpolated_value(:two).should  == "$one tw0"
+            @settings.uninterpolated_value(:four).should == "$two $three FOUR"
+        end
+
         it "should interpolate set values for other parameters into returned parameter values" do
             @settings[:one] = "on3"
             @settings[:two] = "$one tw0"

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list