summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-27 23:09:53 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-27 23:09:53 +0000
commit56116c2aa64ccbbc6740d30b5901b2700bcae036 (patch)
treec03cac4bf2eb6ea372bd0476ae388317a0bb2e26
parentc894eb20ddf812056e897217fd55d31182dbc52f (diff)
downloadpuppet-56116c2aa64ccbbc6740d30b5901b2700bcae036.tar.gz
puppet-56116c2aa64ccbbc6740d30b5901b2700bcae036.tar.xz
puppet-56116c2aa64ccbbc6740d30b5901b2700bcae036.zip
Fixing bug #73; node names now appear only once in the path
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@955 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/ast/node.rb6
-rw-r--r--lib/puppet/parser/ast/nodedef.rb6
-rw-r--r--lib/puppet/parser/scope.rb14
-rwxr-xr-xtest/language/ast.rb18
4 files changed, 34 insertions, 10 deletions
diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb
index e8f4c5d87..97e8de06e 100644
--- a/lib/puppet/parser/ast/node.rb
+++ b/lib/puppet/parser/ast/node.rb
@@ -3,18 +3,18 @@ class Puppet::Parser::AST
# other objects. That's just the way it is, at least for now.
class Node < AST::HostClass
@name = :node
- attr_accessor :name, :args, :code, :parentclass
+ attr_accessor :type, :args, :code, :parentclass
#def evaluate(scope, facts = {})
def evaluate(hash)
scope = hash[:scope]
facts = hash[:facts] || {}
+ #scope.info "name is %s, type is %s" % [self.name, self.type]
# nodes are never instantiated like a normal object,
# but we need the type to be the name users would use for
# instantiation, otherwise tags don't work out
scope = scope.newscope(
- :type => @name,
- :name => @name,
+ :type => self.type,
:keyword => @keyword
)
scope.context = self.object_id
diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb
index d41eeecde..cc710329f 100644
--- a/lib/puppet/parser/ast/nodedef.rb
+++ b/lib/puppet/parser/ast/nodedef.rb
@@ -21,8 +21,12 @@ class Puppet::Parser::AST
names.each { |name|
#Puppet.debug("defining host '%s' in scope %s" %
# [name, scope.object_id])
+ # We use 'type' here instead of name, because every component
+ # type supports both 'type' and 'name', and 'type' is a more
+ # appropriate description of the syntactic role that this term
+ # plays.
arghash = {
- :name => name,
+ :type => name,
:code => @code
}
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 344372327..e81664219 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -190,7 +190,12 @@ module Puppet
# If they've passed classes in, then just generate from there.
if classes
- return self.gennode(names, facts, classes, parent)
+ return self.gennode(
+ :names => names,
+ :facts => facts,
+ :classes => classes,
+ :parent => parent
+ )
end
scope = code = nil
@@ -243,7 +248,12 @@ module Puppet
# Pull in all of the appropriate classes and evaluate them. It'd
# be nice if this didn't know quite so much about how AST::Node
# operated internally.
- def gennode(names, facts, classes, parent)
+ #def gennode(names, facts, classes, parent)
+ def gennode(hash)
+ names = hash[:names]
+ facts = hash[:facts]
+ classes = hash[:classes]
+ parent = hash[:parent]
name = names.shift
arghash = {
:name => name,
diff --git a/test/language/ast.rb b/test/language/ast.rb
index fa7d8a651..0c164b64a 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -172,9 +172,8 @@ class TestAST < Test::Unit::TestCase
scope = nil
assert_nothing_raised("Could not evaluate node") {
scope = Puppet::Parser::Scope.new()
- scope.name = "nodetest"
- scope.type = "nodetest"
- scope.keyword = "nodetest"
+ scope.type = "puppet"
+ scope.name = "top"
scope.top = true
top.evaluate(:scope => scope)
}
@@ -210,9 +209,20 @@ class TestAST < Test::Unit::TestCase
# of the parent class
assert(! scope.lookupclass("parent"), "Found parent class in top scope")
+ trans = nil
# Verify that we can evaluate the node twice
assert_nothing_raised("Could not retrieve node definition") {
- scope.evalnode(:name => [nodename], :facts => {})
+ trans = scope.evalnode(:name => [nodename], :facts => {})
+ }
+
+ objects = nil
+ assert_nothing_raised("Could not convert to objects") {
+ objects = trans.to_type
+ }
+
+ Puppet.type(:file).each { |obj|
+ assert(obj.path !~ /#{nodename}\[#{nodename}\]/,
+ "Node name appears twice")
}
end