diff options
author | Luke Kanies <luke@madstop.com> | 2008-02-25 19:53:24 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-02-25 19:53:24 -0500 |
commit | 42bfdf2fc7affa91265043e583c9673b738d22dd (patch) | |
tree | 999b959a94738e00401566ef50ed3ac4dfb6af52 | |
parent | 125851278d745e443c0598fbb0577b010f824365 (diff) | |
download | puppet-42bfdf2fc7affa91265043e583c9673b738d22dd.tar.gz puppet-42bfdf2fc7affa91265043e583c9673b738d22dd.tar.xz puppet-42bfdf2fc7affa91265043e583c9673b738d22dd.zip |
Fixing #1085, I think -- I was not returning a resource
if the class had already been evaluated, but this was only
being run into in corner cases -- mostly where one class
included another class, I assume.
-rw-r--r-- | lib/puppet/parser/ast/definition.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 9 | ||||
-rwxr-xr-x | spec/unit/parser/ast/hostclass.rb | 8 |
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb index 2b7506446..0c65c702c 100644 --- a/lib/puppet/parser/ast/definition.rb +++ b/lib/puppet/parser/ast/definition.rb @@ -24,9 +24,6 @@ class Puppet::Parser::AST::Definition < Puppet::Parser::AST::Branch # Create a resource that knows how to evaluate our actual code. def evaluate(scope) - # Do nothing if the resource already exists; this provides the singleton nature classes need. - return if scope.catalog.resource(self.class.name, self.classname) - resource = Puppet::Parser::Resource.new(:type => self.class.name, :title => self.classname, :scope => scope, :source => scope.source) scope.catalog.tag(*resource.tags) diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index 8d4d01660..7f89f8151 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -21,7 +21,14 @@ class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition # Make sure our parent class has been evaluated, if we have one. def evaluate(scope) if parentclass and ! scope.catalog.resource(self.class.name, parentclass) - resource = parentobj.evaluate(scope) + parent_resource = parentobj.evaluate(scope) + end + + # Do nothing if the resource already exists; this makes sure we don't + # get multiple copies of the class resource, which helps provide the + # singleton nature of classes. + if resource = scope.catalog.resource(self.class.name, self.classname) + return resource end super diff --git a/spec/unit/parser/ast/hostclass.rb b/spec/unit/parser/ast/hostclass.rb index a53c3b092..0abc174d9 100755 --- a/spec/unit/parser/ast/hostclass.rb +++ b/spec/unit/parser/ast/hostclass.rb @@ -42,6 +42,12 @@ describe Puppet::Parser::AST::HostClass do @top.evaluate(@scope) end + it "should return the existing resource when not creating a new one" do + @compiler.catalog.expects(:resource).with(:class, "top").returns("something") + @compiler.catalog.expects(:add_resource).never + @top.evaluate(@scope).should == "something" + end + it "should not create a new parent resource if one already exists and it has a parent class" do @top.evaluate(@scope) @@ -126,4 +132,4 @@ describe Puppet::Parser::AST::HostClass do @compiler.class_scope(@middle).namespaces.should be_include(@top.namespace) end end -end
\ No newline at end of file +end |