summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-15 22:17:20 -0600
committerLuke Kanies <luke@madstop.com>2007-09-15 22:17:20 -0600
commitf17f19dae941b17a56c1fc83ed3a89712b98c427 (patch)
tree3615e9be9ed585511bbe0b85737208bbd85f00f0 /test/lib
parent3ccf483f77b026dde8a53bd8e9dff6a5fd0f6722 (diff)
The whole system now uses Configuration objects instead of
ever converting the Transportable objects into a tree of components and then converting that into a graph. This is a significant step, and drastically simplifies the model of how to use a configuration. The old code might have looked something like this: file = Puppet::Type.create :path => "/whatever", ... comp = Puppet::Type.create :name => :whatever comp.push file transaction = comp.evaluate transaction.evaluate The new code looks like this: file = Puppet::Type.create :path => "/whatever", ... config = Puppet::Node::Configuration.new config.add_resource file config.apply I did not really intend to do this much refactoring, but I found I could not use a Configuration object to do work without refactoring a lot of the system. The primary problem was that the Client::Master and the Config classes determined how the transactions behaved; when I moved to using a Configuration, this distinction was lost, which meant that configurations were often needing to create other configurations, which resulted in a whole lot of infinite recursion (e.g., Config objects that create directories for Puppet use Configuration objects -- yes, I'm s/Config/Settings/g soon -- and these Configuration objects would need to create directories). Not everything is fixed, but it's very close. I am clearly over the hump, though, so I wanted to get a commit in.
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/puppettest/support/assertions.rb52
-rwxr-xr-xtest/lib/puppettest/support/resources.rb34
-rw-r--r--test/lib/puppettest/support/utils.rb38
3 files changed, 55 insertions, 69 deletions
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 9369f17e7..7e3e5ca2b 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -38,7 +38,7 @@ module PuppetTest
run_events(:rollback, trans, events, msg)
end
- def assert_events(events, *items)
+ def assert_events(events, *resources)
trans = nil
comp = nil
msg = nil
@@ -46,56 +46,26 @@ module PuppetTest
unless events.is_a? Array
raise Puppet::DevError, "Incorrect call of assert_events"
end
- if items[-1].is_a? String
- msg = items.pop
+ if resources[-1].is_a? String
+ msg = resources.pop
end
- remove_comp = false
- # They either passed a comp or a list of items.
- if items[0].is_a? Puppet.type(:component)
- comp = items.shift
- else
- comp = newcomp(items[0].title, *items)
- remove_comp = true
- end
- msg ||= comp.title
- assert_nothing_raised("Component %s failed" % [msg]) {
- trans = comp.evaluate
- }
+ config = resources2config(*resources)
+ transaction = Puppet::Transaction.new(config)
- run_events(:evaluate, trans, events, msg)
+ run_events(:evaluate, transaction, events, msg)
- if remove_comp
- Puppet.type(:component).delete(comp)
- end
-
- return trans
+ return transaction
end
# A simpler method that just applies what we have.
- def assert_apply(*objects)
- if objects[0].is_a?(Puppet.type(:component))
- comp = objects.shift
- unless objects.empty?
- objects.each { |o| comp.push o }
- end
- else
- comp = newcomp(*objects)
- end
- trans = nil
-
- assert_nothing_raised("Failed to create transaction") {
- trans = comp.evaluate
- }
+ def assert_apply(*resources)
+ config = resources2config(*resources)
events = nil
- assert_nothing_raised("Failed to evaluate transaction") {
- events = trans.evaluate.collect { |e| e.event }
+ assert_nothing_raised("Failed to evaluate") {
+ events = config.apply.events
}
- trans.cleanup
- Puppet.type(:component).delete(comp)
events
end
end
-
-# $Id$
diff --git a/test/lib/puppettest/support/resources.rb b/test/lib/puppettest/support/resources.rb
index 45d89c5fb..18d7caa77 100755
--- a/test/lib/puppettest/support/resources.rb
+++ b/test/lib/puppettest/support/resources.rb
@@ -4,34 +4,34 @@
# Copyright (c) 2006. All rights reserved.
module PuppetTest::Support::Resources
- def treefile(name)
- Puppet::Type.type(:file).create :path => "/tmp/#{name}", :mode => 0755
+ def tree_resource(name)
+ Puppet::Type.type(:file).create :title => name, :path => "/tmp/#{name}", :mode => 0755
end
- def treecomp(name)
+ def tree_container(name)
Puppet::Type::Component.create :name => name, :type => "yay"
end
- def treenode(name, *children)
- comp = treecomp name
- children.each do |c|
- if c.is_a?(String)
- comp.push treefile(c)
- else
- comp.push c
+ def treenode(config, name, *resources)
+ comp = tree_container name
+ resources.each do |resource|
+ if resource.is_a?(String)
+ resource = tree_resource(resource)
end
+ config.add_edge!(comp, resource)
+ config.add_resource resource unless config.resource(resource.ref)
end
return comp
end
def mktree
- one = treenode("one", "a", "b")
- two = treenode("two", "c", "d")
- middle = treenode("middle", "e", "f", two)
- top = treenode("top", "g", "h", middle, one)
+ configuration = Puppet::Node::Configuration.new do |config|
+ one = treenode(config, "one", "a", "b")
+ two = treenode(config, "two", "c", "d")
+ middle = treenode(config, "middle", "e", "f", two)
+ top = treenode(config, "top", "g", "h", middle, one)
+ end
- return one, two, middle, top
+ return configuration
end
end
-
-# $Id$ \ No newline at end of file
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index c7d54d5e6..7f4260e31 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -19,6 +19,25 @@ module PuppetTest
}
end
+ # Turn a list of resources, or possibly a configuration and some resources,
+ # into a configuration object.
+ def resources2config(*resources)
+ if resources[0].is_a?(Puppet::Node::Configuration)
+ config = resources.shift
+ unless resources.empty?
+ resources.each { |r| config.add_resource r }
+ end
+ elsif resources[0].is_a?(Puppet.type(:component))
+ raise ArgumentError, "resource2config() no longer accpts components"
+ comp = resources.shift
+ comp.delve
+ else
+ config = Puppet::Node::Configuration.new
+ resources.each { |res| config.add_resource res }
+ end
+ return config
+ end
+
# stop any services that might be hanging around
def stopservices
if stype = Puppet::Type.type(:service)
@@ -127,20 +146,17 @@ module PuppetTest
}
end
- def newcomp(*ary)
- name = nil
- if ary[0].is_a?(String)
- name = ary.shift
+ def mk_configuration(*resources)
+ if resources[0].is_a?(String)
+ name = resources.shift
else
- name = ary[0].title
+ name = :testing
+ end
+ config = Puppet::Node::Configuration.new :testing do |conf|
+ resources.each { |resource| conf.add_resource resource }
end
- comp = Puppet.type(:component).create(:name => name)
- ary.each { |item|
- comp.push item
- }
-
- return comp
+ return config
end
def setme