summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-02-05 19:59:18 +0100
committerJames Turnbull <james@lovedthanlost.net>2009-02-11 08:53:13 +1100
commitb22d148e6d6eb36c9b02a58dc0c04c9650d5207b (patch)
tree1712b24353ae2299b8f9941e63f6dd29251a0cc8
parent6331bfc9b6dc5140147730b3c4f79fef35265a94 (diff)
downloadpuppet-b22d148e6d6eb36c9b02a58dc0c04c9650d5207b.tar.gz
puppet-b22d148e6d6eb36c9b02a58dc0c04c9650d5207b.tar.xz
puppet-b22d148e6d6eb36c9b02a58dc0c04c9650d5207b.zip
Fix #1691 - Realize fails with array of Resource References
The following snippet: realize( File["/tmp/a","/tmp/b"] ) is parsed into: AST::Function @name=realize @arguments= AST::ASTArray @children = [ AST::ResourceReference @title= AST::ASTArray @children = [ String(/tmp/a), String(/tmp/b) ] ] When evaluated: ResourceReference gives -> [ File[/tmp/a], File[/tmp/b] ] which means the function arguments are: [[File[/tmp/a], File[/tmp/b]] after evaluating the @arguments ASTArray of AST::Functions. Then the collector complains that it can't find the resource because it is not supposed to work on non-flattened resource array. The fix is to flatten in the realize function (although it can be done more generally in the AST::Function evaluation) before the resources are given to the Collector. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
-rw-r--r--CHANGELOG1
-rw-r--r--lib/puppet/parser/functions/realize.rb2
-rwxr-xr-xspec/unit/parser/functions/realize.rb51
3 files changed, 53 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8721c61a2..99aafa161 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,5 @@
0.24.8
+ Fixed #1922 - Functions squash all arguments into a single hash
Fixed #1538 - Yumrepo sets permissions wrongly on files in /etc/yum.repos.d
Fixed #1936 - Added /* */ support to the vim file
diff --git a/lib/puppet/parser/functions/realize.rb b/lib/puppet/parser/functions/realize.rb
index 1bdde234e..6aff19d29 100644
--- a/lib/puppet/parser/functions/realize.rb
+++ b/lib/puppet/parser/functions/realize.rb
@@ -8,7 +8,7 @@ Puppet::Parser::Functions::newfunction(:realize, :doc => "Make a virtual object
reference; e.g.: ``realize User[luke]``." ) do |vals|
coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual)
vals = [vals] unless vals.is_a?(Array)
- coll.resources = vals
+ coll.resources = vals.flatten
compiler.add_collection(coll)
end
diff --git a/spec/unit/parser/functions/realize.rb b/spec/unit/parser/functions/realize.rb
new file mode 100755
index 000000000..d9c94b143
--- /dev/null
+++ b/spec/unit/parser/functions/realize.rb
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the realize function" do
+
+ before :each do
+ @collector = stub_everything 'collector'
+ @scope = Puppet::Parser::Scope.new()
+ @compiler = stub 'compiler'
+ @compiler.stubs(:add_collection).with(@collector)
+ @scope.stubs(:compiler).returns(@compiler)
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("realize").should == "function_realize"
+ end
+
+ it "should create a Collector when called" do
+
+ Puppet::Parser::Collector.expects(:new).returns(@collector)
+
+ @scope.function_realize("test")
+ end
+
+ it "should assign the passed-in resources to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+
+ @collector.expects(:resources=).with(["test"])
+
+ @scope.function_realize("test")
+ end
+
+ it "should flatten the resources assigned to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+
+ @collector.expects(:resources=).with(["test"])
+
+ @scope.function_realize([["test"]])
+ end
+
+ it "should let the compiler know this collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+ @collector.stubs(:resources=).with(["test"])
+
+ @compiler.expects(:add_collection).with(@collector)
+
+ @scope.function_realize("test")
+ end
+
+end