summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2010-09-29 16:32:19 -0700
committerMarkus Roberts <Markus@reality.com>2010-09-30 14:14:31 -0700
commit0aaa742e0f09c25fb5591b72c9073bb1fee59ece (patch)
treedb3a34ab094fb89437e03e5bdfb935c3eee938d5
parentea49d13192fce5e891a5ea767ecf05fc3107a411 (diff)
downloadpuppet-0aaa742e0f09c25fb5591b72c9073bb1fee59ece.tar.gz
puppet-0aaa742e0f09c25fb5591b72c9073bb1fee59ece.tar.xz
puppet-0aaa742e0f09c25fb5591b72c9073bb1fee59ece.zip
Fixes #4792 (Duplicate definition since 2.6.1 upgrade)
The evaluate_definitions method was first figuring out which resources needed to be evaluated (using unevaluated_resources), and then evaluating them one by one. As a result, if evaluating one resource triggered another resource to be evaluated, the latter resource could get evaluated twice. This bug could occur, for example, if both resources were classes that were included into the node by an external node classifier, and if the first of the two classes included the second. Modified Resource#evaluate to be idempotent. Also added an integration test to verify the fix.
-rw-r--r--lib/puppet/parser/resource.rb1
-rwxr-xr-xspec/integration/parser/compiler_spec.rb21
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index e34f284fc..c007d4dbe 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -64,6 +64,7 @@ class Puppet::Parser::Resource < Puppet::Resource
# Retrieve the associated definition and evaluate it.
def evaluate
+ return if evaluated?
@evaluated = true
if klass = resource_type and ! builtin_type?
finish
diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb
index 9158ad1c2..f80221e3d 100755
--- a/spec/integration/parser/compiler_spec.rb
+++ b/spec/integration/parser/compiler_spec.rb
@@ -27,6 +27,27 @@ describe Puppet::Parser::Compiler do
@compiler.catalog.version.should == version
end
+ it "should not create duplicate resources when a class is referenced both directly and indirectly by the node classifier (4792)" do
+ Puppet[:code] = <<-PP
+ class foo
+ {
+ notify { foo_notify: }
+ include bar
+ }
+ class bar
+ {
+ notify { bar_notify: }
+ }
+ PP
+
+ @node.stubs(:classes).returns(['foo', 'bar'])
+
+ catalog = Puppet::Parser::Compiler.compile(@node)
+
+ catalog.resource("Notify[foo_notify]").should_not be_nil
+ catalog.resource("Notify[bar_notify]").should_not be_nil
+ end
+
describe "when resolving class references" do
it "should favor local scope, even if there's an included class in topscope" do
Puppet[:code] = <<-PP