summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/collector.rb8
-rw-r--r--lib/puppet/parser/compile.rb6
-rwxr-xr-xtest/language/compile.rb37
-rw-r--r--test/lib/puppettest/parsertesting.rb12
-rwxr-xr-xtest/network/client/client.rb5
-rwxr-xr-xtest/rails/ast.rb3
-rwxr-xr-xtest/rails/collection.rb16
-rwxr-xr-xtest/rails/configuration.rb10
-rwxr-xr-xtest/rails/host.rb2
-rwxr-xr-xtest/rails/railsresource.rb8
-rwxr-xr-xtest/tagging/tagging.rb170
11 files changed, 61 insertions, 216 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index c9d5ed5f0..d995bf7a7 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -121,6 +121,10 @@ class Puppet::Parser::Collector
def initialize(scope, type, equery, vquery, form)
@scope = scope
+
+ unless scope.resource
+ raise "wtf?"
+ end
@type = type
@equery = equery
@vquery = vquery
@@ -162,7 +166,7 @@ class Puppet::Parser::Collector
# XXX Because the scopes don't expect objects to return values,
# we have to manually add our objects to the scope. This is
# ber-lame.
- scope.setresource(resource)
+ scope.compile.store_resource(scope, resource)
rescue => detail
if Puppet[:trace]
puts detail.backtrace
@@ -174,5 +178,3 @@ class Puppet::Parser::Collector
return resource
end
end
-
-# $Id$
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index cc9938e50..6aeebeaae 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -246,7 +246,11 @@ class Puppet::Parser::Compile
raise Puppet::ParseError, "Could not find default node or by name with '%s'" % node.names.join(", ")
end
- astnode.safeevaluate :scope => topscope
+ # Create a resource to model this node, and then add it to the list
+ # of resources.
+ resource = Puppet::Parser::Resource.new(:type => "node", :title => astnode.classname, :scope => topscope, :source => topscope.source)
+ store_resource(topscope, resource)
+ @configuration.tag(astnode.classname)
end
# Evaluate our collections and return true if anything returned an object.
diff --git a/test/language/compile.rb b/test/language/compile.rb
index ceec3c346..5732acba3 100755
--- a/test/language/compile.rb
+++ b/test/language/compile.rb
@@ -189,6 +189,7 @@ class TestCompile < Test::Unit::TestCase
def test_evaluate_ast_node
# First try it with ast_nodes disabled
compile = mkcompile :ast_nodes => false
+ name = compile.node.name
compile.expects(:ast_nodes?).returns(false)
compile.parser.expects(:nodes).never
@@ -196,11 +197,14 @@ class TestCompile < Test::Unit::TestCase
compile.send(:evaluate_ast_node)
end
+ assert_nil(compile.resources.find { |r| r.to_s == "Node[#{name}]" }, "Created node object when ast_nodes was false")
+
# Now try it with them enabled, but no node found.
nodes = mock 'node_hash'
compile = mkcompile :ast_nodes => true
+ name = compile.node.name
compile.expects(:ast_nodes?).returns(true)
- compile.parser.expects(:nodes).returns(nodes).times(4)
+ compile.parser.stubs(:nodes).returns(nodes)
# Set some names for our test
@node.names = %w{a b c}
@@ -217,44 +221,41 @@ class TestCompile < Test::Unit::TestCase
end
# Finally, make sure it works dandily when we have a node
- nodes = mock 'hash'
compile = mkcompile :ast_nodes => true
compile.expects(:ast_nodes?).returns(true)
- compile.parser.expects(:nodes).returns(nodes).times(3)
- node = mock 'node'
- node.expects(:safeevaluate).with(:scope => compile.topscope)
+ node = stub 'node', :classname => "c"
+ nodes = {"c" => node}
+ compile.parser.stubs(:nodes).returns(nodes)
+
# Set some names for our test
@node.names = %w{a b c}
- nodes.expects(:[]).with("a").returns(nil)
- nodes.expects(:[]).with("b").returns(nil)
- nodes.expects(:[]).with("c").returns(node)
- nodes.expects(:[]).with("default").never
- # And make sure the lack of a node throws an exception
+ # And make sure we throw no exceptions.
assert_nothing_raised("Failed when a node was found") do
compile.send(:evaluate_ast_node)
end
+ assert_instance_of(Puppet::Parser::Resource, compile.resources.find { |r| r.to_s == "Node[c]" },
+ "Did not create node resource")
+
# Lastly, check when we actually find the default.
- nodes = mock 'hash'
compile = mkcompile :ast_nodes => true
compile.expects(:ast_nodes?).returns(true)
- compile.parser.expects(:nodes).returns(nodes).times(4)
- node = mock 'node'
- node.expects(:safeevaluate).with(:scope => compile.topscope)
+ node = stub 'node', :classname => "default"
+ nodes = {"default" => node}
+ compile.parser.stubs(:nodes).returns(nodes)
+
# Set some names for our test
@node.names = %w{a b c}
- nodes.expects(:[]).with("a").returns(nil)
- nodes.expects(:[]).with("b").returns(nil)
- nodes.expects(:[]).with("c").returns(nil)
- nodes.expects(:[]).with("default").returns(node)
# And make sure the lack of a node throws an exception
assert_nothing_raised("Failed when a node was found") do
compile.send(:evaluate_ast_node)
end
+ assert_instance_of(Puppet::Parser::Resource, compile.resources.find { |r| r.to_s == "Node[default]" },
+ "Did not create default node resource")
end
def test_evaluate_node_classes
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index c71508803..eef0cd8bc 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -41,7 +41,7 @@ module PuppetTest::ParserTesting
)
end
- def mkconfig(parser = nil)
+ def mkcompile(parser = nil)
require 'puppet/network/handler/node'
parser ||= mkparser
node = mknode
@@ -67,15 +67,15 @@ module PuppetTest::ParserTesting
def mkscope(hash = {})
hash[:parser] ||= mkparser
- config ||= mkconfig(hash[:parser])
- config.topscope.source = (hash[:parser].findclass("", "") || hash[:parser].newclass(""))
+ compile ||= mkcompile(hash[:parser])
+ compile.topscope.source = (hash[:parser].findclass("", "") || hash[:parser].newclass(""))
- unless config.topscope.source
+ unless compile.topscope.source
raise "Could not find source for scope"
end
# Make the 'main' stuff
- config.send(:evaluate_main)
- config.topscope
+ compile.send(:evaluate_main)
+ compile.topscope
end
def classobj(name, hash = {})
diff --git a/test/network/client/client.rb b/test/network/client/client.rb
index 3f540d10f..93c63d637 100755
--- a/test/network/client/client.rb
+++ b/test/network/client/client.rb
@@ -164,7 +164,10 @@ class TestClient < Test::Unit::TestCase
# Fake that it's local, so it creates the class file
client.local = false
- client.expects(:setclasses).with(%w{yaytest bootest})
+ # We can't guarantee class ordering
+ client.expects(:setclasses).with do |array|
+ array.length == 2 and array.include?("yaytest") and array.include?("bootest")
+ end
assert_nothing_raised {
client.getconfig
}
diff --git a/test/rails/ast.rb b/test/rails/ast.rb
index b205aa0d5..fb6374401 100755
--- a/test/rails/ast.rb
+++ b/test/rails/ast.rb
@@ -20,7 +20,8 @@ class TestRailsAST < PuppetTest::TestCase
def test_exported_collexp
railsinit
Puppet[:storeconfigs] = true
- @interp, @scope, @source = mkclassframing
+
+ @scope = mkscope
# make a rails resource
railsresource "file", "/tmp/testing", :owner => "root", :group => "bin",
diff --git a/test/rails/collection.rb b/test/rails/collection.rb
index 31aa02928..56f71e635 100755
--- a/test/rails/collection.rb
+++ b/test/rails/collection.rb
@@ -23,6 +23,7 @@ class TestRailsCollection < PuppetTest::TestCase
super
Puppet[:trace] = false
@scope = mkscope
+ @scope.compile.send(:evaluate_main)
end
def test_collect_exported
@@ -31,7 +32,7 @@ class TestRailsCollection < PuppetTest::TestCase
# make an exported resource
exported = mkresource(:type => "file", :title => "/tmp/exported",
:exported => true, :params => {:owner => "root"})
- @scope.setresource exported
+ @scope.compile.store_resource @scope, exported
assert(exported.exported?, "Object was not marked exported")
assert(exported.virtual?, "Object was not marked virtual")
@@ -39,7 +40,7 @@ class TestRailsCollection < PuppetTest::TestCase
# And a non-exported
real = mkresource(:type => "file", :title => "/tmp/real",
:params => {:owner => "root"})
- @scope.setresource real
+ @scope.compile.store_resource @scope, real
# Now make a collector
coll = nil
@@ -122,16 +123,17 @@ class TestRailsCollection < PuppetTest::TestCase
# Make a new set with a different node name
node = mknode("other")
- config = Puppet::Parser::Compile.new(node, mkparser)
- config.topscope.source = mock("source")
+ compile = Puppet::Parser::Compile.new(node, mkparser)
+ compile.send(:evaluate_main)
+ compile.topscope.source = mock("source")
# It's important that it's a different name, since same-name resources are ignored.
- assert_equal("other", config.node.name, "Did not get correct node name")
+ assert_equal("other", compile.node.name, "Did not get correct node name")
# Now make a collector
coll = nil
assert_nothing_raised do
- coll = Puppet::Parser::Collector.new(config.topscope, "file", nil, nil, :exported)
+ coll = Puppet::Parser::Collector.new(compile.topscope, "file", nil, nil, :exported)
end
# And try to collect the virtual resources.
@@ -163,7 +165,7 @@ class TestRailsCollection < PuppetTest::TestCase
# Now make a normal resource
normal = mkresource(:type => "file", :title => "/tmp/conflicttest",
:params => {:owner => "root"})
- @scope.setresource normal
+ @scope.compile.store_resource @scope, normal
# Now make a collector
coll = nil
diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb
index 31d1cf779..752ea5375 100755
--- a/test/rails/configuration.rb
+++ b/test/rails/configuration.rb
@@ -24,11 +24,11 @@ class ConfigurationRailsTests < PuppetTest::TestCase
# We need to make sure finished objects are stored in the db.
def test_finish_before_store
railsinit
- config = mkconfig
- config.ast_nodes = true
- parser = config.parser
+ compile = mkcompile
+ compile.ast_nodes = true
+ parser = compile.parser
- node = parser.newnode [config.node.name], :code => AST::ASTArray.new(:children => [
+ node = parser.newnode [compile.node.name], :code => AST::ASTArray.new(:children => [
resourcedef("file", "/tmp/yay", :group => "root"),
defaultobj("file", :owner => "root")
])
@@ -44,7 +44,7 @@ class ConfigurationRailsTests < PuppetTest::TestCase
raise "Resource was not passed to store()"
end
end
- config.compile
+ compile.compile
end
def test_hoststorage
diff --git a/test/rails/host.rb b/test/rails/host.rb
index 67095a18a..5ac2f763e 100755
--- a/test/rails/host.rb
+++ b/test/rails/host.rb
@@ -35,7 +35,7 @@ class TestRailsHost < PuppetTest::TestCase
end
def test_store
- @interp, @scope, @source = mkclassframing
+ @scope = mkscope
# First make some objects
resources = []
4.times { |i|
diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb
index b8e5450b3..ca582b8b0 100755
--- a/test/rails/railsresource.rb
+++ b/test/rails/railsresource.rb
@@ -7,12 +7,14 @@ require 'puppet/rails'
require 'puppettest'
require 'puppettest/railstesting'
require 'puppettest/resourcetesting'
+require 'puppettest/parsertesting'
# Don't do any tests w/out this class
if Puppet.features.rails?
class TestRailsResource < Test::Unit::TestCase
include PuppetTest::RailsTesting
include PuppetTest::ResourceTesting
+ include PuppetTest::ParserTesting
def setup
super
@@ -55,7 +57,7 @@ class TestRailsResource < Test::Unit::TestCase
resource = mktest_resource
# We need a scope
- interp, scope, source = mkclassframing
+ scope = mkscope
# Find the new resource and include all it's parameters.
resource = Puppet::Rails::Resource.find_by_id(resource.id)
@@ -69,7 +71,7 @@ class TestRailsResource < Test::Unit::TestCase
assert_equal("root", res[:owner])
assert_equal("644", res[:mode])
assert_equal("/tmp/to_resource", res.title)
- assert_equal(source, res.source)
+ assert_equal(scope.source, res.source)
end
def test_parameters
@@ -111,7 +113,7 @@ class TestExportedResources < PuppetTest::TestCase
def setup
super
Puppet[:trace] = false
- @interp, @scope, @source = mkclassframing
+ @scope = mkscope
end
confine "Missing rails support" => Puppet.features.rails?
diff --git a/test/tagging/tagging.rb b/test/tagging/tagging.rb
deleted file mode 100755
index afab3faa4..000000000
--- a/test/tagging/tagging.rb
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/usr/bin/env ruby
-
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'puppet'
-require 'puppettest'
-require 'puppettest/parsertesting'
-require 'puppettest/resourcetesting'
-
-class TestTagging < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
-
- # Make sure the scopes are getting the right tags
- def test_scopetags
- scope = nil
- assert_nothing_raised {
- scope = mkscope
- scope.name = "yayness"
- scope.type = "solaris"
- }
-
- assert_nothing_raised {
- assert_equal(%w{solaris}, scope.tags, "Incorrect scope tags")
- }
- end
-
- # Test deeper tags, where a scope gets all of its parent scopes' tags
- def test_deepscopetags
- scope = nil
- assert_nothing_raised {
- scope = mkscope
- scope.name = "yayness"
- scope.type = "solaris"
- scope = scope.newscope
- scope.name = "booness"
- scope.type = "apache"
- }
-
- assert_nothing_raised {
- # Scopes put their own tags first
- assert_equal(%w{apache solaris}, scope.tags, "Incorrect scope tags")
- }
- end
-
- # Verify that the tags make their way to the objects
- def test_objecttags
- scope = nil
- assert_nothing_raised {
- scope = mkscope
- scope.name = "yayness"
- scope.type = "solaris"
- }
-
- resource = mkresource :type => "file", :title => "/tmp/testing",
- :params => {:owner => "root"}, :file => "/yay", :line => 1,
- :scope => scope
-
- assert_nothing_raised {
- scope.setresource(resource)
- }
-
- assert_nothing_raised {
- assert_equal(%w{solaris file}, resource.tags,
- "Incorrect tags")
- }
- end
-
- # Make sure that specifying tags results in only those objects getting
- # run.
- def test_tagspecs
- a = tempfile()
- b = tempfile()
-
- afile = Puppet.type(:file).create(
- :path => a,
- :ensure => :file
- )
- afile.tag("a")
-
- bfile = Puppet.type(:file).create(
- :path => b,
- :ensure => :file
- )
- bfile.tag(:b)
-
- # First, make sure they get created when no spec'ed tags
- assert_events([:file_created,:file_created], afile, bfile)
- assert(FileTest.exists?(a), "A did not get created")
- assert(FileTest.exists?(b), "B did not get created")
- File.unlink(a)
- File.unlink(b)
-
- # Set the tags to a
- assert_nothing_raised {
- Puppet[:tags] = "a"
- }
-
- assert_events([:file_created], afile, bfile)
- assert(FileTest.exists?(a), "A did not get created")
- assert(!FileTest.exists?(b), "B got created")
- File.unlink(a)
-
- # Set the tags to b
- assert_nothing_raised {
- Puppet[:tags] = "b"
- }
-
- assert_events([:file_created], afile, bfile)
- assert(!FileTest.exists?(a), "A got created")
- assert(FileTest.exists?(b), "B did not get created")
- File.unlink(b)
-
- # Set the tags to something else
- assert_nothing_raised {
- Puppet[:tags] = "c"
- }
-
- assert_events([], afile, bfile)
- assert(!FileTest.exists?(a), "A got created")
- assert(!FileTest.exists?(b), "B got created")
-
- # Now set both tags
- assert_nothing_raised {
- Puppet[:tags] = "b, a"
- }
-
- assert_events([:file_created, :file_created], afile, bfile)
- assert(FileTest.exists?(a), "A did not get created")
- assert(FileTest.exists?(b), "B did not get created")
- File.unlink(a)
-
- end
-
- def test_metaparamtag
- path = tempfile()
-
- start = %w{some tags}
- tags = %w{a list of tags}
-
- obj = nil
- assert_nothing_raised do
- obj = Puppet.type(:file).create(
- :path => path,
- :ensure => "file",
- :tag => start
- )
- end
-
-
- assert(obj, "Did not make object")
-
- start.each do |tag|
- assert(obj.tagged?(tag), "Object was not tagged with %s" % tag)
- end
-
- tags.each do |tag|
- assert_nothing_raised {
- obj[:tag] = tag
- }
- end
-
- tags.each do |tag|
- assert(obj.tagged?(tag), "Object was not tagged with %s" % tag)
- end
- end
-end
-
-# $Id$