summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-11 22:23:23 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-11 22:23:23 +0000
commitf522a7e4fe87de6214d1d8e5e6d587d1948117ab (patch)
tree9529f77a196972cc84c29bb4cdf163907740e2ee
parent373fb3b57c9edafc1935789d7b5cb99d45656f2e (diff)
downloadpuppet-f522a7e4fe87de6214d1d8e5e6d587d1948117ab.tar.gz
puppet-f522a7e4fe87de6214d1d8e5e6d587d1948117ab.tar.xz
puppet-f522a7e4fe87de6214d1d8e5e6d587d1948117ab.zip
Adding the host name as a tag (stripped of the domain name)
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1105 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/ast/node.rb4
-rwxr-xr-xtest/language/ast.rb36
-rw-r--r--test/puppettest.rb2
3 files changed, 36 insertions, 6 deletions
diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb
index 2e68cbdb3..2a8e6a85b 100644
--- a/lib/puppet/parser/ast/node.rb
+++ b/lib/puppet/parser/ast/node.rb
@@ -39,6 +39,10 @@ class Puppet::Parser::AST
# And then evaluate our code.
@code.safeevaluate(:scope => scope)
+ # Mark our node name as a class, too, but strip it of the domain
+ # name.
+ scope.setclass(self.object_id, @type.sub(/\..+/, ''))
+
return scope
end
diff --git a/test/language/ast.rb b/test/language/ast.rb
index dc5934bc2..5ffb72091 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -351,11 +351,11 @@ class TestAST < Test::Unit::TestCase
# create a short-name node
shortname = "mynodename"
- children << nodeobj(shortname)
+ children << nodedef(shortname)
# And a long-name node
longname = "node.domain.com"
- children << nodeobj(longname)
+ children << nodedef(longname)
# Create the wrapper object
top = nil
@@ -399,7 +399,7 @@ class TestAST < Test::Unit::TestCase
# create a short-name node
name = "mynodename"
- children << nodeobj(name)
+ children << nodedef(name)
# Create the wrapper object
top = nil
@@ -480,7 +480,7 @@ class TestAST < Test::Unit::TestCase
# create the base node
name = "basenode"
- children << nodeobj(name)
+ children << nodedef(name)
# and the sub node
name = "subnode"
@@ -494,7 +494,7 @@ class TestAST < Test::Unit::TestCase
]
)
)
- #subnode = nodeobj(name)
+ #subnode = nodedef(name)
#subnode.parentclass = "basenode"
#children << subnode
@@ -675,4 +675,30 @@ class TestAST < Test::Unit::TestCase
end
end
+
+ # Test that we strip the domain off of host names before they are set as classes
+ def test_nodenamestrip
+ children = []
+
+ longname = "node.domain.com"
+ children << nodedef(longname)
+
+ # Create the wrapper object
+ top = nil
+ assert_nothing_raised("Could not create top object") {
+ top = AST::ASTArray.new(
+ :children => children
+ )
+ }
+
+ scope = Puppet::Parser::Scope.new()
+
+ assert_nothing_raised("Could not evaluate node") {
+ objects = scope.evaluate(:names => [longname], :facts => {}, :ast => top)
+ }
+
+ assert(!scope.classlist.include?("node.domain.com"),
+ "Node's long name got set")
+ assert(scope.classlist.include?("node"), "Node's name did not get set")
+ end
end
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 627ac6897..470a3d4fe 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -807,7 +807,7 @@ module ParserTesting
}
end
- def nodeobj(name)
+ def nodedef(name)
assert_nothing_raised("Could not create node %s" % name) {
return AST::NodeDef.new(
:file => tempfile(),