diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-25 00:43:15 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-25 00:43:15 -0500 |
| commit | 4679f4dcc110e3362b0097efe1d5a416c659611b (patch) | |
| tree | d8dd9aa3f220c7a1d8e3cb0d486e1a7bba7276f7 /test | |
| parent | c3c3e519219ad80ac07d21c74849fbc4246c9d7a (diff) | |
| parent | cdc8ea6e81c1b5eba5ea784bb7079c4c1f3965a4 (diff) | |
| download | puppet-4679f4dcc110e3362b0097efe1d5a416c659611b.tar.gz puppet-4679f4dcc110e3362b0097efe1d5a416c659611b.tar.xz puppet-4679f4dcc110e3362b0097efe1d5a416c659611b.zip | |
Merge branch 'indirection' of git://reductivelabs.com/puppet-luke
Diffstat (limited to 'test')
44 files changed, 379 insertions, 2199 deletions
diff --git a/test/certmgr/certmgr.rb b/test/certmgr/certmgr.rb index fb1611d7f..3d863dc27 100755 --- a/test/certmgr/certmgr.rb +++ b/test/certmgr/certmgr.rb @@ -239,13 +239,13 @@ class TestCertMgr < Test::Unit::TestCase ca.revoke(h1.serial) - oldcert = File.read(Puppet.config[:cacert]) - oldserial = File.read(Puppet.config[:serial]) + oldcert = File.read(Puppet.settings[:cacert]) + oldserial = File.read(Puppet.settings[:serial]) # Recreate the CA from disk ca = mkCA() - newcert = File.read(Puppet.config[:cacert]) - newserial = File.read(Puppet.config[:serial]) + newcert = File.read(Puppet.settings[:cacert]) + newserial = File.read(Puppet.settings[:serial]) assert_equal(oldcert, newcert, "The certs are not equal after making a new CA.") assert_equal(oldserial, newserial, "The serials are not equal after making a new CA.") store = mkStore(ca) diff --git a/test/certmgr/inventory.rb b/test/certmgr/inventory.rb index 15d3e5217..9efcb0c09 100755 --- a/test/certmgr/inventory.rb +++ b/test/certmgr/inventory.rb @@ -56,8 +56,8 @@ class TestCertInventory < Test::Unit::TestCase file.expects(:puts).with do |written| written.include? cert.subject.to_s end - Puppet::Util::Config.any_instance.stubs(:write) - Puppet::Util::Config.any_instance.expects(:write). + Puppet::Util::Settings.any_instance.stubs(:write) + Puppet::Util::Settings.any_instance.expects(:write). with(:cert_inventory, 'a').yields(file) Puppet::SSLCertificates::Inventory.add(cert) diff --git a/test/data/snippets/failmissingexecpath.pp b/test/data/snippets/failmissingexecpath.pp deleted file mode 100644 index b03875547..000000000 --- a/test/data/snippets/failmissingexecpath.pp +++ /dev/null @@ -1,14 +0,0 @@ -define distloc($path) { - file { "/tmp/exectesting1": - ensure => file - } - exec { "exectest": - command => "touch $path", - subscribe => File["/tmp/exectesting1"], - refreshonly => true - } -} - -distloc { yay: - path => "/tmp/execdisttesting", -} diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 2c74543e7..7168a81d8 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -197,7 +197,7 @@ class TestSnippets < Test::Unit::TestCase def snippet_classpathtest path = "/tmp/classtest" - file = @file[path] + file = @configuration.resource(:file, path) assert(file, "did not create file %s" % path) assert_nothing_raised { @@ -271,14 +271,6 @@ class TestSnippets < Test::Unit::TestCase assert_mode_equal(0755, file) end - def snippet_failmissingexecpath - file = "/tmp/exectesting1" - execfile = "/tmp/execdisttesting" - assert_file(file) - - assert_nil(Puppet::Type.type(:exec)["exectest"], "invalid exec was created") - end - def snippet_selectorvalues nums = %w{1 2 3 4 5} files = nums.collect { |n| @@ -472,13 +464,14 @@ class TestSnippets < Test::Unit::TestCase :Manifest => snippet(file), :Local => true ) - server.send(:fact_handler).stubs(:set) - server.send(:fact_handler).stubs(:get).returns(facts) + facts = Puppet::Node::Facts.new("testhost", facts) + Puppet::Node::Facts.stubs(:save) + Puppet::Node::Facts.stubs(:find).returns(facts) client = Puppet::Network::Client.master.new( :Master => server, :Cache => false ) - client.class.stubs(:facts).returns(facts) + client.class.stubs(:facts).returns(facts.values) assert(client.local) assert_nothing_raised { @@ -507,6 +500,7 @@ class TestSnippets < Test::Unit::TestCase assert(obj.name) } } + @configuration = client.configuration assert_nothing_raised { self.send(mname) } diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index b56bc563e..021d6d1de 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -5,7 +5,12 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../lib require 'puppet' require 'mocha' -require 'test/unit' + +# Only load the test/unit class if we're not in the spec directory. +# Else we get the bogus 'no tests, no failures' message. +unless Dir.getwd =~ /spec/ + require 'test/unit' +end # Yay; hackish but it works if ARGV.include?("-d") @@ -141,7 +146,7 @@ module PuppetTest end @configpath = File.join(tmpdir, - self.class.to_s + "configdir" + @@testcount.to_s + "/" + "configdir" + @@testcount.to_s + "/" ) unless defined? $user and $group @@ -149,7 +154,7 @@ module PuppetTest $group = nonrootgroup().gid.to_s end - Puppet.config.clear + Puppet.settings.clear Puppet[:user] = $user Puppet[:group] = $group @@ -197,8 +202,7 @@ module PuppetTest @@tmpfilenum = 1 end - f = File.join(self.tmpdir(), self.class.to_s + "_" + @method_name.to_s + - @@tmpfilenum.to_s) + f = File.join(self.tmpdir(), "tempfile_" + @@tmpfilenum.to_s) @@tmpfiles << f return f end @@ -223,11 +227,11 @@ module PuppetTest when "Darwin": "/private/tmp" when "SunOS": "/var/tmp" else - "/tmp" + "/tmp" end - @tmpdir = File.join(@tmpdir, "puppettesting") + @tmpdir = File.join(@tmpdir, "puppettesting" + Process.pid.to_s) unless File.exists?(@tmpdir) FileUtils.mkdir_p(@tmpdir) @@ -260,6 +264,8 @@ module PuppetTest Puppet::Type.allclear Puppet::Util::Storage.clear Puppet.clear + Puppet.settings.clear + Puppet::Indirector::Indirection.clear_cache @memoryatend = Puppet::Util.memory diff = @memoryatend - @memoryatstart diff --git a/test/lib/puppettest/graph.rb b/test/lib/puppettest/graph.rb deleted file mode 100644 index db77889bd..000000000 --- a/test/lib/puppettest/graph.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke A. Kanies on 2006-11-24. -# Copyright (c) 2006. All rights reserved. - -require 'puppet/util/graph' - -class Container - include Puppet::Util::Graph - include Enumerable - attr_accessor :name - def each - @children.each do |c| yield c end - end - - def initialize(name, ary) - @name = name - @children = ary - end - - def push(*ary) - ary.each { |c| @children.push(c)} - end - - def to_s - @name - end -end - -module PuppetTest::Graph - def build_tree - one = Container.new("one", %w{a b}) - two = Container.new("two", ["c", "d"]) - three = Container.new("three", ["i", "j"]) - middle = Container.new("middle", ["e", "f", two]) - top = Container.new("top", ["g", "h", middle, one, three]) - return one, two, three, middle, top - end -end - -# $Id$ diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index eef0cd8bc..62fa7213e 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -42,7 +42,6 @@ module PuppetTest::ParserTesting end def mkcompile(parser = nil) - require 'puppet/network/handler/node' parser ||= mkparser node = mknode return Compile.new(node, parser) @@ -309,17 +308,17 @@ module PuppetTest::ParserTesting ) } - config = nil + trans = nil assert_nothing_raised { - config = interp.compile(mknode) + trans = interp.compile(mknode) } - comp = nil + config = nil assert_nothing_raised { - comp = config.extract.to_type + config = trans.extract.to_configuration } - assert_apply(comp) + config.apply files.each do |file| assert(FileTest.exists?(file), "Did not create %s" % file) diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb new file mode 100644 index 000000000..e4b0f9033 --- /dev/null +++ b/test/lib/puppettest/runnable_test.rb @@ -0,0 +1,30 @@ +# Manage whether a test is runnable. +module PuppetTest + module RunnableTest + # Confine this test based on specified criteria. The keys of the + # hash should be the message to use if the test is not suitable, + # and the values should be either 'true' or 'false'; true values + # mean the test is suitable. + def confine(hash) + @confines ||= {} + hash.each do |message, result| + @confines[message] = result + end + end + + # Evaluate all of our tests to see if any of them are false + # and thus whether this test is considered not runnable. + def runnable? + @messages ||= [] + return false unless @messages.empty? + return true unless defined? @confines + @confines.find_all do |message, result| + ! result + end.each do |message, result| + @messages << message + end + + return @messages.empty? + end + end +end 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 diff --git a/test/lib/puppettest/testcase.rb b/test/lib/puppettest/testcase.rb index cfedeee26..15c835854 100644 --- a/test/lib/puppettest/testcase.rb +++ b/test/lib/puppettest/testcase.rb @@ -4,28 +4,11 @@ # Copyright (c) 2007. All rights reserved. require 'puppettest' +require 'puppettest/runnable_test' class PuppetTest::TestCase < Test::Unit::TestCase include PuppetTest - def self.confine(hash) - @confines ||= {} - hash.each do |message, result| - @confines[message] = result - end - end - - def self.runnable? - @messages ||= [] - return false unless @messages.empty? - return true unless defined? @confines - @confines.find_all do |message, result| - ! result - end.each do |message, result| - @messages << message - end - - return @messages.empty? - end + extend PuppetTest::RunnableTest def self.suite # Always skip this parent class. It'd be nice if there were a @@ -44,5 +27,3 @@ class PuppetTest::TestCase < Test::Unit::TestCase end end end - -# $Id$ diff --git a/test/network/client/ca.rb b/test/network/client/ca.rb index 00ed7413a..511b6fcaa 100755 --- a/test/network/client/ca.rb +++ b/test/network/client/ca.rb @@ -23,7 +23,7 @@ class TestClientCA < Test::Unit::TestCase end [:hostprivkey, :hostcert, :localcacert].each do |name| - assert(FileTest.exists?(Puppet.config[name]), + assert(FileTest.exists?(Puppet.settings[name]), "Did not create cert %s" % name) end end diff --git a/test/network/client/client.rb b/test/network/client/client.rb index 93c63d637..382cd55cf 100755 --- a/test/network/client/client.rb +++ b/test/network/client/client.rb @@ -113,9 +113,9 @@ class TestClient < Test::Unit::TestCase # Create a new ssl root. confdir = tempfile() Puppet[:ssldir] = confdir - Puppet.config.mkdir(:ssldir) - Puppet.config.clearused - Puppet.config.use(:ssl, :ca) + Puppet.settings.mkdir(:ssldir) + Puppet.settings.clearused + Puppet.settings.use(:ssl, :ca) mkserver diff --git a/test/network/client/master.rb b/test/network/client/master.rb index a29254d16..169a1de5f 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -88,51 +88,6 @@ class TestMasterClient < Test::Unit::TestCase return master, objects end - def test_apply - master, objects = mk_fake_client - - check = Proc.new do |hash| - assert(objects.trans, "transaction was not created") - trans = objects.trans - hash[:yes].each do |m| - assert_equal(1, trans.send(m.to_s + "?"), "did not call #{m} enough times") - end - hash[:no].each do |m| - assert_equal(0, trans.send(m.to_s + "?"), "called #{m} too many times") - end - end - - # First try it with no arguments - assert_nothing_raised do - master.apply - end - check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{report tags ignoreschedules} - assert_equal(0, master.reported, "master sent report with reports disabled") - - - # Now enable reporting and make sure the report method gets called - Puppet[:report] = true - assert_nothing_raised do - master.apply - end - check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{tags ignoreschedules} - assert_equal(1, master.reported, "master did not send report") - - # Now try it with tags enabled - assert_nothing_raised do - master.apply("tags") - end - check.call :yes => %w{evaluate cleanup tags addtimes}, :no => %w{ignoreschedules} - assert_equal(2, master.reported, "master did not send report") - - # and ignoreschedules - assert_nothing_raised do - master.apply("tags", true) - end - check.call :yes => %w{evaluate cleanup tags ignoreschedules addtimes}, :no => %w{} - assert_equal(3, master.reported, "master did not send report") - end - def test_getconfig client = mkclient @@ -167,9 +122,8 @@ class TestMasterClient < Test::Unit::TestCase [:getplugins, :get_actual_config].each do |method| assert($methodsrun.include?(method), "method %s was not run" % method) end - - objects = client.objects - assert(objects.finalized?, "objects were not finalized") + + assert_instance_of(Puppet::Node::Configuration, client.configuration, "Configuration was not created") end def test_disable @@ -233,7 +187,7 @@ class TestMasterClient < Test::Unit::TestCase } end - # This method is supposed + # This method downloads files, and yields each file object if a block is given. def test_download source = tempfile() dest = tempfile() @@ -726,7 +680,7 @@ end client.apply # Make sure the config is not cached. - config = Puppet.config[:localconfig] + ".yaml" + config = Puppet.settings[:localconfig] + ".yaml" assert(! File.exists?(config), "Cached an invalid configuration") end end diff --git a/test/network/handler/configuration.rb b/test/network/handler/configuration.rb index 072fdc053..29a393769 100755 --- a/test/network/handler/configuration.rb +++ b/test/network/handler/configuration.rb @@ -20,19 +20,6 @@ class TestHandlerConfiguration < Test::Unit::TestCase assert(config.local?, "Config is not considered local after being started that way") end - # Make sure we create the node handler when necessary. - def test_node_handler - config = Config.new - handler = nil - assert_nothing_raised("Could not create node handler") do - handler = config.send(:node_handler) - end - assert_instance_of(Puppet::Network::Handler.handler(:node), handler, "Did not create node handler") - - # Now make sure we get the same object back again - assert_equal(handler.object_id, config.send(:node_handler).object_id, "Did not cache node handler") - end - # Test creation/returning of the interpreter def test_interpreter config = Config.new @@ -76,14 +63,14 @@ class TestHandlerConfiguration < Test::Unit::TestCase fakenode = Object.new # Set the server facts to something config.instance_variable_set("@server_facts", :facts) - fakenode.expects(:fact_merge).with(:facts) + fakenode.expects(:merge).with(:facts) config.send(:add_node_data, fakenode) # Now try it with classes. config.instance_variable_set("@options", {:Classes => %w{a b}}) list = [] fakenode = Object.new - fakenode.expects(:fact_merge).with(:facts) + fakenode.expects(:merge).with(:facts) fakenode.expects(:classes).returns(list).times(2) config.send(:add_node_data, fakenode) assert_equal(%w{a b}, list, "Did not add classes to node") @@ -170,19 +157,14 @@ class TestHandlerConfiguration < Test::Unit::TestCase def test_version # First try the case where we can't look up the node config = Config.new - handler = Object.new - handler.expects(:details).with(:client).returns(false) - config.expects(:node_handler).returns(handler) + node = Object.new + Puppet::Node.stubs(:search).with(:client).returns(false, node) interp = Object.new assert_instance_of(Bignum, config.version(:client), "Did not return configuration version") # And then when we find the node. config = Config.new - node = Object.new - handler = Object.new - handler.expects(:details).with(:client).returns(node) config.expects(:update_node_check).with(node) - config.expects(:node_handler).returns(handler) interp = Object.new interp.expects(:configuration_version).returns(:version) config.expects(:interpreter).returns(interp) diff --git a/test/network/handler/facts.rb b/test/network/handler/facts.rb deleted file mode 100755 index 03327b8c4..000000000 --- a/test/network/handler/facts.rb +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env ruby - -$:.unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'puppettest' -require 'mocha' -require 'puppet/network/handler/facts' - -class TestFactsHandler < Test::Unit::TestCase - include PuppetTest::ServerTest - - def setup - super - - @class = Puppet::Network::Handler.handler(:facts) - - @@client_facts = {} - - unless Puppet::Util::FactStore.store(:testing) - Puppet::Util::FactStore.newstore(:testing) do - def get(node) - @@client_facts[node] - end - - def set(node, facts) - @@client_facts[node] = facts - end - end - end - - Puppet[:factstore] = :testing - - @handler = @class.new - - @facts = {:a => :b, :c => :d} - @name = "foo" - - @backend = @handler.instance_variable_get("@backend") - end - - def teardown - @@client_facts.clear - end - - def test_strip_internal - @facts[:_puppet_one] = "yay" - @facts[:_puppet_two] = "boo" - @facts[:_puppetthree] = "foo" - - newfacts = nil - assert_nothing_raised("Could not call strip_internal") do - newfacts = @handler.send(:strip_internal, @facts) - end - - [:_puppet_one, :_puppet_two, :_puppetthree].each do |name| - assert(@facts.include?(name), "%s was removed in strip_internal from original hash" % name) - end - [:_puppet_one, :_puppet_two].each do |name| - assert(! newfacts.include?(name), "%s was not removed in strip_internal" % name) - end - assert_equal("foo", newfacts[:_puppetthree], "_puppetthree was removed in strip_internal") - end - - def test_add_internal - newfacts = nil - assert_nothing_raised("Could not call strip_internal") do - newfacts = @handler.send(:add_internal, @facts) - end - - assert_instance_of(Time, newfacts[:_puppet_timestamp], "Did not set timestamp in add_internal") - assert(! @facts.include?(:_puppet_timestamp), "Modified original hash in add_internal") - end - - def test_set - newfacts = @facts.dup - newfacts[:_puppet_timestamp] = Time.now - @handler.expects(:add_internal).with(@facts).returns(newfacts) - @backend.expects(:set).with(@name, newfacts).returns(nil) - - assert_nothing_raised("Could not set facts") do - assert_nil(@handler.set(@name, @facts), "handler.set did not return nil") - end - end - - def test_get - prefacts = @facts.dup - prefacts[:_puppet_timestamp] = Time.now - @@client_facts[@name] = prefacts - @handler.expects(:strip_internal).with(prefacts).returns(@facts) - @backend.expects(:get).with(@name).returns(prefacts) - - assert_nothing_raised("Could not retrieve facts") do - assert_equal(@facts, @handler.get(@name), "did not get correct answer from handler.get") - end - - @handler = @class.new - assert_nothing_raised("Failed to call 'get' with no stored facts") do - @handler.get("nosuchname") - end - end - - def test_store_date - time = Time.now - @facts[:_puppet_timestamp] = time - - @handler.expects(:get).with(@name).returns(@facts) - - assert_equal(time.to_i, @handler.store_date(@name), "Did not retrieve timestamp correctly") - end -end - -# $Id$ diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index a976726ef..4f8e7fab2 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -8,6 +8,11 @@ require 'puppet/network/handler/master' class TestMaster < Test::Unit::TestCase include PuppetTest::ServerTest + def teardown + super + Puppet::Indirector::Indirection.clear_cache + end + def test_defaultmanifest textfiles { |file| Puppet[:manifest] = file @@ -70,10 +75,11 @@ class TestMaster < Test::Unit::TestCase assert(! client.fresh?(facts), "Client is incorrectly up to date") - Puppet.config.use(:main) + Puppet.settings.use(:main) + config = nil assert_nothing_raised { - client.getconfig - client.apply + config = client.getconfig + config.apply } # Now it should be up to date @@ -108,8 +114,8 @@ class TestMaster < Test::Unit::TestCase # Retrieve and apply the new config assert_nothing_raised { - client.getconfig - client.apply + config = client.getconfig + config.apply } assert(client.fresh?(facts), "Client is not up to date") diff --git a/test/network/handler/node.rb b/test/network/handler/node.rb deleted file mode 100755 index 6b8ab9290..000000000 --- a/test/network/handler/node.rb +++ /dev/null @@ -1,640 +0,0 @@ -#!/usr/bin/env ruby - -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'mocha' -require 'puppettest' -require 'puppettest/resourcetesting' -require 'puppettest/parsertesting' -require 'puppettest/servertest' -require 'puppet/network/handler/node' - -module NodeTesting - include PuppetTest - Node = Puppet::Network::Handler::Node - SimpleNode = Puppet::Node - - def mk_node_mapper - # First, make sure our nodesearch command works as we expect - # Make a nodemapper - mapper = tempfile() - ruby = %x{which ruby}.chomp - File.open(mapper, "w") { |f| - f.puts "#!#{ruby} - require 'yaml' - name = ARGV.last.chomp - result = {} - - if name =~ /a/ - result[:parameters] = {'one' => ARGV.last + '1', 'two' => ARGV.last + '2'} - end - - if name =~ /p/ - result['classes'] = [1,2,3].collect { |n| ARGV.last + n.to_s } - end - - puts YAML.dump(result) - " - } - File.chmod(0755, mapper) - mapper - end - - def mk_searcher(name) - searcher = Object.new - searcher.extend(Node.node_source(name)) - searcher.meta_def(:newnode) do |name, *args| - SimpleNode.new(name, *args) - end - searcher - end - - def mk_node_source - @node_info = {} - @node_source = Node.newnode_source(:testing, :fact_merge => true) do - def nodesearch(key) - if info = @node_info[key] - SimpleNode.new(info) - else - nil - end - end - end - Puppet[:node_source] = "testing" - - cleanup { Node.rm_node_source(:testing) } - end -end - -class TestNodeHandler < Test::Unit::TestCase - include NodeTesting - - def setup - super - mk_node_source - end - - # Make sure that the handler includes the appropriate - # node source. - def test_initialize - # First try it when passing in the node source - handler = nil - assert_nothing_raised("Could not specify a node source") do - handler = Node.new(:Source => :testing) - end - assert(handler.metaclass.included_modules.include?(@node_source), "Handler did not include node source") - - # Now use the Puppet[:node_source] - Puppet[:node_source] = "testing" - assert_nothing_raised("Could not specify a node source") do - handler = Node.new() - end - assert(handler.metaclass.included_modules.include?(@node_source), "Handler did not include node source") - - # And make sure we throw an exception when an invalid node source is used - assert_raise(ArgumentError, "Accepted an invalid node source") do - handler = Node.new(:Source => "invalid") - end - end - - # Make sure we can find and we cache a fact handler. - def test_fact_handler - handler = Node.new - fhandler = nil - assert_nothing_raised("Could not retrieve the fact handler") do - fhandler = handler.send(:fact_handler) - end - assert_instance_of(Puppet::Network::Handler::Facts, fhandler, "Did not get a fact handler back") - - # Now call it again, making sure we're caching the value. - fhandler2 = nil - assert_nothing_raised("Could not retrieve the fact handler") do - fhandler2 = handler.send(:fact_handler) - end - assert_instance_of(Puppet::Network::Handler::Facts, fhandler2, "Did not get a fact handler on the second run") - assert_equal(fhandler.object_id, fhandler2.object_id, "Did not cache fact handler") - end - - # Make sure we can get node facts from the fact handler. - def test_node_facts - # Check the case where we find the node. - handler = Node.new - fhandler = handler.send(:fact_handler) - fhandler.expects(:get).with("present").returns("a" => "b") - - result = nil - assert_nothing_raised("Could not get facts from fact handler") do - result = handler.send(:node_facts, "present") - end - assert_equal({"a" => "b"}, result, "Did not get correct facts back") - - # Now try the case where the fact handler knows nothing about our host - fhandler.expects(:get).with('missing').returns(nil) - result = nil - assert_nothing_raised("Could not get facts from fact handler when host is missing") do - result = handler.send(:node_facts, "missing") - end - assert_equal({}, result, "Did not get empty hash when no facts are known") - end - - # Test our simple shorthand - def test_newnode - SimpleNode.expects(:new).with("stuff") - handler = Node.new - handler.send(:newnode, "stuff") - end - - # Make sure we can build up the correct node names to search for - def test_node_names - handler = Node.new - - # Verify that the handler asks for the facts if we don't pass them in - handler.expects(:node_facts).with("testing").returns({}) - handler.send(:node_names, "testing") - - handler = Node.new - # Test it first with no parameters - assert_equal(%w{testing}, handler.send(:node_names, "testing"), "Node names did not default to an array including just the node name") - - # Now test it with a fully qualified name - assert_equal(%w{testing.domain.com testing}, handler.send(:node_names, "testing.domain.com"), - "Fully qualified names did not get turned into multiple names, longest first") - - # And try it with a short name + domain fact - assert_equal(%w{testing host.domain.com host}, handler.send(:node_names, "testing", "domain" => "domain.com", "hostname" => "host"), - "The domain fact was not used to build up an fqdn") - - # And with an fqdn - assert_equal(%w{testing host.domain.com host}, handler.send(:node_names, "testing", "fqdn" => "host.domain.com"), - "The fqdn was not used") - - # And make sure the fqdn beats the domain - assert_equal(%w{testing host.other.com host}, handler.send(:node_names, "testing", "domain" => "domain.com", "fqdn" => "host.other.com"), - "The domain was used in preference to the fqdn") - end - - # Make sure we can retrieve a whole node by name. - def test_details_when_we_find_nodes - handler = Node.new - - # Make sure we get the facts first - handler.expects(:node_facts).with("host").returns(:facts) - - # Find the node names - handler.expects(:node_names).with("host", :facts).returns(%w{a b c}) - - # Iterate across them - handler.expects(:nodesearch).with("a").returns(nil) - handler.expects(:nodesearch).with("b").returns(nil) - - # Create an example node to return - node = SimpleNode.new("host") - - # Make sure its source is set - node.expects(:source=).with(handler.source) - - # And that the names are retained - node.expects(:names=).with(%w{a b c}) - - # And make sure we actually get it back - handler.expects(:nodesearch).with("c").returns(node) - - handler.expects(:fact_merge?).returns(true) - - # Make sure we merge the facts with the node's parameters. - node.expects(:fact_merge).with(:facts) - - # Now call the method - result = nil - assert_nothing_raised("could not call 'details'") do - result = handler.details("host") - end - assert_equal(node, result, "Did not get correct node back") - end - - # But make sure we pass through to creating default nodes when appropriate. - def test_details_using_default_node - handler = Node.new - - # Make sure we get the facts first - handler.expects(:node_facts).with("host").returns(:facts) - - # Find the node names - handler.expects(:node_names).with("host", :facts).returns([]) - - # Create an example node to return - node = SimpleNode.new("host") - - # Make sure its source is set - node.expects(:source=).with(handler.source) - - # And make sure we actually get it back - handler.expects(:nodesearch).with("default").returns(node) - - # This time, have it return false - handler.expects(:fact_merge?).returns(false) - - # And because fact_merge was false, we don't merge them. - node.expects(:fact_merge).never - - # Now call the method - result = nil - assert_nothing_raised("could not call 'details'") do - result = handler.details("host") - end - assert_equal(node, result, "Did not get correct node back") - end - - # Make sure our handler behaves rationally when it comes to getting environment data. - def test_environment - # What happens when we can't find the node - handler = Node.new - handler.expects(:details).with("fake").returns(nil) - - result = nil - assert_nothing_raised("Could not call 'Node.environment'") do - result = handler.environment("fake") - end - assert_nil(result, "Got an environment for a node we could not find") - - # Now for nodes we can find - handler = Node.new - node = SimpleNode.new("fake") - handler.expects(:details).with("fake").returns(node) - node.expects(:environment).returns("dev") - - result = nil - assert_nothing_raised("Could not call 'Node.environment'") do - result = handler.environment("fake") - end - assert_equal("dev", result, "Did not get environment back") - end - - # Make sure our handler behaves rationally when it comes to getting parameter data. - def test_parameters - # What happens when we can't find the node - handler = Node.new - handler.expects(:details).with("fake").returns(nil) - - result = nil - assert_nothing_raised("Could not call 'Node.parameters'") do - result = handler.parameters("fake") - end - assert_nil(result, "Got parameters for a node we could not find") - - # Now for nodes we can find - handler = Node.new - node = SimpleNode.new("fake") - handler.expects(:details).with("fake").returns(node) - node.expects(:parameters).returns({"a" => "b"}) - - result = nil - assert_nothing_raised("Could not call 'Node.parameters'") do - result = handler.parameters("fake") - end - assert_equal({"a" => "b"}, result, "Did not get parameters back") - end - - def test_classes - # What happens when we can't find the node - handler = Node.new - handler.expects(:details).with("fake").returns(nil) - - result = nil - assert_nothing_raised("Could not call 'Node.classes'") do - result = handler.classes("fake") - end - assert_nil(result, "Got classes for a node we could not find") - - # Now for nodes we can find - handler = Node.new - node = SimpleNode.new("fake") - handler.expects(:details).with("fake").returns(node) - node.expects(:classes).returns(%w{yay foo}) - - result = nil - assert_nothing_raised("Could not call 'Node.classes'") do - result = handler.classes("fake") - end - assert_equal(%w{yay foo}, result, "Did not get classes back") - end - - # We reuse the filetimeout for the node caching timeout. - def test_node_caching - handler = Node.new - - node = Object.new - node.metaclass.instance_eval do - attr_accessor :time, :name - end - node.time = Time.now - node.name = "yay" - - # Make sure caching works normally - assert_nothing_raised("Could not cache node") do - handler.send(:cache, node) - end - assert_equal(node.object_id, handler.send(:cached?, "yay").object_id, "Did not get node back from the cache") - - # And that it's returned if we ask for it, instead of creating a new node. - assert_equal(node.object_id, handler.details("yay").object_id, "Did not use cached node") - - # Now set the node's time to be a long time ago - node.time = Time.now - 50000 - assert(! handler.send(:cached?, "yay"), "Timed-out node was returned from cache") - end -end - -# Test our configuration object. -class TestNodeSources < Test::Unit::TestCase - include NodeTesting - - def test_node_sources - mod = nil - assert_nothing_raised("Could not add new search type") do - mod = Node.newnode_source(:testing) do - def nodesearch(name) - end - end - end - assert_equal(mod, Node.node_source(:testing), "Did not get node_source back") - - cleanup do - Node.rm_node_source(:testing) - assert(! Node.const_defined?("Testing"), "Did not remove constant") - end - end - - def test_external_node_source - source = Node.node_source(:external) - assert(source, "Could not find external node source") - mapper = mk_node_mapper - searcher = mk_searcher(:external) - assert(searcher.fact_merge?, "External node source does not merge facts") - - # Make sure it gives the right response - assert_equal({'classes' => %w{apple1 apple2 apple3}, :parameters => {"one" => "apple1", "two" => "apple2"}}, - YAML.load(%x{#{mapper} apple})) - - # First make sure we get nil back by default - assert_nothing_raised { - assert_nil(searcher.nodesearch("apple"), - "Interp#nodesearch_external defaulted to a non-nil response") - } - assert_nothing_raised { Puppet[:external_nodes] = mapper } - - node = nil - # Both 'a' and 'p', so we get classes and parameters - assert_nothing_raised { node = searcher.nodesearch("apple") } - assert_equal("apple", node.name, "node name was not set correctly for apple") - assert_equal(%w{apple1 apple2 apple3}, node.classes, "node classes were not set correctly for apple") - assert_equal( {"one" => "apple1", "two" => "apple2"}, node.parameters, "node parameters were not set correctly for apple") - - # A 'p' but no 'a', so we only get classes - assert_nothing_raised { node = searcher.nodesearch("plum") } - assert_equal("plum", node.name, "node name was not set correctly for plum") - assert_equal(%w{plum1 plum2 plum3}, node.classes, "node classes were not set correctly for plum") - assert_equal({}, node.parameters, "node parameters were not set correctly for plum") - - # An 'a' but no 'p', so we only get parameters. - assert_nothing_raised { node = searcher.nodesearch("guava")} # no p's, thus no classes - assert_equal("guava", node.name, "node name was not set correctly for guava") - assert_equal([], node.classes, "node classes were not set correctly for guava") - assert_equal({"one" => "guava1", "two" => "guava2"}, node.parameters, "node parameters were not set correctly for guava") - - assert_nothing_raised { node = searcher.nodesearch("honeydew")} # neither, thus nil - assert_nil(node) - end - - # Make sure a nodesearch with arguments works - def test_nodesearch_external_arguments - mapper = mk_node_mapper - Puppet[:external_nodes] = "#{mapper} -s something -p somethingelse" - searcher = mk_searcher(:external) - node = nil - assert_nothing_raised do - node = searcher.nodesearch("apple") - end - assert_instance_of(SimpleNode, node, "did not create node") - end - - # A wrapper test, to make sure we're correctly calling the external search method. - def test_nodesearch_external_functional - mapper = mk_node_mapper - searcher = mk_searcher(:external) - - Puppet[:external_nodes] = mapper - - node = nil - assert_nothing_raised do - node = searcher.nodesearch("apple") - end - assert_instance_of(SimpleNode, node, "did not create node") - end - - # This can stay in the main test suite because it doesn't actually use ldapsearch, - # it just overrides the method so it behaves as though it were hitting ldap. - def test_ldap_nodesearch - source = Node.node_source(:ldap) - assert(source, "Could not find ldap node source") - searcher = mk_searcher(:ldap) - assert(searcher.fact_merge?, "LDAP node source does not merge facts") - - nodetable = {} - - # Override the ldapsearch definition, so we don't have to actually set it up. - searcher.meta_def(:ldapsearch) do |name| - nodetable[name] - end - - # Make sure we get nothing for nonexistent hosts - node = nil - assert_nothing_raised do - node = searcher.nodesearch("nosuchhost") - end - - assert_nil(node, "Got a node for a non-existent host") - - # Now add a base node with some classes and parameters - nodetable["base"] = [nil, %w{one two}, {"base" => "true"}] - - assert_nothing_raised do - node = searcher.nodesearch("base") - end - - assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch") - assert_equal("base", node.name, "node name was not set") - - assert_equal(%w{one two}, node.classes, "node classes were not set") - assert_equal({"base" => "true"}, node.parameters, "node parameters were not set") - - # Now use a different with this as the base - nodetable["middle"] = ["base", %w{three}, {"center" => "boo"}] - assert_nothing_raised do - node = searcher.nodesearch("middle") - end - - assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch") - assert_equal("middle", node.name, "node name was not set") - - assert_equal(%w{one two three}.sort, node.classes.sort, "node classes were not set correctly with a parent node") - assert_equal({"base" => "true", "center" => "boo"}, node.parameters, "node parameters were not set correctly with a parent node") - - # And one further, to make sure we fully recurse - nodetable["top"] = ["middle", %w{four five}, {"master" => "far"}] - assert_nothing_raised do - node = searcher.nodesearch("top") - end - - assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch") - assert_equal("top", node.name, "node name was not set") - - assert_equal(%w{one two three four five}.sort, node.classes.sort, "node classes were not set correctly with the top node") - assert_equal({"base" => "true", "center" => "boo", "master" => "far"}, node.parameters, "node parameters were not set correctly with the top node") - end - - # Make sure we always get a node back from the 'none' nodesource. - def test_nodesource_none - source = Node.node_source(:none) - assert(source, "Could not find 'none' node source") - searcher = mk_searcher(:none) - assert(searcher.fact_merge?, "'none' node source does not merge facts") - - # Run a couple of node names through it - node = nil - %w{192.168.0.1 0:0:0:3:a:f host host.domain.com}.each do |name| - assert_nothing_raised("Could not create an empty node with name '%s'" % name) do - node = searcher.nodesearch(name) - end - assert_instance_of(SimpleNode, node, "Did not get a simple node back for %s" % name) - assert_equal(name, node.name, "Name was not set correctly") - end - end -end - -class LdapNodeTest < PuppetTest::TestCase - include NodeTesting - include PuppetTest::ServerTest - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - AST = Puppet::Parser::AST - confine "LDAP is not available" => Puppet.features.ldap? - confine "No LDAP test data for networks other than Luke's" => Facter.value(:domain) == "madstop.com" - - def ldapconnect - - @ldap = LDAP::Conn.new("ldap", 389) - @ldap.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ) - @ldap.simple_bind("", "") - - return @ldap - end - - def ldaphost(name) - node = Puppet::Node.new(name) - parent = nil - found = false - @ldap.search( "ou=hosts, dc=madstop, dc=com", 2, - "(&(objectclass=puppetclient)(cn=%s))" % name - ) do |entry| - node.classes = entry.vals("puppetclass") || [] - node.parameters = entry.to_hash.inject({}) do |hash, ary| - if ary[1].length == 1 - hash[ary[0]] = ary[1].shift - else - hash[ary[0]] = ary[1] - end - hash - end - parent = node.parameters["parentnode"] - found = true - end - raise "Could not find node %s" % name unless found - - return node, parent - end - - def test_ldapsearch - Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com" - Puppet[:ldapnodes] = true - - searcher = Object.new - searcher.extend(Node.node_source(:ldap)) - - ldapconnect() - - # Make sure we get nil and nil back when we search for something missing - parent, classes, parameters = nil - assert_nothing_raised do - parent, classes, parameters = searcher.ldapsearch("nosuchhost") - end - - assert_nil(parent, "Got a parent for a non-existent host") - assert_nil(classes, "Got classes for a non-existent host") - - # Make sure we can find 'culain' in ldap - assert_nothing_raised do - parent, classes, parameters = searcher.ldapsearch("culain") - end - - node, realparent = ldaphost("culain") - assert_equal(realparent, parent, "did not get correct parent node from ldap") - assert_equal(node.classes, classes, "did not get correct ldap classes from ldap") - assert_equal(node.parameters, parameters, "did not get correct ldap parameters from ldap") - - # Now compare when we specify the attributes to get. - Puppet[:ldapattrs] = "cn" - assert_nothing_raised do - parent, classes, parameters = searcher.ldapsearch("culain") - end - assert_equal(realparent, parent, "did not get correct parent node from ldap") - assert_equal(node.classes, classes, "did not get correct ldap classes from ldap") - - list = %w{cn puppetclass parentnode dn} - should = node.parameters.inject({}) { |h, a| h[a[0]] = a[1] if list.include?(a[0]); h } - assert_equal(should, parameters, "did not get correct ldap parameters from ldap") - end -end - -class LdapReconnectTests < PuppetTest::TestCase - include NodeTesting - include PuppetTest::ServerTest - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - AST = Puppet::Parser::AST - confine "Not running on culain as root" => (Puppet::Util::SUIDManager.uid == 0 and Facter.value("hostname") == "culain") - - def test_ldapreconnect - Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com" - Puppet[:ldapnodes] = true - - searcher = Object.new - searcher.extend(Node.node_source(:ldap)) - hostname = "culain.madstop.com" - - # look for our host - assert_nothing_raised { - parent, classes = searcher.nodesearch(hostname) - } - - # Now restart ldap - system("/etc/init.d/slapd restart 2>/dev/null >/dev/null") - sleep(1) - - # and look again - assert_nothing_raised { - parent, classes = searcher.nodesearch(hostname) - } - - # Now stop ldap - system("/etc/init.d/slapd stop 2>/dev/null >/dev/null") - cleanup do - system("/etc/init.d/slapd start 2>/dev/null >/dev/null") - end - - # And make sure we actually fail here - assert_raise(Puppet::Error) { - parent, classes = searcher.nodesearch(hostname) - } - end -end diff --git a/test/other/dsl.rb b/test/other/dsl.rb index f1fd1a1e9..59610cd0f 100755 --- a/test/other/dsl.rb +++ b/test/other/dsl.rb @@ -214,5 +214,3 @@ class TestDSL < Test::Unit::TestCase assert_instance_of(Puppet::Parser::Resource, file) end end - -# $Id$ diff --git a/test/other/events.rb b/test/other/events.rb index 802a701a3..b67ea05a1 100755 --- a/test/other/events.rb +++ b/test/other/events.rb @@ -23,7 +23,7 @@ class TestEvents < Test::Unit::TestCase :subscribe => [[file.class.name, file.name]] ) - comp = newcomp("eventtesting", file, exec) + comp = mk_configuration("eventtesting", file, exec) trans = assert_events([:file_created, :triggered], comp) @@ -44,56 +44,16 @@ class TestEvents < Test::Unit::TestCase ) - comp = Puppet.type(:component).create( - :name => "eventtesting" - ) - comp.push exec - trans = comp.evaluate - events = nil - assert_nothing_raised { - events = trans.evaluate - } + config = mk_configuration + config.add_resource file + config.add_resource exec + trans = config.apply - assert_equal(1, events.length) + assert_equal(1, trans.events.length) assert_equal(0, trans.triggered?(exec, :refresh)) end - # Verify that one component can subscribe to another component and the "right" - # thing happens - def test_ladderrequire - comps = {} - objects = {} - fname = tempfile() - file = Puppet.type(:file).create( - :name => tempfile(), - :ensure => "file" - ) - - exec = Puppet.type(:exec).create( - :name => "touch %s" % fname, - :path => "/usr/bin:/bin", - :refreshonly => true - ) - - fcomp = newcomp(file) - ecomp = newcomp(exec) - comp = newcomp("laddercomp", fcomp, ecomp) - - ecomp[:subscribe] = [[fcomp.class.name, fcomp.name]] - - comp.finalize - - trans = comp.evaluate - events = nil - assert_nothing_raised { - events = trans.evaluate - } - - assert(FileTest.exists?(fname), "#{fname} does not exist") - #assert_equal(events.length, trans.triggered?(objects[:b], :refresh)) - end - def test_multiplerefreshes files = [] @@ -115,7 +75,7 @@ class TestEvents < Test::Unit::TestCase ["file", f.name] } - comp = newcomp(exec, *files) + comp = mk_configuration(exec, *files) assert_apply(comp) assert(FileTest.exists?(fname), "Exec file did not get created") @@ -147,17 +107,16 @@ class TestEvents < Test::Unit::TestCase ) execs = [exec1, exec2, exec3] - comp = newcomp(exec1,exec2,exec3) + config = mk_configuration(exec1,exec2,exec3) - trans = comp.evaluate - execs.each do |e| assert(trans.resources.vertex?(e), "%s is not in graph" % e.title) end + trans = Puppet::Transaction.new(config) + execs.each do |e| assert(config.vertex?(e), "%s is not in graph" % e.title) end trans.prepare - execs.each do |e| assert(trans.relgraph.vertex?(e), "%s is not in relgraph" % e.title) end - reverse = trans.relgraph.reversal + execs.each do |e| assert(config.vertex?(e), "%s is not in relgraph" % e.title) end + reverse = trans.relationship_graph.reversal execs.each do |e| assert(reverse.vertex?(e), "%s is not in reversed graph" % e.title) end - - assert_apply(comp) + config.apply assert(FileTest.exists?(file), "File does not exist") diff --git a/test/other/overrides.rb b/test/other/overrides.rb index 2bc443980..9a7c4b8ba 100755 --- a/test/other/overrides.rb +++ b/test/other/overrides.rb @@ -90,12 +90,10 @@ class TestOverrides < Test::Unit::TestCase } } - comp = newcomp("overrides", baseobj) - children.each { |child| comp.push child } + config = mk_configuration(baseobj, *children) assert_nothing_raised("Could not eval component") { - trans = comp.evaluate - trans.evaluate + config.apply } files.each { |path, mode| diff --git a/test/other/pgraph.rb b/test/other/pgraph.rb deleted file mode 100755 index 34ba0e18c..000000000 --- a/test/other/pgraph.rb +++ /dev/null @@ -1,290 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke Kanies on 2006-11-16. -# Copyright (c) 2006. All rights reserved. - -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'puppettest' -require 'puppettest/graph' - -class TestPGraph < Test::Unit::TestCase - include PuppetTest - include PuppetTest::Graph - - Edge = Puppet::Relationship - - def test_clear - graph = Puppet::PGraph.new - graph.add_edge!("a", "b") - graph.add_vertex! "c" - assert_nothing_raised do - graph.clear - end - assert(graph.vertices.empty?, "Still have vertices after clear") - assert(graph.edges.empty?, "still have edges after clear") - end - - - def test_matching_edges - graph = Puppet::PGraph.new - - event = Puppet::Event.new(:source => "a", :event => :yay) - none = Puppet::Event.new(:source => "a", :event => :NONE) - - edges = {} - - edges["a/b"] = Edge["a", "b", {:event => :yay, :callback => :refresh}] - edges["a/c"] = Edge["a", "c", {:event => :yay, :callback => :refresh}] - - graph.add_edge!(edges["a/b"]) - - # Try it for the trivial case of one target and a matching event - assert_equal([edges["a/b"]], graph.matching_edges([event])) - - # Make sure we get nothing with a different event - assert_equal([], graph.matching_edges([none])) - - # Set up multiple targets and make sure we get them all back - graph.add_edge!(edges["a/c"]) - assert_equal([edges["a/b"], edges["a/c"]].sort, graph.matching_edges([event]).sort) - assert_equal([], graph.matching_edges([none])) - end - - def test_dependencies - graph = Puppet::PGraph.new - - graph.add_edge!("a", "b") - graph.add_edge!("a", "c") - graph.add_edge!("b", "d") - - assert_equal(%w{b c d}.sort, graph.dependents("a").sort) - assert_equal(%w{d}.sort, graph.dependents("b").sort) - assert_equal([].sort, graph.dependents("c").sort) - - assert_equal(%w{a b}, graph.dependencies("d").sort) - assert_equal(%w{a}, graph.dependencies("b").sort) - assert_equal(%w{a}, graph.dependencies("c").sort) - assert_equal([], graph.dependencies("a").sort) - - end - - # Test that we can take a containment graph and rearrange it by dependencies - def test_splice - one, two, three, middle, top = build_tree - empty = Container.new("empty", []) - # Also, add an empty container to top - top.push empty - - contgraph = top.to_graph - - # Now add a couple of child files, so that we can test whether all - # containers get spliced, rather than just components. - - # Now make a dependency graph - deps = Puppet::PGraph.new - - contgraph.vertices.each do |v| - deps.add_vertex(v) - end - - # We have to specify a relationship to our empty container, else it - # never makes it into the dep graph in the first place. - {one => two, "f" => "c", "h" => middle, "c" => empty}.each do |source, target| - deps.add_edge!(source, target, :callback => :refresh) - end - - #contgraph.to_jpg(File.expand_path("~/Desktop/pics"), "main") - #deps.to_jpg(File.expand_path("~/Desktop/pics"), "before") - assert_nothing_raised { deps.splice!(contgraph, Container) } - - assert(! deps.cyclic?, "Created a cyclic graph") - - # Make sure there are no container objects remaining - #deps.to_jpg(File.expand_path("~/Desktop/pics"), "after") - c = deps.vertices.find_all { |v| v.is_a?(Container) } - assert(c.empty?, "Still have containers %s" % c.inspect) - - # Now make sure the containers got spliced correctly. - contgraph.leaves(middle).each do |leaf| - assert(deps.edge?("h", leaf), "no edge for h => %s" % leaf) - end - one.each do |oobj| - two.each do |tobj| - assert(deps.edge?(oobj, tobj), "no %s => %s edge" % [oobj, tobj]) - end - end - - nons = deps.vertices.find_all { |v| ! v.is_a?(String) } - assert(nons.empty?, - "still contain non-strings %s" % nons.inspect) - - deps.edges.each do |edge| - assert_equal({:callback => :refresh}, edge.label, - "Label was not copied for %s => %s" % [edge.source, edge.target]) - end - - # Now add some relationships to three, but only add labels to one of - # the relationships. - - # Add a simple, label-less relationship - deps.add_edge!(two, three) - assert_nothing_raised { deps.splice!(contgraph, Container) } - - # And make sure it stuck, with no labels. - assert_equal({}, deps.edge_label("c", "i"), - "label was created for c => i") - - # Now add some edges with labels, in a way that should overwrite - deps.add_edge!("c", three, {:callback => :refresh}) - assert_nothing_raised { deps.splice!(contgraph, Container) } - - # And make sure the label got copied. - assert_equal({:callback => :refresh}, deps.edge_label("c", "i"), - "label was not copied for c => i") - - # Lastly, add some new label-less edges and make sure the label stays. - deps.add_edge!(middle, three) - assert_nothing_raised { deps.splice!(contgraph, Container) } - assert_equal({:callback => :refresh}, deps.edge_label("c", "i"), - "label was lost for c => i") - - # Now make sure the 'three' edges all have the label we've used. - # Note that this will not work when we support more than one type of - # subscription. - three.each do |child| - edge = deps.edge_class.new("c", child) - assert(deps.edge?(edge), "no c => %s edge" % child) - assert_equal({:callback => :refresh}, deps[edge], - "label was not retained for c => %s" % child) - end - end - - def test_copy_label - graph = Puppet::PGraph.new - - # First make an edge with no label - graph.add_edge!(:a, :b) - assert_nil(graph.edge_label(:a, :b), "Created a label") - - # Now try to copy an empty label in. - graph.copy_label(:a, :b, {}) - - # It should just do nothing, since we copied an empty label. - assert_nil(graph.edge_label(:a, :b), "Created a label") - - # Now copy in a real label. - graph.copy_label(:a, :b, {:callback => :yay}) - assert_equal({:callback => :yay}, - graph.edge_label(:a, :b), "Did not copy label") - - # Now copy in a nil label - graph.copy_label(:a, :b, nil) - assert_equal({:callback => :yay}, - graph.edge_label(:a, :b), "lost label") - - # And an empty one. - graph.copy_label(:a, :b, {}) - assert_equal({:callback => :yay}, - graph.edge_label(:a, :b), "lost label") - end - - def test_fail_on_cycle - { - {:a => :b, :b => :a, :c => :a, :d => :c} => true, # larger tree involving a smaller cycle - {:a => :b, :b => :c, :c => :a} => true, - {:a => :b, :b => :a, :c => :d, :d => :c} => true, - {:a => :b, :b => :c} => false, - }.each do |hash, result| - graph = Puppet::PGraph.new - hash.each do |a,b| - graph.add_edge!(a, b) - end - - if result - assert_raise(Puppet::Error, "%s did not fail" % hash.inspect) do - graph.topsort - end - else - assert_nothing_raised("%s failed" % hash.inspect) do - graph.topsort - end - end - end - end - - # This isn't really a unit test, it's just a way to do some graphing with - # tons of relationships so we can see how it performs. - def disabled_test_lots_of_relationships - containers = Puppet::PGraph.new - relationships = Puppet::PGraph.new - labels = %w{a b c d e} - conts = {} - vertices = {} - labels.each do |label| - vertices[label] = [] - end - num = 100 - num.times do |i| - labels.each do |label| - vertices[label] << ("%s%s" % [label, i]) - end - end - labels.each do |label| - conts[label] = Container.new(label, vertices[label]) - end - - conts.each do |label, cont| - cont.each do |child| - containers.add_edge!(cont, child) - end - end - prev = nil - labels.inject(nil) do |prev, label| - if prev - containers.add_edge!(conts[prev], conts[label]) - end - label - end - - containers.to_jpg(File.expand_path("~/Desktop/pics/lots"), "start") - - # Now create the relationship graph - - # Make everything in both b and c require d1 - %w{b c}.each do |label| - conts[label].each do |v| - relationships.add_edge!(v, "d1") - #relationships.add_edge!(v, conts["d"]) - end - end - - # Make most in b also require the appropriate thing in c - conts["b"].each do |v| - i = v.split('')[1] - - relationships.add_edge!(v, "c%s" % i) - end - - # And make d1 require most of e - num.times do |i| - relationships.add_edge!("d1", "e%s" % i) - end - - containers.vertices.each do |v| - relationships.add_vertex!(v) - end - relationships.to_jpg(File.expand_path("~/Desktop/pics/lots"), "relationships") - - time = Benchmark.realtime do - relationships.splice!(containers, Container) - end - relationships.to_jpg(File.expand_path("~/Desktop/pics/lots"), "final") - puts time - time = Benchmark.realtime do - relationships.topsort - end - end -end - -# $Id$ diff --git a/test/other/relationships.rb b/test/other/relationships.rb index a5c9db5dc..771b119ee 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -172,15 +172,12 @@ class TestRelationships < Test::Unit::TestCase end assert_equal([Puppet::Relationship[file, exec]], reqs) - # Now make sure that these relationships are added to the transaction's - # relgraph - trans = Puppet::Transaction.new(newcomp(file, exec)) - assert_nothing_raised do - trans.evaluate + # Now make sure that these relationships are added to the + # relationship graph + config = mk_configuration(file, exec) + config.apply do |trans| + assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created") end - - graph = trans.relgraph - assert(graph.edge?(file, exec), "autorequire edge was not created") end def test_requires? diff --git a/test/other/report.rb b/test/other/report.rb index c59881f72..3de2dfbee 100755 --- a/test/other/report.rb +++ b/test/other/report.rb @@ -26,16 +26,10 @@ class TestReports < Test::Unit::TestCase ) end - comp = newcomp(*objects) - - trans = nil - assert_nothing_raised("Failed to create transaction") { - trans = comp.evaluate - } - - assert_nothing_raised("Failed to evaluate transaction") { - trans.evaluate - } + config = mk_configuration(*objects) + # So the report works out. + config.retrieval_duration = 0.001 + trans = config.apply return trans.generate_report end @@ -92,7 +86,7 @@ class TestReports < Test::Unit::TestCase # We have to reuse reporting here because of something going on in the # server/report.rb file - Puppet.config.use(:reporting) + Puppet.settings.use(:reporting) 3.times { |i| log = Puppet.warning("Report test message %s" % i) @@ -119,7 +113,7 @@ class TestReports < Test::Unit::TestCase if Puppet.features.rrd? def test_rrdgraph_report - Puppet.config.use(:metrics) + Puppet.settings.use(:metrics) report = mkreport assert(! report.metrics.empty?, "Did not receive any metrics") diff --git a/test/other/transactions.rb b/test/other/transactions.rb index bf5f65084..7d17a92e7 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -7,8 +7,6 @@ require 'puppettest' require 'mocha' require 'puppettest/support/resources' -# $Id$ - class TestTransactions < Test::Unit::TestCase include PuppetTest::FileTesting include PuppetTest::Support::Resources @@ -133,7 +131,7 @@ class TestTransactions < Test::Unit::TestCase inst = type.create :name => "yay" # Create a transaction - trans = Puppet::Transaction.new(newcomp(inst)) + trans = Puppet::Transaction.new(mk_configuration(inst)) # Make sure prefetch works assert_nothing_raised do @@ -255,7 +253,7 @@ class TestTransactions < Test::Unit::TestCase } - component = newcomp("file",file) + component = mk_configuration("file",file) require 'etc' groupname = Etc.getgrgid(File.stat(file.name).gid).name assert_nothing_raised() { @@ -295,12 +293,11 @@ class TestTransactions < Test::Unit::TestCase file[:check] = check file[:group] = @groups[0] - assert_apply(file) + config = mk_configuration(file) + config.apply @@tmpfiles << execfile - component = newcomp("both",file,exec) - # 'subscribe' expects an array of arrays exec[:subscribe] = [[file.class.name,file.name]] exec[:refreshonly] = true @@ -317,7 +314,11 @@ class TestTransactions < Test::Unit::TestCase file[:mode] = "755" } - trans = assert_events([:file_changed, :triggered], component) + # Make a new configuration so the resource relationships get + # set up. + config = mk_configuration(file, exec) + + trans = assert_events([:file_changed, :triggered], config) assert(FileTest.exists?(execfile), "Execfile does not exist") File.unlink(execfile) @@ -325,7 +326,7 @@ class TestTransactions < Test::Unit::TestCase file[:group] = @groups[1] } - trans = assert_events([:file_changed, :triggered], component) + trans = assert_events([:file_changed, :triggered], config) assert(FileTest.exists?(execfile), "Execfile does not exist") end @@ -343,24 +344,30 @@ class TestTransactions < Test::Unit::TestCase file[:group] = @groups[0] assert_apply(file) - fcomp = newcomp("file",file) - ecomp = newcomp("exec",exec) + config = Puppet::Node::Configuration.new + fcomp = Puppet::Type.type(:component).create(:name => "file") + config.add_resource fcomp + config.add_resource file + config.add_edge!(fcomp, file) - component = newcomp("both",fcomp,ecomp) + ecomp = Puppet::Type.type(:component).create(:name => "exec") + config.add_resource ecomp + config.add_resource exec + config.add_edge!(ecomp, exec) # 'subscribe' expects an array of arrays #component[:require] = [[file.class.name,file.name]] ecomp[:subscribe] = fcomp exec[:refreshonly] = true - trans = assert_events([], component) + trans = assert_events([], config) assert_nothing_raised() { file[:group] = @groups[1] file[:mode] = "755" } - trans = assert_events([:file_changed, :file_changed, :triggered], component) + trans = assert_events([:file_changed, :file_changed, :triggered], config) end # Make sure that multiple subscriptions get triggered. @@ -426,7 +433,8 @@ class TestTransactions < Test::Unit::TestCase Puppet[:ignoreschedules] = false file = Puppet.type(:file).create( :name => tempfile(), - :ensure => "file" + :ensure => "file", + :backup => false ) fname = tempfile() @@ -437,11 +445,10 @@ class TestTransactions < Test::Unit::TestCase :subscribe => ["file", file.name] ) - comp = newcomp(file,exec) - comp.finalize + config = mk_configuration(file, exec) # Run it once - assert_apply(comp) + assert_apply(config) assert(FileTest.exists?(fname), "File did not get created") assert(!exec.scheduled?, "Exec is somehow scheduled") @@ -451,7 +458,8 @@ class TestTransactions < Test::Unit::TestCase file[:content] = "some content" - assert_events([:file_changed, :triggered], comp) + assert_events([:file_changed, :triggered], config) + assert(FileTest.exists?(fname), "File did not get recreated") # Now remove it, so it can get created again @@ -469,7 +477,7 @@ class TestTransactions < Test::Unit::TestCase assert(! file.insync?(file.retrieve), "Uh, file is in sync?") - assert_events([:file_changed, :triggered], comp) + assert_events([:file_changed, :triggered], config) assert(FileTest.exists?(fname), "File did not get recreated") end @@ -493,11 +501,9 @@ class TestTransactions < Test::Unit::TestCase :ensure => :file ) - comp = newcomp(exec, file1, file2) - - comp.finalize + config = mk_configuration(exec, file1, file2) - assert_apply(comp) + assert_apply(config) assert(! FileTest.exists?(file1[:path]), "File got created even tho its dependency failed") @@ -506,31 +512,27 @@ class TestTransactions < Test::Unit::TestCase end end - def f(n) - Puppet::Type.type(:file)["/tmp/#{n.to_s}"] - end - def test_relationship_graph - one, two, middle, top = mktree + config = mktree + + config.meta_def(:f) do |name| + self.resource("File[%s]" % name) + end - {one => two, "f" => "c", "h" => middle}.each do |source, target| - if source.is_a?(String) - source = f(source) - end - if target.is_a?(String) - target = f(target) - end + {"one" => "two", "File[f]" => "File[c]", "File[h]" => "middle"}.each do |source_ref, target_ref| + source = config.resource(source_ref) or raise "Missing %s" % source_ref + target = config.resource(target_ref) or raise "Missing %s" % target_ref target[:require] = source end - trans = Puppet::Transaction.new(top) + trans = Puppet::Transaction.new(config) graph = nil assert_nothing_raised do graph = trans.relationship_graph end - - assert_instance_of(Puppet::PGraph, graph, + + assert_instance_of(Puppet::Node::Configuration, graph, "Did not get relationship graph") # Make sure all of the components are gone @@ -544,13 +546,13 @@ class TestTransactions < Test::Unit::TestCase sorted = graph.topsort.reverse # Now make sure the appropriate edges are there and are in the right order - assert(graph.dependents(f(:f)).include?(f(:c)), + assert(graph.dependents(config.f(:f)).include?(config.f(:c)), "c not marked a dep of f") - assert(sorted.index(f(:c)) < sorted.index(f(:f)), + assert(sorted.index(config.f(:c)) < sorted.index(config.f(:f)), "c is not before f") - one.each do |o| - two.each do |t| + config.resource("one").each do |o| + config.resource("two").each do |t| assert(graph.dependents(o).include?(t), "%s not marked a dep of %s" % [t.ref, o.ref]) assert(sorted.index(t) < sorted.index(o), @@ -558,22 +560,22 @@ class TestTransactions < Test::Unit::TestCase end end - trans.resources.leaves(middle).each do |child| - assert(graph.dependents(f(:h)).include?(child), + trans.configuration.leaves(config.resource("middle")).each do |child| + assert(graph.dependents(config.f(:h)).include?(child), "%s not marked a dep of h" % [child.ref]) - assert(sorted.index(child) < sorted.index(f(:h)), + assert(sorted.index(child) < sorted.index(config.f(:h)), "%s is not before h" % child.ref) end # Lastly, make sure our 'g' vertex made it into the relationship # graph, since it's not involved in any relationships. - assert(graph.vertex?(f(:g)), + assert(graph.vertex?(config.f(:g)), "Lost vertexes with no relations") # Now make the reversal graph and make sure all of the vertices made it into that reverse = graph.reversal %w{a b c d e f g h}.each do |letter| - file = f(letter) + file = config.f(letter) assert(reverse.vertex?(file), "%s did not make it into reversal" % letter) end end @@ -594,15 +596,15 @@ class TestTransactions < Test::Unit::TestCase yay = Puppet::Type.newgenerator :title => "yay" rah = Puppet::Type.newgenerator :title => "rah" - comp = newcomp(yay, rah) - trans = comp.evaluate + config = mk_configuration(yay, rah) + trans = Puppet::Transaction.new(config) assert_nothing_raised do trans.generate end %w{ya ra y r}.each do |name| - assert(trans.resources.vertex?(Puppet::Type.type(:generator)[name]), + assert(trans.configuration.vertex?(Puppet::Type.type(:generator)[name]), "Generated %s was not a vertex" % name) assert($finished.include?(name), "%s was not finished" % name) end @@ -613,7 +615,7 @@ class TestTransactions < Test::Unit::TestCase end %w{ya ra y r}.each do |name| - assert(!trans.resources.vertex?(Puppet::Type.type(:generator)[name]), + assert(!trans.configuration.vertex?(Puppet::Type.type(:generator)[name]), "Generated vertex %s was not removed from graph" % name) assert_nil(Puppet::Type.type(:generator)[name], "Generated vertex %s was not removed from class" % name) @@ -633,8 +635,8 @@ class TestTransactions < Test::Unit::TestCase yay = Puppet::Type.newgenerator :title => "yay" rah = Puppet::Type.newgenerator :title => "rah", :subscribe => yay - comp = newcomp(yay, rah) - trans = comp.evaluate + config = mk_configuration(yay, rah) + trans = Puppet::Transaction.new(config) trans.prepare @@ -645,13 +647,13 @@ class TestTransactions < Test::Unit::TestCase end ya = type["ya"] assert(ya, "Did not generate ya") - assert(trans.relgraph.vertex?(ya), + assert(trans.relationship_graph.vertex?(ya), "Did not add ya to rel_graph") # Now make sure the appropriate relationships were added - assert(trans.relgraph.edge?(yay, ya), + assert(trans.relationship_graph.edge?(yay, ya), "parent was not required by child") - assert(! trans.relgraph.edge?(ya, rah), + assert(! trans.relationship_graph.edge?(ya, rah), "generated child ya inherited depencency on rah") # Now make sure it in turn eval_generates appropriately @@ -662,7 +664,7 @@ class TestTransactions < Test::Unit::TestCase %w{y}.each do |name| res = type[name] assert(res, "Did not generate %s" % name) - assert(trans.relgraph.vertex?(res), + assert(trans.relationship_graph.vertex?(res), "Did not add %s to rel_graph" % name) assert($finished.include?("y"), "y was not finished") end @@ -670,7 +672,7 @@ class TestTransactions < Test::Unit::TestCase assert_nothing_raised("failed to eval_generate with nil response") do trans.eval_resource(type["y"]) end - assert(trans.relgraph.edge?(yay, ya), "no edge was created for ya => yay") + assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay") assert_nothing_raised("failed to apply rah") do trans.eval_resource(rah) @@ -678,15 +680,15 @@ class TestTransactions < Test::Unit::TestCase ra = type["ra"] assert(ra, "Did not generate ra") - assert(trans.relgraph.vertex?(ra), + assert(trans.relationship_graph.vertex?(ra), "Did not add ra to rel_graph" % name) assert($finished.include?("ra"), "y was not finished") # Now make sure this generated resource has the same relationships as # the generating resource - assert(! trans.relgraph.edge?(yay, ra), + assert(! trans.relationship_graph.edge?(yay, ra), "rah passed its dependencies on to its children") - assert(! trans.relgraph.edge?(ya, ra), + assert(! trans.relationship_graph.edge?(ya, ra), "children have a direct relationship") # Now make sure that cleanup gets rid of those generated types. @@ -695,14 +697,14 @@ class TestTransactions < Test::Unit::TestCase end %w{ya ra y r}.each do |name| - assert(!trans.relgraph.vertex?(type[name]), + assert(!trans.relationship_graph.vertex?(type[name]), "Generated vertex %s was not removed from graph" % name) assert_nil(type[name], "Generated vertex %s was not removed from class" % name) end # Now, start over and make sure that everything gets evaluated. - trans = comp.evaluate + trans = Puppet::Transaction.new(config) $evaluated.clear assert_nothing_raised do trans.evaluate @@ -711,54 +713,41 @@ class TestTransactions < Test::Unit::TestCase assert_equal(%w{yay ya y rah ra r}, $evaluated, "Not all resources were evaluated or not in the right order") end - - def test_tags - res = Puppet::Type.newfile :path => tempfile() - comp = newcomp(res) - - # Make sure they default to none - assert_equal([], comp.evaluate.tags) - - # Make sure we get the main tags - Puppet[:tags] = %w{this is some tags} - assert_equal(%w{this is some tags}, comp.evaluate.tags) - - # And make sure they get processed correctly - Puppet[:tags] = ["one", "two,three", "four"] - assert_equal(%w{one two three four}, comp.evaluate.tags) - - # lastly, make sure we can override them - trans = comp.evaluate - trans.tags = ["one", "two,three", "four"] - assert_equal(%w{one two three four}, comp.evaluate.tags) + + def test_ignore_tags? + config = Puppet::Node::Configuration.new + config.host_config = true + transaction = Puppet::Transaction.new(config) + assert(! transaction.ignore_tags?, "Ignoring tags when applying a host configuration") + + config.host_config = false + transaction = Puppet::Transaction.new(config) + assert(transaction.ignore_tags?, "Not ignoring tags when applying a non-host configuration") end - def test_tagged? - res = Puppet::Type.newfile :path => tempfile() - comp = newcomp(res) - trans = comp.evaluate - - assert(trans.tagged?(res), "tagged? defaulted to false") - - # Now set some tags - trans.tags = %w{some tags} - - # And make sure it's false - assert(! trans.tagged?(res), "matched invalid tags") - - # Set ignoretags and make sure it sticks - trans.ignoretags = true - assert(trans.tagged?(res), "tags were not ignored") - - # Now make sure we actually correctly match tags - res[:tag] = "mytag" - trans.ignoretags = false - trans.tags = %w{notag} - - assert(! trans.tagged?(res), "tags incorrectly matched") - - trans.tags = %w{mytag yaytag} - assert(trans.tagged?(res), "tags should have matched") + def test_missing_tags? + resource = stub 'resource', :tagged? => true + config = Puppet::Node::Configuration.new + + # Mark it as a host config so we don't care which test is first + config.host_config = true + transaction = Puppet::Transaction.new(config) + assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when none are set") + + # host configurations pay attention to tags, no one else does. + Puppet[:tags] = "three,four" + config.host_config = false + transaction = Puppet::Transaction.new(config) + assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when not running a host configuration") + + # + config.host_config = true + transaction = Puppet::Transaction.new(config) + assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when running a host configuration and all tags are present") + + transaction = Puppet::Transaction.new(config) + resource.stubs :tagged? => false + assert(transaction.missing_tags?(resource), "Considered a resource not to be missing tags when running a host configuration and tags are missing") end # Make sure changes generated by eval_generated resources have proxies @@ -772,8 +761,8 @@ class TestTransactions < Test::Unit::TestCase end resource = type.create :name => "test" - comp = newcomp(resource) - trans = comp.evaluate + config = mk_configuration(resource) + trans = Puppet::Transaction.new(config) trans.prepare assert_nothing_raised do @@ -831,7 +820,7 @@ class TestTransactions < Test::Unit::TestCase end # Make a graph with some stuff in it. - graph = Puppet::PGraph.new + graph = Puppet::Node::Configuration.new # Add a non-triggering edge. a = trigger.new(:a) @@ -883,52 +872,12 @@ class TestTransactions < Test::Unit::TestCase assert(trans.triggered?(c, :refresh), "Transaction did not store the trigger") end - - def test_graph - Puppet.config.use(:main) - # Make a graph - graph = Puppet::PGraph.new - graph.add_edge!("a", "b") - - # Create our transaction - trans = Puppet::Transaction.new(graph) - - assert_nothing_raised do - trans.graph(graph, :testing) - end - - dotfile = File.join(Puppet[:graphdir], "testing.dot") - assert(! FileTest.exists?(dotfile), "Enabled graphing even tho disabled") - - # Now enable graphing - Puppet[:graph] = true - - assert_nothing_raised do - trans.graph(graph, :testing) - end - assert(FileTest.exists?(dotfile), "Did not create graph.") - end - - def test_created_graphs - FileUtils.mkdir_p(Puppet[:graphdir]) - file = Puppet::Type.newfile(:path => tempfile, :content => "yay") - exec = Puppet::Type.type(:exec).create(:command => "echo yay", :path => ENV['PATH'], - :require => file) - - Puppet[:graph] = true - assert_apply(file, exec) - - %w{resources relationships expanded_relationships}.each do |name| - file = File.join(Puppet[:graphdir], "%s.dot" % name) - assert(FileTest.exists?(file), "graph for %s was not created" % name) - end - end def test_set_target file = Puppet::Type.newfile(:path => tempfile(), :content => "yay") exec1 = Puppet::Type.type(:exec).create :command => "/bin/echo exec1" exec2 = Puppet::Type.type(:exec).create :command => "/bin/echo exec2" - trans = Puppet::Transaction.new(newcomp(file, exec1, exec2)) + trans = Puppet::Transaction.new(mk_configuration(file, exec1, exec2)) # First try it with an edge that has no callback edge = Puppet::Relationship.new(file, exec1) @@ -975,7 +924,8 @@ class TestTransactions < Test::Unit::TestCase one[:require] = two two[:require] = one - trans = newcomp(one, two).evaluate + config = mk_configuration(one, two) + trans = Puppet::Transaction.new(config) assert_raise(Puppet::Error) do trans.prepare end @@ -1042,15 +992,15 @@ class TestTransactions < Test::Unit::TestCase rels[dir] = file rels.each do |after, before| - comp = newcomp(before, after) - trans = comp.evaluate + config = mk_configuration(before, after) + trans = Puppet::Transaction.new(config) str = "from %s to %s" % [before, after] assert_nothing_raised("Failed to create graph %s" % str) do trans.prepare end - graph = trans.relgraph + graph = trans.relationship_graph assert(graph.edge?(before, after), "did not create manual relationship %s" % str) assert(! graph.edge?(after, before), "created automatic relationship %s" % str) end @@ -1063,7 +1013,7 @@ class TestTransactions < Test::Unit::TestCase one[:require] = two one[:subscribe] = two - comp = newcomp(one, two) + comp = mk_configuration(one, two) trans = Puppet::Transaction.new(comp) graph = trans.relationship_graph @@ -1188,5 +1138,3 @@ class TestTransactions < Test::Unit::TestCase assert_equal(1, $flushed, "object was flushed in noop") end end - -# $Id$ diff --git a/test/puppet/conffiles.rb b/test/puppet/conffiles.rb index 3dfa53a13..1800c80f6 100755 --- a/test/puppet/conffiles.rb +++ b/test/puppet/conffiles.rb @@ -3,7 +3,6 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppettest' -require 'puppet/util/config' class TestConfFiles < Test::Unit::TestCase include PuppetTest @@ -72,7 +71,7 @@ class TestConfFiles < Test::Unit::TestCase path = tempfile() sampledata { |data| - config = Puppet::Util::Config.new + config = Puppet::Util::Settings.new data.each { |section, hash| hash.each { |param, value| config.setdefaults(section, param => [value, value]) @@ -100,7 +99,7 @@ class TestConfFiles < Test::Unit::TestCase # that the default config is free of simple typos etc. def test_genconfig assert_nothing_raised { - Puppet::config::to_config + Puppet::settings::to_config } end diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 534c35759..b2c111e60 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -174,7 +174,7 @@ class TestType < Test::Unit::TestCase ) } - comp = newcomp(twoobj, oneobj) + comp = mk_configuration(twoobj, oneobj) assert_nothing_raised { comp.finalize @@ -246,76 +246,6 @@ class TestType < Test::Unit::TestCase # and make sure managed objects start with them assert(user.property(:ensure), "User did not get an ensure property") end - - # Make sure removal works - def test_remove - objects = {} - top = Puppet.type(:component).create(:name => "top") - objects[top.class] = top - - base = tempfile() - - # now make a two-tier, 5 piece tree - %w{a b}.each do |letter| - name = "comp%s" % letter - comp = Puppet.type(:component).create(:name => name) - top.push comp - objects[comp.class] = comp - - 5.times do |i| - file = base + letter + i.to_s - - obj = Puppet.type(:file).create(:name => file, :ensure => "file") - - comp.push obj - objects[obj.class] = obj - end - end - - assert_nothing_raised do - top.remove - end - - objects.each do |klass, obj| - assert_nil(klass[obj.name], "object %s was not removed" % obj.name) - end - end - - # Verify that objects can't be their own children. - def test_object_recursion - comp = Puppet.type(:component).create(:name => "top") - - file = Puppet.type(:component).create(:name => "middle") - - assert_raise(Puppet::DevError) do - comp.push(comp) - end - - assert_raise(Puppet::DevError) do - file.push(file) - end - - assert_raise(Puppet::DevError) do - comp.parent = comp - end - - assert_raise(Puppet::DevError) do - file.parent = file - end - - assert_nothing_raised { - comp.push(file) - } - - assert_raise(Puppet::DevError) do - file.push(comp) - end - - assert_raise(Puppet::DevError) do - comp.parent = file - end - end - def test_newtype_methods assert_nothing_raised { Puppet::Type.newtype(:mytype) do @@ -732,12 +662,22 @@ class TestType < Test::Unit::TestCase end def test_path + config = mk_configuration + # Check that our paths are built correctly. Just pick a random, "normal" type. type = Puppet::Type.type(:exec) mk = Proc.new do |i, hash| hash[:title] = "exec%s" % i hash[:command] = "/bin/echo" - type.create(hash) + if parent = hash[:parent] + hash.delete(:parent) + end + res = type.create(hash) + config.add_resource res + if parent + config.add_edge!(parent, res) + end + res end exec = mk.call(1, {}) @@ -745,25 +685,31 @@ class TestType < Test::Unit::TestCase assert_equal("/Exec[exec1]", exec.path) comp = Puppet::Type.newcomponent :title => "My[component]", :type => "Yay" + config.add_resource comp exec = mk.call(2, :parent => comp) assert_equal("/My[component]/Exec[exec2]", exec.path) comp = Puppet::Type.newcomponent :name => "Other[thing]" + config.add_resource comp exec = mk.call(3, :parent => comp) assert_equal("/Other[thing]/Exec[exec3]", exec.path) comp = Puppet::Type.newcomponent :type => "server", :name => "server" + config.add_resource comp exec = mk.call(4, :parent => comp) assert_equal("/server/Exec[exec4]", exec.path) comp = Puppet::Type.newcomponent :type => "whatever", :name => "class[main]" + config.add_resource comp exec = mk.call(5, :parent => comp) assert_equal("//Exec[exec5]", exec.path) - comp = Puppet::Type.newcomponent :type => "yay", :name => "Good[bad]", :parent => comp - exec = mk.call(6, :parent => comp) + newcomp = Puppet::Type.newcomponent :type => "yay", :name => "Good[bad]" + config.add_resource newcomp + config.add_edge! comp, newcomp + exec = mk.call(6, :parent => newcomp) assert_equal("//Good[bad]/Exec[exec6]", exec.path) end diff --git a/test/ral/providers/service.rb b/test/ral/providers/service.rb index d21298162..5a4a6c1c2 100755 --- a/test/ral/providers/service.rb +++ b/test/ral/providers/service.rb @@ -54,7 +54,7 @@ class TestLocalService < Test::Unit::TestCase service.retrieve } - comp = newcomp("servicetst", service) + comp = mk_configuration("servicetst", service) service[:ensure] = :running Puppet.info "Starting %s" % service.name @@ -105,7 +105,7 @@ class TestLocalService < Test::Unit::TestCase service.retrieve } - comp = newcomp("servicetst", service) + comp = mk_configuration("servicetst", service) service[:enable] = true Puppet.info "Enabling %s" % service.name diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb index 5d09a5183..2802f3440 100755 --- a/test/ral/types/basic.rb +++ b/test/ral/types/basic.rb @@ -35,12 +35,9 @@ class TestBasic < Test::Unit::TestCase :path => ENV["PATH"] ) } - assert_nothing_raised() { - @component.push( - @configfile, - @command - ) - } + @config = mk_configuration(@component, @configfile, @command) + @config.add_edge! @component, @configfile + @config.add_edge! @component, @command end def teardown @@ -86,5 +83,3 @@ class TestBasic < Test::Unit::TestCase } end end - -# $Id$ diff --git a/test/ral/types/component.rb b/test/ral/types/component.rb deleted file mode 100755 index 06c32dd01..000000000 --- a/test/ral/types/component.rb +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env ruby - -$:.unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'puppettest' -require 'puppettest/support/resources' - -# $Id$ - -class TestComponent < Test::Unit::TestCase - include PuppetTest - include PuppetTest::Support::Resources - def setup - super - @@used = {} - @type = Puppet::Type::Component - @file = Puppet::Type.type(:file) - end - - def randnum(limit) - num = nil - looped = 0 - loop do - looped += 1 - if looped > 2000 - raise "Reached limit of looping" - break - end - num = rand(limit) - unless @@used.include?(num) - @@used[num] = true - break - end - end - - num - end - - def mkfile(num = nil) - unless num - num = randnum(1000) - end - name = tempfile() + num.to_s - - file = Puppet.type(:file).create( - :path => name, - :checksum => "md5" - ) - @@tmpfiles << name - file - end - - def mkcomp - Puppet.type(:component).create(:name => "component_" + randnum(1000).to_s) - end - - def mkrandcomp(numfiles, numdivs) - comp = mkcomp - hash = {} - found = 0 - - divs = {} - - numdivs.times { |i| - num = i + 2 - divs[num] = nil - } - while found < numfiles - num = randnum(numfiles) - found += 1 - f = mkfile(num) - hash[f.name] = f - reqd = [] - divs.each { |n,obj| - if rand(50) % n == 0 - if obj - unless reqd.include?(obj.object_id) - f[:require] = [[obj.class.name, obj.name]] - reqd << obj.object_id - end - end - end - - divs[n] = f - } - end - - hash.each { |name, obj| - comp.push obj - } - - comp.finalize - comp - end - - def test_to_graph - one, two, middle, top = mktree - - graph = nil - assert_nothing_raised do - graph = top.to_graph - end - - assert(graph.is_a?(Puppet::PGraph), "result is not a pgraph") - - [one, two, middle, top].each do |comp| - comp.each do |child| - assert(graph.edge?(comp, child), - "Did not create edge from %s => %s" % [comp.name, child.name]) - end - end - end -end diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb index 7b2e770f0..1695befac 100755 --- a/test/ral/types/cron.rb +++ b/test/ral/types/cron.rb @@ -94,7 +94,7 @@ class TestCron < Test::Unit::TestCase text = obj.read name = cron.name - comp = newcomp(name, cron) + comp = mk_configuration(name, cron) assert_events([:cron_created], comp) cron.provider.class.prefetch @@ -157,7 +157,7 @@ class TestCron < Test::Unit::TestCase def test_makeandretrievecron %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name| cron = mkcron(name) - comp = newcomp(name, cron) + comp = mk_configuration(name, cron) trans = assert_events([:cron_created], comp, name) cron.provider.class.prefetch diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb index ede6361cd..0c7cc1d90 100755 --- a/test/ral/types/exec.rb +++ b/test/ral/types/exec.rb @@ -179,7 +179,7 @@ class TestExec < Test::Unit::TestCase ) } - comp = newcomp("createstest", exec) + comp = mk_configuration("createstest", exec) assert_events([:executed_command], comp, "creates") assert_events([], comp, "creates") end @@ -202,7 +202,7 @@ class TestExec < Test::Unit::TestCase :require => [:file, oexe] ) - comp = newcomp("Testing", file, exec) + comp = mk_configuration("Testing", file, exec) assert_events([:file_created, :executed_command], comp) end @@ -299,7 +299,7 @@ class TestExec < Test::Unit::TestCase :path => ENV['PATH'] ) } - comp = newcomp(exec) + comp = mk_configuration(exec) assert_events([:executed_command], comp) assert_events([:executed_command], comp) @@ -344,7 +344,7 @@ class TestExec < Test::Unit::TestCase exec = Puppet.type(:exec).create(args) } - comp = newcomp("usertest", exec) + comp = mk_configuration("usertest", exec) assert_events([:executed_command], comp, "usertest") assert(FileTest.exists?(file), "File does not exist") @@ -425,7 +425,7 @@ class TestExec < Test::Unit::TestCase ) } - comp = newcomp(file, exec) + comp = mk_configuration(file, exec) comp.finalize assert_events([:executed_command, :file_changed], comp) diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index f3e1a562d..0c16d6dff 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -122,7 +122,7 @@ class TestFile < Test::Unit::TestCase ) } - comp = newcomp("createusertest", file) + comp = mk_configuration("createusertest", file) assert_events([:file_created], comp) end @@ -397,6 +397,8 @@ class TestFile < Test::Unit::TestCase events = assert_apply(file) + assert(events) + assert(! events.include?(:file_changed), "File incorrectly changed") assert_events([], file) @@ -493,6 +495,7 @@ class TestFile < Test::Unit::TestCase # Create a test directory path = tempfile() dir = @file.create :path => path, :mode => 0755, :recurse => true + config = mk_configuration(dir) Dir.mkdir(path) @@ -673,6 +676,7 @@ class TestFile < Test::Unit::TestCase :check => %w{owner mode group} ) } + config = mk_configuration dir children = nil @@ -683,19 +687,22 @@ class TestFile < Test::Unit::TestCase assert_equal([subdir], children.collect {|c| c.title }, "Incorrect generated children") - dir.class[subdir].remove + # Remove our subdir resource, + subdir_resource = config.resource(:file, subdir) + config.remove_resource(subdir_resource) + # Create the test file File.open(tmpfile, "w") { |f| f.puts "yayness" } assert_nothing_raised { children = dir.eval_generate } + # And make sure we get both resources back. assert_equal([subdir, tmpfile].sort, children.collect {|c| c.title }.sort, - "Incorrect generated children") + "Incorrect generated children when recurse == %s" % value.inspect) File.unlink(tmpfile) - #system("rm -rf %s" % basedir) Puppet.type(:file).clear end end @@ -754,6 +761,7 @@ class TestFile < Test::Unit::TestCase :check => %w{owner mode group} ) } + mk_configuration dir assert_nothing_raised { dir.eval_generate @@ -796,6 +804,7 @@ class TestFile < Test::Unit::TestCase :check => %w{mode owner group} ) } + mk_configuration dirobj assert_nothing_raised { dirobj.eval_generate @@ -884,7 +893,7 @@ class TestFile < Test::Unit::TestCase ) } - comp = newcomp("yay", file) + comp = mk_configuration("yay", file) comp.finalize assert_apply(comp) #assert_events([:directory_created], comp) @@ -1274,26 +1283,27 @@ class TestFile < Test::Unit::TestCase lfobj = Puppet::Type.newfile( :title => "localfile", :path => localfile, - :content => "rahtest" + :content => "rahtest", + :backup => false ) - destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir, :source => sourcedir, + :backup => false, :recurse => true) - comp = newcomp(lfobj, destobj) - assert_apply(comp) + config = mk_configuration(lfobj, destobj) + config.apply assert(FileTest.exists?(dsourcefile), "File did not get copied") assert(FileTest.exists?(localfile), "File did not get created") assert(FileTest.exists?(purgee), "File got prematurely purged") assert_nothing_raised { destobj[:purge] = true } - assert_apply(comp) + config.apply - assert(FileTest.exists?(dsourcefile), "Source file got purged") assert(FileTest.exists?(localfile), "Local file got purged") + assert(FileTest.exists?(dsourcefile), "Source file got purged") assert(! FileTest.exists?(purgee), "File did not get purged") end @@ -1333,7 +1343,7 @@ class TestFile < Test::Unit::TestCase group = Puppet.type(:group).create( :name => "pptestg" ) - comp = newcomp(user, group, home) + comp = mk_configuration(user, group, home) } # Now make sure we get a relationship for each of these @@ -1629,6 +1639,7 @@ class TestFile < Test::Unit::TestCase file = File.join(dir, "file") File.open(file, "w") { |f| f.puts "" } obj = Puppet::Type.newfile :path => dir, :recurse => true, :mode => 0755 + mk_configuration obj assert_equal("/%s" % obj.ref, obj.path) @@ -1739,6 +1750,7 @@ class TestFile < Test::Unit::TestCase File.open(file, "w") { |f| f.puts "yay" } File.chmod(0644, file) obj = Puppet::Type.newfile(:path => dir, :mode => 0750, :recurse => "2") + config = mk_configuration(obj) children = nil assert_nothing_raised("Failure when recursing") do @@ -1747,6 +1759,7 @@ class TestFile < Test::Unit::TestCase assert(obj.class[subdir], "did not create subdir object") children.each do |c| assert_nothing_raised("Failure when recursing on %s" % c) do + c.configuration = config others = c.eval_generate end end @@ -1780,6 +1793,7 @@ class TestFile < Test::Unit::TestCase obj = Puppet::Type.newfile(:path => dir, :ensure => :directory, :recurse => true) + config = mk_configuration(obj) children = nil assert_nothing_raised do children = obj.eval_generate diff --git a/test/ral/types/file/target.rb b/test/ral/types/file/target.rb index 1e62f07ac..c4597cedf 100755 --- a/test/ral/types/file/target.rb +++ b/test/ral/types/file/target.rb @@ -44,6 +44,7 @@ class TestFileTarget < Test::Unit::TestCase def test_linkrecurse dest = tempfile() link = @file.create :path => tempfile(), :recurse => true, :ensure => dest + mk_configuration link ret = nil @@ -317,9 +318,8 @@ class TestFileTarget < Test::Unit::TestCase :source => dirs["source"], :recurse => true ) - - - trans = assert_apply(obj) + config = mk_configuration obj + config.apply newfile = File.join(dirs["target"], "sourcefile") diff --git a/test/ral/types/fileignoresource.rb b/test/ral/types/fileignoresource.rb index fa01aecdc..153946770 100755 --- a/test/ral/types/fileignoresource.rb +++ b/test/ral/types/fileignoresource.rb @@ -73,19 +73,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase ) } - #make a component and adds the file - comp = Puppet.type(:component).create( - :name => "component" - ) - comp.push tofile - - #make, evaluate transaction and sync the component - assert_nothing_raised { - trans = comp.evaluate - } - assert_nothing_raised { - trans.evaluate - } + config = mk_configuration(tofile) + config.apply #topath should exist as a directory with sourcedir as a directory @@ -150,19 +139,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase ) } - #make a component and adds the file - comp = Puppet.type(:component).create( - :name => "component" - ) - comp.push tofile - - #make, evaluate transaction and sync the component - assert_nothing_raised { - trans = comp.evaluate - } - assert_nothing_raised { - trans.evaluate - } + config = mk_configuration(tofile) + config.apply #topath should exist as a directory with sourcedir as a directory @@ -170,6 +148,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase assert(FileTest.exists?(File.join(topath,sourcefile1))) assert(FileTest.exists?(File.join(topath,subdir))) assert(FileTest.exists?(File.join(File.join(topath,subdir),sourcefile1))) + #This file should not assert(!(FileTest.exists?(File.join(topath,sourcefile2)))) assert(!(FileTest.exists?(File.join(topath,subdir2)))) @@ -235,19 +214,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase ) } - #make a component and adds the file - comp = Puppet.type(:component).create( - :name => "component" - ) - comp.push tofile - - #make, evaluate transaction and sync the component - assert_nothing_raised { - trans = comp.evaluate - } - assert_nothing_raised { - trans.evaluate - } + config = mk_configuration(tofile) + config.apply #topath should exist as a directory with sourcedir as a directory @@ -273,5 +241,3 @@ class TestFileIgnoreSources < Test::Unit::TestCase end end - -# $Id$ diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb index b257fd935..01d9766db 100755 --- a/test/ral/types/filesources.rb +++ b/test/ral/types/filesources.rb @@ -62,6 +62,7 @@ class TestFileSources < Test::Unit::TestCase :name => path ) } + config = mk_configuration(file) child = nil assert_nothing_raised { child = file.newchild("childtest", true) @@ -275,6 +276,7 @@ class TestFileSources < Test::Unit::TestCase # The sourcerecurse method will only ever get called when we're # recursing, so we go ahead and set it. obj = Puppet::Type.newfile :source => source, :path => dest, :recurse => true + config = mk_configuration(obj) result = nil sourced = nil @@ -288,7 +290,7 @@ class TestFileSources < Test::Unit::TestCase assert_equal([dfileobj], result) # Clean this up so it can be recreated - dfileobj.remove + config.remove_resource(dfileobj) # Make sure we correctly iterate over the sources nosource = tempfile() @@ -577,51 +579,6 @@ class TestFileSources < Test::Unit::TestCase } end - def test_networkSourcesWithoutService - server = nil - - Puppet[:autosign] = true - Puppet[:masterport] = 8765 - - serverpid = nil - assert_nothing_raised() { - server = Puppet::Network::Server::WEBrick.new( - :Handlers => { - :CA => {}, # so that certs autogenerate - } - ) - - } - serverpid = fork { - assert_nothing_raised() { - #trap(:INT) { server.shutdown; Kernel.exit! } - trap(:INT) { server.shutdown } - server.start - } - } - @@tmppids << serverpid - - sleep(1) - - name = File.join(tmpdir(), "nosourcefile") - file = Puppet.type(:file).create( - :source => "puppet://localhost/dist/file", - :name => name - ) - - assert_nothing_raised { - file.retrieve - } - - comp = newcomp("nosource", file) - - assert_nothing_raised { - comp.evaluate - } - - assert(!FileTest.exists?(name), "File with no source exists anyway") - end - def test_unmountedNetworkSources server = nil mounts = { @@ -669,11 +626,8 @@ class TestFileSources < Test::Unit::TestCase file.retrieve } - comp = newcomp("nosource", file) - - assert_nothing_raised { - comp.evaluate - } + comp = mk_configuration(file) + comp.apply assert(!FileTest.exists?(name), "File with no source exists anyway") end @@ -722,7 +676,7 @@ class TestFileSources < Test::Unit::TestCase ) } - comp = newcomp(file) + comp = mk_configuration(file) assert_events([:file_created], comp) assert(File.exists?(to), "File does not exist") @@ -808,9 +762,8 @@ class TestFileSources < Test::Unit::TestCase trans = nil assert_nothing_raised { file[:links] = :manage - comp = newcomp(file) - trans = comp.evaluate - trans.evaluate + comp = mk_configuration(file) + trans = comp.apply } assert(trans.failed?(file), "Object did not fail to copy links") diff --git a/test/ral/types/group.rb b/test/ral/types/group.rb index 9870d533a..5189c63a1 100755 --- a/test/ral/types/group.rb +++ b/test/ral/types/group.rb @@ -65,7 +65,7 @@ class TestGroup < Test::Unit::TestCase def attrtest_ensure(group) group[:ensure] = :absent - comp = newcomp("ensuretest", group) + comp = mk_configuration("ensuretest", group) assert_apply(comp) assert_equal(:absent, group.provider.ensure, "Group is still present") group[:ensure] = :present @@ -91,7 +91,7 @@ class TestGroup < Test::Unit::TestCase assert_equal(15, group.should(:gid), "Did not convert gid to number") - comp = newcomp(group) + comp = mk_configuration(group) trans = assert_events([:group_modified], comp, "group") assert_equal(15, group.provider.gid, "GID was not changed") diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb index b8d576b9a..8fada1adb 100755 --- a/test/ral/types/tidy.rb +++ b/test/ral/types/tidy.rb @@ -55,7 +55,7 @@ class TestTidy < Test::Unit::TestCase assert_nothing_raised { link = newlink(:target => source, :recurse => true) } - comp = newcomp("linktest",link) + comp = mk_configuration("linktest",link) cycle(comp) path = link.name diff --git a/test/ral/types/user.rb b/test/ral/types/user.rb index 121ac9cf0..9b24cc74a 100755 --- a/test/ral/types/user.rb +++ b/test/ral/types/user.rb @@ -82,7 +82,7 @@ class TestUser < Test::Unit::TestCase old = user.provider.ensure user[:ensure] = :absent - comp = newcomp("ensuretest", user) + comp = mk_configuration("ensuretest", user) assert_apply(user) assert(!user.provider.exists?, "User is still present") user[:ensure] = :present @@ -102,7 +102,7 @@ class TestUser < Test::Unit::TestCase old = user.provider.comment user[:comment] = "A different comment" - comp = newcomp("commenttest", user) + comp = mk_configuration("commenttest", user) trans = assert_events([:user_changed], comp, "user") @@ -117,7 +117,7 @@ class TestUser < Test::Unit::TestCase def attrtest_home(user) obj = nil - comp = newcomp("hometest", user) + comp = mk_configuration("hometest", user) old = user.provider.home user[:home] = old @@ -137,7 +137,7 @@ class TestUser < Test::Unit::TestCase def attrtest_shell(user) old = user.provider.shell - comp = newcomp("shelltest", user) + comp = mk_configuration("shelltest", user) user[:shell] = old @@ -167,7 +167,7 @@ class TestUser < Test::Unit::TestCase def attrtest_gid(user) obj = nil old = user.provider.gid - comp = newcomp("gidtest", user) + comp = mk_configuration("gidtest", user) user.retrieve @@ -216,7 +216,7 @@ class TestUser < Test::Unit::TestCase def attrtest_uid(user) obj = nil - comp = newcomp("uidtest", user) + comp = mk_configuration("uidtest", user) user.provider.uid = 1 @@ -387,7 +387,7 @@ class TestUser < Test::Unit::TestCase ogroup = Puppet.type(:group).create( :name => "yayness" ) - comp = newcomp(user, group, home, ogroup) + comp = mk_configuration(user, group, home, ogroup) } rels = nil @@ -404,7 +404,7 @@ class TestUser < Test::Unit::TestCase user = mkuser(name) - comp = newcomp("usercomp", user) + comp = mk_configuration("usercomp", user) trans = assert_events([:user_created], comp, "user") @@ -424,7 +424,7 @@ class TestUser < Test::Unit::TestCase assert(! user.provider.exists?, "User %s is present" % name) - comp = newcomp("usercomp", user) + comp = mk_configuration("usercomp", user) trans = assert_events([:user_created], comp, "user") diff --git a/test/util/fact_store.rb b/test/util/fact_store.rb deleted file mode 100755 index 5b04d1374..000000000 --- a/test/util/fact_store.rb +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke Kanies on 2007-05-02. -# Copyright (c) 2007. All rights reserved. - -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'puppettest' -require 'puppet/util/fact_store' - -class TestFactStore < Test::Unit::TestCase - include PuppetTest - - def test_new_fact_store - klass = nil - assert_nothing_raised("Could not create fact store") do - klass = Puppet::Util::FactStore.newstore(:yay) do - end - end - - assert_equal(klass, Puppet::Util::FactStore.store(:yay), "Did not get created store back by name") - end - - def test_yaml_store - yaml = Puppet::Util::FactStore.store(:yaml) - assert(yaml, "Could not retrieve yaml store") - - name = "node" - facts = {"a" => :b, :c => "d", :e => :f, "g" => "h"} - - store = nil - assert_nothing_raised("Could not create YAML store instance") do - store = yaml.new - end - - assert_nothing_raised("Could not store host facts") do - store.set(name, facts) - end - - dir = Puppet[:yamlfactdir] - - file = File.join(dir, name + ".yaml") - assert(FileTest.exists?(file), "Did not create yaml file for node") - - text = File.read(file) - newfacts = nil - assert_nothing_raised("Could not deserialize yaml") do - newfacts = YAML::load(text) - end - - # Don't directly compare the hashes, because there might be extra - # data stored in the client hash - facts.each do |var, value| - assert_equal(value, newfacts[var], "Value for %s changed during storage" % var) - end - - # Now make sure the facts get retrieved correctly - assert_nothing_raised("Could not retrieve facts") do - newfacts = store.get(name) - end - - # Now make sure the hashes are equal, since internal facts should not be returned. - assert_equal(facts, newfacts, "Retrieved facts are not equal") - end -end - -# $Id$ diff --git a/test/util/features.rb b/test/util/features.rb index 14e93c537..1e5858877 100755 --- a/test/util/features.rb +++ b/test/util/features.rb @@ -93,5 +93,3 @@ class TestFeatures < Test::Unit::TestCase end end end - -# $Id$ diff --git a/test/util/graph.rb b/test/util/graph.rb deleted file mode 100755 index 875fd0ec3..000000000 --- a/test/util/graph.rb +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke Kanies on 2006-11-16. -# Copyright (c) 2006. All rights reserved. - -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ - -require 'puppettest' -require 'puppettest/graph' -require 'puppet/util/graph' - -class TestUtilGraph < Test::Unit::TestCase - include PuppetTest - include PuppetTest::Graph - - def test_to_graph - children = %w{a b c d} - list = Container.new("yay", children) - - graph = nil - assert_nothing_raised do - graph = list.to_graph - end - - assert(graph.vertices.include?(list), "wtf?") - - ([list] + children).each do |thing| - assert(graph.vertex?(thing), "%s is not a vertex" % thing) - end - children.each do |child| - assert(graph.edge?(list, child), - "%s/%s was not added as an edge" % ["yay", child]) - end - end - - def test_recursive_to_graph - one, two, three, middle, top = build_tree - - graph = nil - assert_nothing_raised do - graph = top.to_graph - end - - (%w{a b c d e f g h} + [one, two, middle, top]).each do |v| - assert(graph.vertex?(v), "%s is not a vertex" % v) - end - - [one, two, middle, top].each do |con| - con.each do |child| - assert(graph.edge?(con, child), "%s/%s is not an edge" % [con, child]) - end - end - - # Now make sure we correctly retrieve the leaves from each container - {top => %w{a b c d e f g h i j}, - one => %w{a b}, - two => %w{c d}, - three => %w{i j}, - middle => %w{c d e f}}.each do |cont, list| - leaves = nil - assert_nothing_raised do - leaves = graph.leaves(cont) - end - leaves = leaves.sort - assert_equal(list.sort, leaves.sort, - "Got incorrect leaf list for %s" % cont.name) - %w{a b c d e f g h}.each do |letter| - unless list.include?(letter) - assert(!leaves.include?(letter), - "incorrectly got %s as a leaf of %s" % - [letter, cont.to_s]) - end - end - end - end - - def test_to_graph_with_block - middle = Container.new "middle", ["c", "d", 3, 4] - top = Container.new "top", ["a", "b", middle, 1, 2] - - graph = nil - assert_nothing_raised() { - graph = top.to_graph { |c| c.is_a?(String) or c.is_a?(Container) } - } - - %w{a b c d}.each do |child| - assert(graph.vertex?(child), "%s was not added as a vertex" % child) - end - - [1, 2, 3, 4].each do |child| - assert(! graph.vertex?(child), "%s is a vertex" % child) - end - end - - def test_cyclic_graphs - one = Container.new "one", %w{a b} - two = Container.new "two", %w{c d} - - one.push(two) - two.push(one) - - assert_raise(Puppet::Error, "did not fail on cyclic graph") do - one.to_graph - end - end -end - -# $Id$ diff --git a/test/util/config.rb b/test/util/settings.rb index f99ad54b4..62f34fda6 100755 --- a/test/util/config.rb +++ b/test/util/settings.rb @@ -4,14 +4,14 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'mocha' require 'puppettest' -require 'puppet/util/config' +require 'puppet/util/settings' require 'puppettest/parsertesting' -class TestConfig < Test::Unit::TestCase +class TestSettings < Test::Unit::TestCase include PuppetTest include PuppetTest::ParserTesting - CElement = Puppet::Util::Config::CElement - CBoolean = Puppet::Util::Config::CBoolean + CElement = Puppet::Util::Settings::CElement + CBoolean = Puppet::Util::Settings::CBoolean def setup super @@ -59,57 +59,6 @@ class TestConfig < Test::Unit::TestCase } end - # #795 - when --config=relative, we want to fully expand file paths. - def test_relative_paths_when_to_transportable - config = mkconfig - config.setdefaults :yay, :transtest => ["/what/ever", "yo"] - file = config.element(:transtest) - - # Now override it with a relative path name - config[:transtest] = "here" - - should = File.join(Dir.getwd, "here") - - object = file.to_transportable[0] - assert_equal(should, object.name, "Did not translate relative pathnames to full path names") - end - - def test_to_manifest - set_configs - manifest = nil - assert_nothing_raised("Could not convert to a manifest") { - manifest = @config.to_manifest - } - - Puppet[:parseonly] = true - - interp = nil - assert_nothing_raised do - interp = mkinterp :Code => manifest, :UseNodes => false - end - - trans = nil - node = Puppet::Node.new("node") - assert_nothing_raised do - trans = interp.compile(node) - end - assert_nothing_raised("Could not instantiate objects") { - trans.extract.to_type - } - end - - def test_to_comp - set_configs - comp = nil - assert_nothing_raised("Could not convert to a component") { - comp = @config.to_component - } - - assert_nothing_raised("Could not retrieve component") { - comp.retrieve - } - end - def test_to_config set_configs @@ -146,7 +95,7 @@ class TestConfig < Test::Unit::TestCase def mkconfig c = nil assert_nothing_raised { - c = Puppet::Util::Config.new + c = Puppet::Util::Settings.new } return c end @@ -668,91 +617,6 @@ yay = /a/path assert_equal("/my/file", @config[:b], "Values are not equal") end - def test_reuse - c = mkconfig - - file = tempfile() - section = "testing" - assert_nothing_raised { - @config.setdefaults(section, - :myfile => {:default => file, :create => true, :desc => "yay"} - ) - } - - assert_nothing_raised("Could not use a section") { - @config.use(section) - } - - assert(FileTest.exists?(file), "Did not create file") - - assert(! Puppet::Type.type(:file)[file], "File obj still exists") - - File.unlink(file) - - @config.reuse - assert(FileTest.exists?(file), "Did not create file") - end - - def test_mkusers - c = mkconfig - - file = tempfile() - section = "testing" - assert_nothing_raised { - @config.setdefaults(section, - :mkusers => [false, "yay"], - :myfile => { - :default => file, - :owner => "pptest", - :group => "pptest", - :desc => "yay", - :create => true - } - ) - } - - comp = nil - assert_nothing_raised { - comp = @config.to_component - } - - [:user, :group].each do |type| - # The objects might get created internally by Puppet::Util; just - # make sure they're not being managed - if obj = Puppet.type(type)["pptest"] - assert(! obj.managed?, "%s objectis managed" % type) - end - end - comp.each { |o| o.remove } - - @config[:mkusers] = true - - assert_nothing_raised { - @config.to_component - } - - user = Puppet.type(:user)["pptest"] - assert(user, "User object did not get created") - assert(user.managed?, "User object is not managed.") - assert(user.should(:comment), "user does not have a comment set") - - group = Puppet.type(:group)["pptest"] - assert(group, "Group object did not get created") - assert(group.managed?, - "Group object is not managed." - ) - - if Process.uid == 0 - cleanup do - user[:ensure] = :absent - group[:ensure] = :absent - assert_apply(user, group) - end - - assert_apply(user, group) - end - end - def test_notmanagingdev c = mkconfig path = "/dev/testing" @@ -764,11 +628,9 @@ yay = /a/path } ) - assert_nothing_raised { - @config.to_component - } + config = @config.to_configuration - assert(! Puppet.type(:file)["/dev/testing"], "Created dev file") + assert(! config.resource(:file, "/dev/testing"), "Created dev file") end def test_groupsetting @@ -906,15 +768,15 @@ yay = /a/path } assert_equal("http://yayness/rahness", val, - "Config got messed up") + "Settings got messed up") end def test_correct_type_assumptions config = mkconfig - file = Puppet::Util::Config::CFile - element = Puppet::Util::Config::CElement - bool = Puppet::Util::Config::CBoolean + file = Puppet::Util::Settings::CFile + element = Puppet::Util::Settings::CElement + bool = Puppet::Util::Settings::CBoolean # We have to keep these ordered, unfortunately. [ @@ -1119,12 +981,12 @@ yay = /a/path # Now enable it so they'll be added config[:mkusers] = true - comp = config.to_component + comp = config.to_configuration - Puppet::Type.type(:user).each do |u| + comp.vertices.find_all { |r| r.class.name == :user }.each do |u| assert(u.name != "root", "Tried to manage root user") end - Puppet::Type.type(:group).each do |u| + comp.vertices.find_all { |r| r.class.name == :group }.each do |u| assert(u.name != "root", "Tried to manage root group") assert(u.name != "wheel", "Tried to manage wheel group") end |
