[PATCH 0/1] Fix #1104 - Classes and nodes should set $name variables

5 views
Skip to first unread message

Brice Figureau

unread,
Oct 11, 2008, 12:57:42 PM10/11/08
to puppe...@googlegroups.com
Hi,

Still on my journey in closing Puppet language tickets. I now almost feel
like I'm a Puppet Language expert :-)

Please review and comment as usual,

Thanks,
Brice

Brice Figureau (1):
Fix #1104 - Classes and nodes should set $name variables

lib/puppet/parser/ast/hostclass.rb | 7 ++++++-
spec/unit/parser/ast/hostclass.rb | 13 +++++++++++++
2 files changed, 19 insertions(+), 1 deletions(-)

Brice Figureau

unread,
Oct 11, 2008, 12:57:43 PM10/11/08
to puppe...@googlegroups.com
Signed-off-by: Brice Figureau <brice-...@daysofwonder.com>
---

lib/puppet/parser/ast/hostclass.rb | 7 ++++++-
spec/unit/parser/ast/hostclass.rb | 13 +++++++++++++
2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb
index 7f89f81..4f5c479 100644
--- a/lib/puppet/parser/ast/hostclass.rb
+++ b/lib/puppet/parser/ast/hostclass.rb
@@ -56,7 +56,12 @@ class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition

# Don't create a subscope for the top-level class, since it already
# has its own scope.
- scope = subscope(scope, resource) unless resource.title == :main
+ unless resource.title == :main
+ scope = subscope(scope, resource)
+
+ scope.setvar("title", resource.title)
+ scope.setvar("name", resource.name)
+ end

# Add the parent scope namespaces to our own.
if pnames
diff --git a/spec/unit/parser/ast/hostclass.rb b/spec/unit/parser/ast/hostclass.rb
index 0abc174..10aa621 100755
--- a/spec/unit/parser/ast/hostclass.rb
+++ b/spec/unit/parser/ast/hostclass.rb
@@ -123,6 +123,19 @@ describe Puppet::Parser::AST::HostClass do
@compiler.class_scope(@middle).parent.should equal(@compiler.class_scope(@top))
end

+ it "should add the class's name and title to its own scope" do
+ @top_resource.stubs(:safeevaluate)
+ @middle_resource.stubs(:safeevaluate)
+ resource = @middle.evaluate(@scope)
+ scope = stub_everything 'scope', :compiler => @compiler
+ @middle.stubs(:subscope).returns(scope)
+
+ scope.expects(:setvar).with("title","top::middle")
+ scope.expects(:setvar).with("name","top::middle")
+
+ @middle.evaluate_code(resource)
+ end
+
it "should add the parent class's namespace to its namespace search path" do
@top_resource.stubs(:safeevaluate)
@middle_resource.stubs(:safeevaluate)
--
1.6.0.2

Luke Kanies

unread,
Oct 11, 2008, 4:06:26 PM10/11/08
to puppe...@googlegroups.com
+1


--
Basic research is what I am doing when I don't know what I am doing.
--Wernher von Braun
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

Reply all
Reply to author
Forward
0 new messages