From: Markus Roberts <mar...@reality.com>

When we lookup a global variable / fact from code we should explicitly look
in the global scope.

Signed-off-by: Nick Lewis <n...@puppetlabs.com>
---
Local-branch: ticket/next/5027
 lib/puppet/parser/functions/extlookup.rb     |    9 ++-------
 lib/puppet/parser/functions/fqdn_rand.rb     |    2 +-
 spec/unit/parser/functions/extlookup_spec.rb |   10 +++++-----
 spec/unit/parser/functions/fqdn_rand_spec.rb |   20 ++++++++++----------
 4 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/lib/puppet/parser/functions/extlookup.rb 
b/lib/puppet/parser/functions/extlookup.rb
index bc55410..b5688d6 100644
--- a/lib/puppet/parser/functions/extlookup.rb
+++ b/lib/puppet/parser/functions/extlookup.rb
@@ -91,14 +91,9 @@ This is for back compatibility to interpolate variables with 
%. % interpolation
 
   raise Puppet::ParseError, ("extlookup(): wrong number of arguments 
(#{args.length}; must be <= 3)") if args.length > 3
 
-  extlookup_datadir = lookupvar('extlookup_datadir')
-  extlookup_precedence = Array.new
+  extlookup_datadir = lookupvar('::extlookup_datadir')
 
-  extlookup_precedence = lookupvar('extlookup_precedence').collect do |var|
-    var.gsub(/%\{(.+?)\}/) do |capture|
-      lookupvar($1)
-    end
-  end
+  extlookup_precedence = lookupvar('::extlookup_precedence').collect { |var| 
var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } }
 
   datafiles = Array.new
 
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb 
b/lib/puppet/parser/functions/fqdn_rand.rb
index 91157a1..93ab98b 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -7,6 +7,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => 
:rvalue, :doc =>
       $random_number_seed = fqdn_rand(30,30)") do |args|
     require 'digest/md5'
     max = args.shift
-    srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex)
+    srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex)
     rand(max).to_s
 end
diff --git a/spec/unit/parser/functions/extlookup_spec.rb 
b/spec/unit/parser/functions/extlookup_spec.rb
index f2560d3..ad89f65 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -65,7 +65,7 @@ describe "the extlookup function" do
 
   describe "should look in $extlookup_datadir for data files listed by 
$extlookup_precedence" do
     before do
-      @scope.stubs(:lookupvar).with('extlookup_datadir').returns("/tmp")
+      @scope.stubs(:lookupvar).with('::extlookup_datadir').returns("/tmp")
       File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" }
       File.open("/tmp/two.csv","w") do |two|
         two.puts "key,value2"
@@ -74,21 +74,21 @@ describe "the extlookup function" do
     end
 
     it "when the key is in the first file" do
-      
@scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"])
+      
@scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"])
       result = @scope.function_extlookup([ "key" ])
       result.should == "value1"
     end
 
     it "when the key is in the second file" do
-      
@scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"])
+      
@scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"])
       result = @scope.function_extlookup([ "key2" ])
       result.should == "value_two"
     end
 
     it "should not modify extlookup_precedence data" do
       variable = '%{fqdn}'
-      
@scope.stubs(:lookupvar).with('extlookup_precedence').returns([variable,"one"])
-      @scope.stubs(:lookupvar).with('fqdn').returns('myfqdn')
+      
@scope.stubs(:lookupvar).with('::extlookup_precedence').returns([variable,"one"])
+      @scope.stubs(:lookupvar).with('::fqdn').returns('myfqdn')
       result = @scope.function_extlookup([ "key" ])
       variable.should == '%{fqdn}'
     end
diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb 
b/spec/unit/parser/functions/fqdn_rand_spec.rb
index d810741..90792e1 100755
--- a/spec/unit/parser/functions/fqdn_rand_spec.rb
+++ b/spec/unit/parser/functions/fqdn_rand_spec.rb
@@ -16,49 +16,49 @@ describe "the fqdn_rand function" do
   end
 
   it "should handle 0 arguments" do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     lambda { @scope.function_fqdn_rand([]) }.should_not 
raise_error(Puppet::ParseError)
   end
 
   it "should handle 1 argument'}" do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     lambda { @scope.function_fqdn_rand([3]) }.should_not 
raise_error(Puppet::ParseError)
   end
 
 
   (1..10).each { |n|
     it "should handle #{n} additional arguments" do
-      @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+      @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
       lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) 
}.should_not raise_error(Puppet::ParseError)
     end
     it "should handle #{n} additional string arguments" do
-      @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+      @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
       lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 
10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
     end
   }
 
   it "should return a value less than max" do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
   end
 
   it "should return the same values on subsequent invocations for the same 
host" do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
     @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 
4]))
   end
 
   it "should return different sequences of value for different hosts" do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     val1 = @scope.function_fqdn_rand([10000000,4])
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
     val2 = @scope.function_fqdn_rand([10000000,4])
     val1.should_not eql(val2)
   end
 
   it "should return different values for the same hosts with different seeds" 
do
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     val1 = @scope.function_fqdn_rand([10000000,4])
-    @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+    @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
     val2 = @scope.function_fqdn_rand([10000000,42])
     val1.should_not eql(val2)
   end
-- 
1.7.4.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to