diff options
| author | Luke Kanies <luke@madstop.com> | 2007-11-19 01:36:48 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-11-19 01:36:48 -0600 |
| commit | 2b14f627aca1d5be69cf6606044df4d6e67f6eba (patch) | |
| tree | a20db3a608af483f598f482e743868413da8fd8f /test | |
| parent | 9cf477b6cc771eab7bd29d18c49128571e877987 (diff) | |
| download | puppet-2b14f627aca1d5be69cf6606044df4d6e67f6eba.tar.gz puppet-2b14f627aca1d5be69cf6606044df4d6e67f6eba.tar.xz puppet-2b14f627aca1d5be69cf6606044df4d6e67f6eba.zip | |
Reverting the changes I'd made toward removing the global
resources. These are commits:
c19835ce9f8a5138b30a1a32ca741c996b0916d2
9290cc89a2206fb5204578f8e91208857a48b147
ffb4c2dbc7314b364d25e4f7be599ef05b767b44
Diffstat (limited to 'test')
| -rwxr-xr-x | test/language/snippets.rb | 23 | ||||
| -rw-r--r-- | test/lib/puppettest/support/utils.rb | 2 | ||||
| -rwxr-xr-x | test/network/client/client.rb | 29 | ||||
| -rwxr-xr-x | test/network/client/master.rb | 51 | ||||
| -rwxr-xr-x | test/network/handler/fileserver.rb | 19 | ||||
| -rwxr-xr-x | test/network/handler/resource.rb | 5 | ||||
| -rwxr-xr-x | test/other/overrides.rb | 33 | ||||
| -rwxr-xr-x | test/other/relationships.rb | 18 | ||||
| -rwxr-xr-x | test/other/transactions.rb | 36 | ||||
| -rwxr-xr-x | test/ral/types/basic.rb | 7 | ||||
| -rwxr-xr-x | test/ral/types/cron.rb | 14 | ||||
| -rwxr-xr-x | test/ral/types/exec.rb | 13 | ||||
| -rwxr-xr-x | test/ral/types/file.rb | 130 | ||||
| -rwxr-xr-x | test/ral/types/file/target.rb | 26 | ||||
| -rwxr-xr-x | test/ral/types/filebucket.rb | 24 | ||||
| -rwxr-xr-x | test/ral/types/fileignoresource.rb | 7 | ||||
| -rwxr-xr-x | test/ral/types/filesources.rb | 10 | ||||
| -rwxr-xr-x | test/ral/types/host.rb | 4 | ||||
| -rwxr-xr-x | test/ral/types/package.rb | 1 | ||||
| -rwxr-xr-x | test/ral/types/parameter.rb | 5 | ||||
| -rwxr-xr-x | test/ral/types/schedule.rb | 39 | ||||
| -rwxr-xr-x | test/ral/types/sshkey.rb | 18 | ||||
| -rwxr-xr-x | test/ral/types/tidy.rb | 14 | ||||
| -rwxr-xr-x | test/util/filetype.rb | 3 |
24 files changed, 328 insertions, 203 deletions
diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 05597cdec..0806a40b4 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -22,14 +22,14 @@ class TestSnippets < Test::Unit::TestCase end def assert_file(path, msg = nil) - unless file = @configuration.resource(:file, path) + unless file = @file[path] msg ||= "Could not find file %s" % path raise msg end end def assert_mode_equal(mode, path) - unless file = @configuration.resource(:file, path) + unless file = @file[path] raise "Could not find file %s" % path end @@ -211,8 +211,8 @@ class TestSnippets < Test::Unit::TestCase path1 = "/tmp/argumenttest1" path2 = "/tmp/argumenttest2" - file1 = @configuration.resource(:file, path1) - file2 = @configuration.resource(:file, path2) + file1 = @file[path1] + file2 = @file[path2] assert_file(path1) assert_mode_equal(0755, path1) @@ -231,7 +231,7 @@ class TestSnippets < Test::Unit::TestCase } paths.each { |path| - file = @configuration.resource(:file, path) + file = @file[path] assert(file, "File %s is missing" % path) assert_mode_equal(0755, path) } @@ -241,7 +241,7 @@ class TestSnippets < Test::Unit::TestCase paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } paths.each { |path| - file = @configuration.resource(:file, path) + file = @file[path] assert_file(path) assert_mode_equal(0755, path) } @@ -262,7 +262,7 @@ class TestSnippets < Test::Unit::TestCase dir = "/tmp/testdirtest" assert_file(file) assert_file(dir) - assert_equal(:directory, @configuration.resource(:file, dir).should(:ensure), "Directory is not set to be a directory") + assert_equal(:directory, @file[dir].should(:ensure), "Directory is not set to be a directory") end def snippet_scopetest @@ -349,7 +349,7 @@ class TestSnippets < Test::Unit::TestCase }.each { |count, str| path = "/tmp/singlequote%s" % count assert_file(path) - assert_equal(str, @configuration.resource(:file, path).should(:content)) + assert_equal(str, @file[path].should(:content)) } end @@ -387,20 +387,21 @@ class TestSnippets < Test::Unit::TestCase end def snippet_emptyexec - assert(@configuration.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec") + assert(Puppet::Type.type(:exec)["touch /tmp/emptyexectest"], + "Did not create exec") end def snippet_multisubs path = "/tmp/multisubtest" assert_file(path) - file = @configuration.resource(:file, path) + file = @file[path] assert_equal("sub2", file.should(:content), "sub2 did not override content") assert_mode_equal(0755, path) end def snippet_collection assert_file("/tmp/colltest1") - assert_nil(@configuration.resource(:file, "/tmp/colltest2"), "Incorrectly collected file") + assert_nil(@file["/tmp/colltest2"], "Incorrectly collected file") end def snippet_virtualresources diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb index 83509733e..d9bd6b2b6 100644 --- a/test/lib/puppettest/support/utils.rb +++ b/test/lib/puppettest/support/utils.rb @@ -27,7 +27,7 @@ module PuppetTest::Support::Utils if resources[0].is_a?(Puppet::Node::Configuration) config = resources.shift unless resources.empty? - resources.each { |r| config.add_resource(r) unless config.resource(r.class.name, r.title) } + resources.each { |r| config.add_resource r } end elsif resources[0].is_a?(Puppet.type(:component)) raise ArgumentError, "resource2config() no longer accpts components" diff --git a/test/network/client/client.rb b/test/network/client/client.rb index 8d08bd3d7..4a7e9cdb6 100755 --- a/test/network/client/client.rb +++ b/test/network/client/client.rb @@ -140,6 +140,35 @@ class TestClient < Test::Unit::TestCase } end + def test_classfile + Puppet[:code] = "class yaytest {}\n class bootest {}\n include yaytest, bootest" + + Puppet::Node::Facts.indirection.stubs(:save) + + master = client = nil + assert_nothing_raised() { + master = Puppet::Network::Handler.master.new( + :Local => false + ) + } + assert_nothing_raised() { + client = Puppet::Network::Client.master.new( + :Master => master + ) + } + + # Fake that it's local, so it creates the class file + client.local = false + + # We can't guarantee class ordering + client.expects(:setclasses).with do |array| + array.length == 2 and array.include?("yaytest") and array.include?("bootest") + end + assert_nothing_raised { + client.getconfig + } + end + def test_client_loading # Make sure we don't get a failure but that we also get nothing back assert_nothing_raised do diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 0caba4bd2..7216af936 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -332,6 +332,39 @@ end assert(FileTest.exists?(file), "file was not created on second run") end + def test_default_objects + # Make sure they start out missing + assert_nil(Puppet::Type.type(:filebucket)["puppet"], + "default filebucket already exists") + assert_nil(Puppet::Type.type(:schedule)["daily"], + "default schedules already exists") + + master = mkclient() + + # Now make sure they got created + assert(Puppet::Type.type(:filebucket)["puppet"], + "default filebucket not found") + assert(Puppet::Type.type(:schedule)["daily"], + "default schedules not found") + + # clear everything, and make sure we can recreate them + Puppet::Type.allclear + assert_nil(Puppet::Type.type(:filebucket)["puppet"], + "default filebucket not removed") + assert_nil(Puppet::Type.type(:schedule)["daily"], + "default schedules not removed") + assert_nothing_raised { master.mkdefault_objects } + assert(Puppet::Type.type(:filebucket)["puppet"], + "default filebucket not found") + assert(Puppet::Type.type(:schedule)["daily"], + "default schedules not found") + + + # Make sure we've got schedules + assert(Puppet::Type.type(:schedule)["hourly"], "Could not retrieve hourly schedule") + assert(Puppet::Type.type(:filebucket)["puppet"], "Could not retrieve default bucket") + end + # #540 - make sure downloads aren't affected by noop def test_download_in_noop source = tempfile @@ -517,6 +550,24 @@ end assert_equal(facts["environment"], Puppet[:environment], "Did not add environment to client facts") end + # This is partially to fix #532, but also to save on memory. + def test_remove_objects_after_every_run + client = mkclient + + ftype = Puppet::Type.type(:file) + file = ftype.create :title => "/what/ever", :ensure => :present + config = Puppet::Node::Configuration.new + config.add_resource(file) + + config.expects :apply + + client.configuration = config + client.expects(:getconfig) + client.run + + assert_nil(ftype[@createdfile], "file object was not removed from memory") + end + # #685 def test_http_failures_do_not_kill_puppetd client = mkclient diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb index 8703700ea..3539169dc 100755 --- a/test/network/handler/fileserver.rb +++ b/test/network/handler/fileserver.rb @@ -8,11 +8,6 @@ require 'puppet/network/handler/fileserver' class TestFileServer < Test::Unit::TestCase include PuppetTest - def setup - super - Facter.stubs(:to_hash).returns({}) - end - def mkmount(path = nil) mount = nil name = "yaytest" @@ -151,6 +146,10 @@ class TestFileServer < Test::Unit::TestCase list = server.list(sfile, :ignore, true, false) } + assert_nothing_raised { + file = Puppet.type(:file)[tmpfile] + } + output = "/\tfile" # verify it got listed as a file @@ -944,11 +943,10 @@ allow * end # Now, check that they use Facter info - Facter.stubs(:value).with("hostname").returns("myhost") - Facter.stubs(:value).with("domain").returns("mydomain") - local = "myhost" - domain = "mydomain" + Puppet.notice "The following messages are normal" client = nil + local = Facter["hostname"].value + domain = Facter["domain"].value fqdn = [local, domain].join(".") {"%h" => local, # Short name "%H" => fqdn, # Full name @@ -956,7 +954,6 @@ allow * "%%" => "%", # escape "%o" => "%o" # other }.each do |pat, repl| - Puppet.expects(:notice) check.call(client, pat, repl) end @@ -1135,8 +1132,6 @@ allow * def test_failures # create a server with the file server = nil - Facter.stubs(:[]).with("hostname").returns("myhost") - Facter.stubs(:[]).with("domain").returns("mydomain") config = tempfile [ diff --git a/test/network/handler/resource.rb b/test/network/handler/resource.rb index 247014a47..0d6373160 100755 --- a/test/network/handler/resource.rb +++ b/test/network/handler/resource.rb @@ -3,12 +3,10 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/utils' require 'base64' require 'cgi' class TestResourceServer < Test::Unit::TestCase - include PuppetTest include PuppetTest::ServerTest def verify_described(type, described) @@ -181,6 +179,9 @@ class TestResourceServer < Test::Unit::TestCase require 'etc' + # Make the example schedules, for testing + Puppet::Type.type(:schedule).mkdefaultschedules + Puppet::Type.eachtype do |type| unless type.respond_to? :instances Puppet.warning "%s does not respond to :instances" % type.name diff --git a/test/other/overrides.rb b/test/other/overrides.rb index 800eab1b7..272f78e30 100755 --- a/test/other/overrides.rb +++ b/test/other/overrides.rb @@ -25,27 +25,28 @@ class TestOverrides < Test::Unit::TestCase baseobj = nil basefile = File.join(basedir, "file") - config = mk_configuration - - baseobj = config.create_resource(:file, - :title => "base", - :path => basedir, - :recurse => true, - :mode => "755" - ) + assert_nothing_raised("Could not create base obj") { + baseobj = Puppet.type(:file).create( + :title => "base", + :path => basedir, + :recurse => true, + :mode => "755" + ) + } subobj = nil subdir = File.join(basedir, "0") subfile = File.join(subdir, "file") + assert_nothing_raised("Could not create sub obj") { + subobj = Puppet.type(:file).create( + :title => "sub", + :path => subdir, + :recurse => true, + :mode => "644" + ) + } - subobj = config.create_resource(:file, - :title => "sub", - :path => subdir, - :recurse => true, - :mode => "644" - ) - - config.apply + assert_apply(baseobj, subobj) assert(File.stat(basefile).mode & 007777 == 0755) assert(File.stat(subfile).mode & 007777 == 0644) diff --git a/test/other/relationships.rb b/test/other/relationships.rb index fe1ae1ac4..0f2a103fe 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -61,20 +61,19 @@ class TestRelationships < Test::Unit::TestCase :notify => true, :before => true} refreshers = [:subscribe, :notify] [:require, :subscribe, :notify, :before].each do |param| - config = mk_configuration # Create three files to generate our events and three # execs to receive them files = [] execs = [] 3.times do |i| - files << config.create_resource(:file, + files << Puppet::Type.newfile( :title => "file#{i}", :path => tempfile(), :ensure => :file ) path = tempfile() - execs << config.create_resource(:exec, + execs << Puppet::Type.newexec( :title => "notifytest#{i}", :path => "/usr/bin:/bin", :command => "touch #{path}", @@ -166,9 +165,7 @@ class TestRelationships < Test::Unit::TestCase :ensure => :directory) exec = Puppet::Type.newexec(:title => "myexec", :cwd => path, :command => "/bin/echo") - - config = mk_configuration(file, exec) - + reqs = nil assert_nothing_raised do reqs = exec.autorequire @@ -176,10 +173,13 @@ class TestRelationships < Test::Unit::TestCase assert_instance_of(Puppet::Relationship, reqs[0], "Did not return a relationship edge") assert_equal(file, reqs[0].source, "Did not set the autorequire source correctly") assert_equal(exec, reqs[0].target, "Did not set the autorequire target correctly") - + # Now make sure that these relationships are added to the # relationship graph - assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created") + config = mk_configuration(file, exec) + config.apply do |trans| + assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created") + end end def test_requires? @@ -210,7 +210,7 @@ class TestRelationships < Test::Unit::TestCase file = Puppet::Type.newfile :path => tempfile, :require => ["file", "/no/such/file"] assert_raise(Puppet::Error) do - config = mk_configuration(file) + file.builddepends end end end diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 2498cc014..8156ba478 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -6,10 +6,8 @@ require 'puppet' require 'puppettest' require 'mocha' require 'puppettest/support/resources' -require 'puppettest/support/utils' class TestTransactions < Test::Unit::TestCase - include PuppetTest include PuppetTest::FileTesting include PuppetTest::Support::Resources class Fakeprop <Puppet::Property @@ -431,25 +429,26 @@ class TestTransactions < Test::Unit::TestCase # Make sure that unscheduled and untagged objects still respond to events def test_unscheduled_and_untagged_response - config = mk_configuration - config.add_resource(*(Puppet::Type.type(:schedule).create_default_resources)) + Puppet::Type.type(:schedule).mkdefaultschedules Puppet[:ignoreschedules] = false - file = config.create_resource(:file, + file = Puppet.type(:file).create( :name => tempfile(), :ensure => "file", :backup => false ) fname = tempfile() - exec = config.create_resource(:exec, + exec = Puppet.type(:exec).create( :name => "touch %s" % fname, :path => "/usr/bin:/bin", :schedule => "monthly", :subscribe => ["file", file.name] ) + config = mk_configuration(file, exec) + # Run it once - config.apply + assert_apply(config) assert(FileTest.exists?(fname), "File did not get created") assert(!exec.scheduled?, "Exec is somehow scheduled") @@ -605,7 +604,8 @@ class TestTransactions < Test::Unit::TestCase end %w{ya ra y r}.each do |name| - assert(trans.configuration.vertex?(config.resource(:generator, name)), "Generated %s was not a vertex" % 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 @@ -615,8 +615,10 @@ class TestTransactions < Test::Unit::TestCase end %w{ya ra y r}.each do |name| - assert(!trans.configuration.vertex?(config.resource(:generator, name)), "Generated vertex %s was not removed from graph" % name) - assert_nil(config.resource(:generator, name), "Generated vertex %s was not removed from class" % 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) end end @@ -643,7 +645,7 @@ class TestTransactions < Test::Unit::TestCase assert_nothing_raised("failed to apply yay") do trans.eval_resource(yay) end - ya = config.resource(:generator, "ya") + ya = type["ya"] assert(ya, "Did not generate ya") assert(trans.relationship_graph.vertex?(ya), "Did not add ya to rel_graph") @@ -656,11 +658,11 @@ class TestTransactions < Test::Unit::TestCase # Now make sure it in turn eval_generates appropriately assert_nothing_raised("failed to apply yay") do - trans.eval_resource(config.resource(:generator, "ya")) + trans.eval_resource(type["ya"]) end %w{y}.each do |name| - res = config.resource(:generator, name) + res = type[name] assert(res, "Did not generate %s" % name) assert(trans.relationship_graph.vertex?(res), "Did not add %s to rel_graph" % name) @@ -668,7 +670,7 @@ class TestTransactions < Test::Unit::TestCase end assert_nothing_raised("failed to eval_generate with nil response") do - trans.eval_resource(config.resource(:generator, "y")) + trans.eval_resource(type["y"]) end assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay") @@ -676,7 +678,7 @@ class TestTransactions < Test::Unit::TestCase trans.eval_resource(rah) end - ra = config.resource(:generator, "ra") + ra = type["ra"] assert(ra, "Did not generate ra") assert(trans.relationship_graph.vertex?(ra), "Did not add ra to rel_graph" % name) @@ -695,9 +697,9 @@ class TestTransactions < Test::Unit::TestCase end %w{ya ra y r}.each do |name| - assert(!trans.relationship_graph.vertex?(config.resource(:generator, name)), + assert(!trans.relationship_graph.vertex?(type[name]), "Generated vertex %s was not removed from graph" % name) - assert_nil(config.resource(:generator, name), + assert_nil(type[name], "Generated vertex %s was not removed from class" % name) end diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb index 862beeadc..4427238bf 100755 --- a/test/ral/types/basic.rb +++ b/test/ral/types/basic.rb @@ -68,6 +68,13 @@ class TestBasic < Test::Unit::TestCase assert_equal("echo", @command.title) end + def test_object_retrieval + [@command, @configfile].each { |obj| + assert_equal(obj.class[obj.name].object_id, obj.object_id, + "%s did not match class version" % obj.ref) + } + end + def test_paths [@configfile, @command, @component].each { |obj| assert_nothing_raised { diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb index d6f29efe4..a9a00240c 100755 --- a/test/ral/types/cron.rb +++ b/test/ral/types/cron.rb @@ -150,6 +150,20 @@ class TestCron < Test::Unit::TestCase end end + def test_makeandretrievecron + %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name| + cron = mkcron(name) + comp = mk_configuration(name, cron) + trans = assert_events([:cron_created], comp, name) + + cron.provider.class.prefetch + cron = nil + + assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron") + assert_instance_of(Puppet.type(:cron), cron) + end + end + # Do input validation testing on all of the parameters. def test_arguments values = { diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb index ed0ea9980..11a6d4055 100755 --- a/test/ral/types/exec.rb +++ b/test/ral/types/exec.rb @@ -203,45 +203,42 @@ class TestExec < Test::Unit::TestCase ) comp = mk_configuration("Testing", file, exec) - Puppet::Node::Facts.indirection.stubs(:terminus_class).returns(:memory) assert_events([:file_created, :executed_command], comp) end # Verify that we auto-require any managed scripts. def test_autorequire_files - config = mk_configuration - exe = tempfile() oexe = tempfile() sh = %x{which sh} File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" } - file = config.create_resource(:file, + file = Puppet.type(:file).create( :path => oexe, :source => exe, :mode => 755 ) basedir = File.dirname(oexe) - baseobj = config.create_resource(:file, + baseobj = Puppet.type(:file).create( :path => basedir, :source => exe, :mode => 755 ) - ofile = config.create_resource(:file, + ofile = Puppet.type(:file).create( :path => exe, :mode => 755 ) - exec = config.create_resource(:exec, + exec = Puppet.type(:exec).create( :command => oexe, :path => ENV["PATH"], :cwd => basedir ) - cat = config.create_resource(:exec, + cat = Puppet.type(:exec).create( :command => "cat %s %s" % [exe, oexe], :path => ENV["PATH"] ) diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index 8435855e6..73095a783 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -3,12 +3,10 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/utils' require 'fileutils' class TestFile < Test::Unit::TestCase include PuppetTest::FileTesting - include PuppetTest::Support::Utils # hmmm # this is complicated, because we store references to the created # objects in a central store @@ -34,8 +32,6 @@ class TestFile < Test::Unit::TestCase @file = Puppet::Type.type(:file) $method = @method_name Puppet[:filetimeout] = -1 - Facter.stubs(:each) - Facter.stubs(:to_hash).returns({}) end def teardown @@ -518,7 +514,7 @@ class TestFile < Test::Unit::TestCase test = File.join(path, "file") File.open(test, "w") { |f| f.puts "yay" } assert_nothing_raised() { ret = dir.localrecurse(true) } - fileobj = config.resource(:file, test) + fileobj = @file[test] assert(fileobj, "child object was not created") assert_equal([fileobj], ret, "child object was not returned") @@ -562,7 +558,7 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised() { ret = dir.localrecurse(true) } assert_equal([bad], ret.collect { |f| f.title }, "purge failed") - badobj = config.resource(:file, bad) + badobj = @file[bad] assert(badobj, "did not create bad object") end @@ -758,6 +754,43 @@ class TestFile < Test::Unit::TestCase assert(file.insync?(currentvalues)) end + def test_remove + basedir = tempfile() + subdir = File.join(basedir, "this") + FileUtils.mkdir_p(subdir) + + dir = nil + assert_nothing_raised { + dir = Puppet.type(:file).create( + :path => basedir, + :recurse => true, + :check => %w{owner mode group} + ) + } + mk_configuration dir + + assert_nothing_raised { + dir.eval_generate + } + + obj = nil + assert_nothing_raised { + obj = Puppet.type(:file)[subdir] + } + + assert(obj, "Could not retrieve subdir object") + + assert_nothing_raised { + obj.remove(true) + } + + assert_nothing_raised { + obj = Puppet.type(:file)[subdir] + } + + assert_nil(obj, "Retrieved removed object") + end + def test_path dir = tempfile() @@ -777,14 +810,14 @@ class TestFile < Test::Unit::TestCase :check => %w{mode owner group} ) } - config = mk_configuration dirobj + mk_configuration dirobj assert_nothing_raised { dirobj.eval_generate } assert_nothing_raised { - file = config.resource(:file, path) + file = dirobj.class[path] } assert(file, "Could not retrieve file object") @@ -796,14 +829,12 @@ class TestFile < Test::Unit::TestCase basedir = tempfile() subfile = File.join(basedir, "subfile") - config = Puppet::Node::Configuration.new - - baseobj = config.create_resource(:file, + baseobj = Puppet.type(:file).create( :name => basedir, :ensure => "directory" ) - subobj = config.create_resource(:file, + subobj = Puppet.type(:file).create( :name => subfile, :ensure => "file" ) @@ -1098,17 +1129,18 @@ class TestFile < Test::Unit::TestCase file = tempfile() newfile = tempfile() - config = mk_configuration - File.open(file, "w", 0411) { |f| f.puts "yayness" } - resource = config.create_resource(:file, - :path => file, :content => "rahness\n", :backup => ".puppet-bak" - ) + obj = nil + assert_nothing_raised { + obj = Puppet::Type.type(:file).create( + :path => file, :content => "rahness\n", :backup => ".puppet-bak" + ) + } - assert_apply(config) + assert_apply(obj) - backupfile = file + resource[:backup] + backupfile = file + obj[:backup] @@tmpfiles << backupfile assert(FileTest.exists?(backupfile), "Backup file %s does not exist" % backupfile) @@ -1119,15 +1151,13 @@ class TestFile < Test::Unit::TestCase bucket = "bucket" bpath = tempfile() Dir.mkdir(bpath) - config.create_resource(:filebucket, + Puppet::Type.type(:filebucket).create( :title => bucket, :path => bpath ) - resource[:backup] = bucket - resource[:content] = "New content" - - resource.finish - assert_apply(config) + obj[:backup] = bucket + obj[:content] = "New content" + assert_apply(obj) md5 = "18cc17fa3047fcc691fdf49c0a7f539a" dir, file, pathfile = Puppet::Network::Handler.filebucket.paths(bpath, md5) @@ -1256,20 +1286,19 @@ class TestFile < Test::Unit::TestCase # this file should get removed File.open(purgee, "w") { |f| f.puts "footest" } - config = mk_configuration - - lfobj = config.create_resource(:file, + lfobj = Puppet::Type.newfile( :title => "localfile", :path => localfile, :content => "rahtest", :backup => false ) - destobj = config.create_resource(:file, :title => "destdir", :path => destdir, + destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir, :source => sourcedir, :backup => false, :recurse => true) + config = mk_configuration(lfobj, destobj) config.apply assert(FileTest.exists?(dsourcefile), "File did not get copied") @@ -1402,11 +1431,10 @@ class TestFile < Test::Unit::TestCase :link => proc { File.symlink(linkdest, path) } } - config = mk_configuration - - bucket = config.create_resource :filebucket, :name => "main", :path => tempfile() + bucket = Puppet::Type.newfilebucket :name => "main", :path => tempfile() - obj = config.create_resource :file, :path => path, :force => true, :links => :manage + obj = Puppet::Type.newfile :path => path, :force => true, + :links => :manage Puppet[:trace] = true ["main", false].each do |backup| @@ -1529,17 +1557,15 @@ class TestFile < Test::Unit::TestCase dfiles = [File.join(dest, "1"), File.join(dest, "dir", "2")] bpath = tempfile - - config = mk_configuration - bucket = config.create_resource :filebucket, :name => "rtest", :path => bpath + bucket = Puppet::Type.type(:filebucket).create :name => "rtest", :path => bpath dipper = bucket.bucket dipper = Puppet::Network::Handler.filebucket.new( :Path => bpath ) assert(dipper, "did not receive bucket client") - file = config.create_resource :file, :path => dest, :source => source, :recurse => true, :backup => "rtest" + file = Puppet::Type.newfile :path => dest, :source => source, :recurse => true, :backup => "rtest" - config.apply + assert_apply(file) dfiles.each do |f| assert(FileTest.exists?(f), "destfile %s was not created" % f) end @@ -1549,7 +1575,7 @@ class TestFile < Test::Unit::TestCase f.puts "boo: %s" % File.basename(sf) } } - config.apply + assert_apply(file) dfiles.each do |f| assert_equal("boo: %s\n" % File.basename(f), File.read(f), "file was not copied correctly") @@ -1574,8 +1600,7 @@ class TestFile < Test::Unit::TestCase def test_backup path = tempfile() - config = Puppet::Node::Configuration.new - file = config.create_resource :file, :path => path, :content => "yay" + file = Puppet::Type.newfile :path => path, :content => "yay" [false, :false, "false"].each do |val| assert_nothing_raised do @@ -1604,7 +1629,7 @@ class TestFile < Test::Unit::TestCase assert_equal("main", file.bucket, "file's bucket was not set") # And then an existing bucket - obj = config.create_resource :filebucket, :name => "testing" + obj = Puppet::Type.type(:filebucket).create :name => "testing" bucket = obj.bucket assert_nothing_raised do @@ -1620,12 +1645,12 @@ 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 - config = mk_configuration obj + mk_configuration obj assert_equal("/%s" % obj.ref, obj.path) list = obj.eval_generate - fileobj = config.resource(:file, file) + fileobj = obj.class[file] assert(fileobj, "did not generate file object") assert_equal("/%s" % fileobj.ref, fileobj.path, "did not generate correct subfile path") end @@ -1642,8 +1667,7 @@ class TestFile < Test::Unit::TestCase # Testing #434 def test_stripping_extra_slashes_during_lookup - config = mk_configuration - file = config.create_resource(:file, :path => "/one/two") + file = Puppet::Type.newfile(:path => "/one/two") %w{/one/two/ /one/two /one//two //one//two//}.each do |path| assert(Puppet::Type.type(:file)[path], "could not look up file via path %s" % path) end @@ -1738,14 +1762,14 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised("Failure when recursing") do children = obj.eval_generate end - assert(config.resource(:file, subdir), "did not create subdir object") + 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 - oobj = config.resource(:file, other) + oobj = obj.class[other] assert(oobj, "did not create other object") assert_nothing_raised do @@ -1756,14 +1780,12 @@ class TestFile < Test::Unit::TestCase # Make sure we default to the "puppet" filebucket, rather than a string def test_backup_defaults_to_bucket path = tempfile - config = Puppet::Node::Configuration.new - config.add_resource(Puppet::Type.type(:filebucket).create_default_resources) - file = config.create_resource :file, :path => path, :content => 'some content' + file = Puppet::Type.newfile(:path => path, :content => 'some content') file.finish - assert_instance_of(Puppet::Network::Client.dipper, file.bucket, + assert_instance_of(Puppet::Network::Client::Dipper, file.bucket, "did not default to a filebucket for backups") - assert_equal(config.resource(:filebucket, "puppet").bucket, file.bucket, + assert_equal(Puppet::Type.type(:filebucket)["puppet"].bucket, file.bucket, "did not default to the 'puppet' filebucket") end @@ -1782,7 +1804,7 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised do children = obj.eval_generate end - fobj = config.resource(:file,file) + fobj = obj.class[file] assert(fobj, "did not create file object") assert(fobj.should(:ensure) != :directory, "ensure was passed to child") end diff --git a/test/ral/types/file/target.rb b/test/ral/types/file/target.rb index cc53e2645..f5cbe4a45 100755 --- a/test/ral/types/file/target.rb +++ b/test/ral/types/file/target.rb @@ -3,11 +3,9 @@ require File.dirname(__FILE__) + '/../../../lib/puppettest' require 'puppettest' -require 'puppettest/support/assertions' require 'fileutils' class TestFileTarget < Test::Unit::TestCase - include PuppetTest include PuppetTest::FileTesting def setup @@ -46,7 +44,7 @@ class TestFileTarget < Test::Unit::TestCase def test_linkrecurse dest = tempfile() link = @file.create :path => tempfile(), :recurse => true, :ensure => dest - config = mk_configuration link + mk_configuration link ret = nil @@ -64,8 +62,7 @@ class TestFileTarget < Test::Unit::TestCase assert_equal(:directory, link.should(:ensure), "ensure was not set to directory") assert_equal([File.join(link.title, "one")], ret.collect { |f| f.title }, "Did not get linked file") - oneobj = config.resource(:file, File.join(link.title, "one")) - + oneobj = @file[File.join(link.title, "one")] assert_equal(one, oneobj.should(:target), "target was not set correctly") oneobj.remove @@ -84,7 +81,7 @@ class TestFileTarget < Test::Unit::TestCase "Did not get links back") returns.each do |path| - obj = config.resource(:file, path) + obj = @file[path] assert(path, "did not get obj for %s" % path) sdest = File.join(dest, File.basename(path)) assert_equal(sdest, obj.should(:target), @@ -102,14 +99,15 @@ class TestFileTarget < Test::Unit::TestCase system("touch %s" % file) link = nil - config = mk_configuration - link = config.create_resource(:file, - :ensure => source, - :path => path, - :recurse => true - ) + assert_nothing_raised { + link = Puppet.type(:file).create( + :ensure => source, + :path => path, + :recurse => true + ) + } - config.apply + assert_apply(link) sublink = File.join(path, "subdir") linkpath = File.join(sublink, "file") @@ -118,7 +116,7 @@ class TestFileTarget < Test::Unit::TestCase assert(File.symlink?(linkpath), "path is not a link") assert_equal(file, File.readlink(linkpath)) - assert_nil(config.resource(:file, sublink), "objects were not removed") + assert_nil(@file[sublink], "objects were not removed") assert_equal([], link.evaluate, "Link is not in sync") end diff --git a/test/ral/types/filebucket.rb b/test/ral/types/filebucket.rb index 3681febf4..ecfe0e167 100755 --- a/test/ral/types/filebucket.rb +++ b/test/ral/types/filebucket.rb @@ -3,12 +3,10 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/utils' require 'fileutils' class TestFileBucket < Test::Unit::TestCase include PuppetTest::FileTesting - include PuppetTest::Support::Utils # hmmm # this is complicated, because we store references to the created # objects in a central store @@ -65,9 +63,14 @@ class TestFileBucket < Test::Unit::TestCase def test_simplebucket name = "yayness" bucketpath = tempfile() - bucket_resource = mkbucket(name, bucketpath) + mkbucket(name, bucketpath) - bucket = bucket_resource.bucket + bucket = nil + assert_nothing_raised { + bucket = Puppet.type(:filebucket).bucket(name) + } + + assert_instance_of(Puppet::Network::Client.dipper, bucket) md5 = nil newpath = tempfile() @@ -106,16 +109,15 @@ class TestFileBucket < Test::Unit::TestCase end def test_fileswithbuckets - Facter.stubs(:to_hash).returns({}) name = "yayness" - resource = mkbucket(name, tempfile()) + mkbucket(name, tempfile()) - config = mk_configuration resource - - bucket = resource.bucket + bucket = nil + assert_nothing_raised { + bucket = Puppet.type(:filebucket).bucket(name) + } file = mktestfile() - config.add_resource(file) assert_nothing_raised { file[:backup] = name } @@ -131,7 +133,7 @@ class TestFileBucket < Test::Unit::TestCase # file[:backup] = true #} - config.apply + assert_apply(file) # so, we've now replaced the file with the opath file assert_equal( diff --git a/test/ral/types/fileignoresource.rb b/test/ral/types/fileignoresource.rb index 501672ab7..5c7536453 100755 --- a/test/ral/types/fileignoresource.rb +++ b/test/ral/types/fileignoresource.rb @@ -3,13 +3,11 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/utils' require 'cgi' require 'fileutils' class TestFileIgnoreSources < Test::Unit::TestCase include PuppetTest::FileTesting - include PuppetTest::Support::Utils def setup super @@ -20,7 +18,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase end end - #This is not needed unless using md5 (correct me if I'm wrong) +#This is not needed unless using md5 (correct me if I'm wrong) def initstorage Puppet::Util::Storage.init Puppet::Util::Storage.load @@ -32,7 +30,6 @@ class TestFileIgnoreSources < Test::Unit::TestCase end def test_ignore_simple_source - Facter.stubs(:to_hash).returns({}) #Temp directory to run tests in path = tempfile() @@ -92,7 +89,6 @@ class TestFileIgnoreSources < Test::Unit::TestCase end def test_ignore_with_wildcard - Facter.stubs(:to_hash).returns({}) #Temp directory to run tests in path = tempfile() @@tmpfiles.push path @@ -162,7 +158,6 @@ class TestFileIgnoreSources < Test::Unit::TestCase end def test_ignore_array - Facter.stubs(:to_hash).returns({}) #Temp directory to run tests in path = tempfile() @@tmpfiles.push path diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb index bfbc185e3..1f22fc9e0 100755 --- a/test/ral/types/filesources.rb +++ b/test/ral/types/filesources.rb @@ -3,13 +3,11 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/assertions' require 'cgi' require 'fileutils' require 'mocha' class TestFileSources < Test::Unit::TestCase - include PuppetTest include PuppetTest::FileTesting def setup super @@ -287,7 +285,7 @@ class TestFileSources < Test::Unit::TestCase end assert_equal([destfile], sourced, "Did not get correct list of sourced objects") - dfileobj = config.resource(:file, destfile) + dfileobj = @file[destfile] assert(dfileobj, "Did not create destfile object") assert_equal([dfileobj], result) @@ -303,7 +301,7 @@ class TestFileSources < Test::Unit::TestCase result, sourced = obj.sourcerecurse(true) end assert_equal([destfile], sourced, "Did not get correct list of sourced objects") - dfileobj = config.resource(:file, destfile) + dfileobj = @file[destfile] assert(dfileobj, "Did not create destfile object with a missing source") assert_equal([dfileobj], result) dfileobj.remove @@ -417,6 +415,9 @@ class TestFileSources < Test::Unit::TestCase def test_sources_with_deleted_destfiles fromdir, todir, one, two = run_complex_sources assert(FileTest.exists?(todir)) + + # We shouldn't have a 'two' file object in memory + assert_nil(@file[two], "object for 'two' is still in memory") # then delete a file File.unlink(two) @@ -938,6 +939,7 @@ class TestFileSources < Test::Unit::TestCase end File.unlink(file1) File.unlink(file3) + Puppet.err :yay assert_apply(obj) assert(FileTest.exists?(file1), "File from source 1 was not copied") diff --git a/test/ral/types/host.rb b/test/ral/types/host.rb index 5e91a8c58..1013651c5 100755 --- a/test/ral/types/host.rb +++ b/test/ral/types/host.rb @@ -154,13 +154,11 @@ class TestHost < Test::Unit::TestCase def test_puppetalias host = mkhost() - config = mk_configuration(host) - assert_nothing_raised { host[:alias] = "testing" } - same = config.resource(:host, "testing") + same = host.class["testing"] assert(same, "Could not retrieve by alias") end end diff --git a/test/ral/types/package.rb b/test/ral/types/package.rb index d09f7d9b7..7d0caa0ba 100755 --- a/test/ral/types/package.rb +++ b/test/ral/types/package.rb @@ -9,7 +9,6 @@ require 'mocha' $platform = Facter["operatingsystem"].value class TestPackages < Test::Unit::TestCase - include PuppetTest include PuppetTest::FileTesting def setup super diff --git a/test/ral/types/parameter.rb b/test/ral/types/parameter.rb index 7eda05bb5..1d402cb85 100755 --- a/test/ral/types/parameter.rb +++ b/test/ral/types/parameter.rb @@ -113,7 +113,8 @@ class TestParameter < Test::Unit::TestCase inst = type.create(:name => "test") - config = mk_configuration(inst) + config = mk_configuration + inst.configuration = config assert_nothing_raised("Could not create shadowed param") { inst[:alias] = "foo" @@ -130,7 +131,7 @@ class TestParameter < Test::Unit::TestCase assert_instance_of(param, obj, "alias is an instance of the wrong class") # Make sure the alias got created - assert(config.resource(inst.class.name, "foo"), "Did not retrieve object by its alias") + assert(type["foo"], "Did not retrieve object by its alias") # Now try it during initialization other = nil diff --git a/test/ral/types/schedule.rb b/test/ral/types/schedule.rb index 06698f288..2870b8db6 100755 --- a/test/ral/types/schedule.rb +++ b/test/ral/types/schedule.rb @@ -242,23 +242,24 @@ class TestSchedule < Test::Unit::TestCase s = mksched s[:period] = :hourly + f = nil path = tempfile() - f = Puppet.type(:file).create( - :name => path, - :schedule => s.name, - :ensure => "file" - ) - - config = mk_configuration(s, f) + assert_nothing_raised { + f = Puppet.type(:file).create( + :name => path, + :schedule => s.name, + :ensure => "file" + ) + } assert(f.scheduled?, "File is not scheduled to run") - config.apply + assert_apply(f) assert(! f.scheduled?, "File is scheduled to run already") File.unlink(path) - config.apply + assert_apply(f) assert(! FileTest.exists?(path), "File was created when not scheduled") end @@ -286,17 +287,25 @@ class TestSchedule < Test::Unit::TestCase # Verify that each of our default schedules exist def test_defaultschedules - defaults = nil - assert_nothing_raised("Could not create default schedules") do - defaults = Puppet.type(:schedule).create_default_resources + assert_nothing_raised do + Puppet.type(:schedule).mkdefaultschedules end s = {} %w{puppet hourly daily weekly monthly}.each { |period| - schedule = defaults.find { |r| r.title == period } - assert(schedule, "Could not find %s schedule" % + obj = Puppet.type(:schedule)[period] + assert(obj, "Could not find %s schedule" % period) - s[period] = schedule + s[period] = obj } + assert_nothing_raised("Could not rerun mkdefaultschedules") do + Puppet.type(:schedule).mkdefaultschedules + end + s.each do |period, obj| + newobj = Puppet.type(:schedule)[period] + assert(newobj, "somehow lost schedule for %s" % period) + assert_equal(obj.object_id, newobj.object_id, + "created a new schedule instead of reusing existing one") + end end def test_period_with_repeat diff --git a/test/ral/types/sshkey.rb b/test/ral/types/sshkey.rb index a2daf6cfb..c99f7562a 100755 --- a/test/ral/types/sshkey.rb +++ b/test/ral/types/sshkey.rb @@ -102,8 +102,6 @@ class TestSSHKey < Test::Unit::TestCase def test_moddingkey key = mkkey() - config = mk_configuration(key) - assert_events([:sshkey_created], key) key.retrieve @@ -115,7 +113,7 @@ class TestSSHKey < Test::Unit::TestCase assert_events([:sshkey_changed], key) aliases.each do |name| - assert_equal(key, config.resource(:sshkey, name), + assert_equal(key, key.class[name], "alias was not set") end end @@ -133,13 +131,12 @@ class TestSSHKey < Test::Unit::TestCase def test_puppetalias key = mkkey() - config = mk_configuration(key) assert_nothing_raised { key[:alias] = "testing" } - same = config.resource(:sshkey, "testing") + same = key.class["testing"] assert(same, "Could not retrieve by alias") end @@ -171,14 +168,13 @@ class TestSSHKey < Test::Unit::TestCase keys << k names << k.name } - config = mk_configuration(*keys) - config.apply - + assert_apply(*keys) + keys.clear + Puppet.type(:sshkey).clear newkey = mkkey() - config = mk_configuration(newkey) + #newkey[:ensure] = :present names << newkey.name - - config.apply + assert_apply(newkey) # Verify we can retrieve that info assert_nothing_raised("Could not retrieve after second write") { diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb index 6cdf0f050..e95f26b95 100755 --- a/test/ral/types/tidy.rb +++ b/test/ral/types/tidy.rb @@ -3,10 +3,8 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' -require 'puppettest/support/utils' class TestTidy < Test::Unit::TestCase - include PuppetTest include PuppetTest::FileTesting def mktmpfile # because luke's home directory is on nfs, it can't be used for testing @@ -203,10 +201,16 @@ class TestTidy < Test::Unit::TestCase path = tempfile() File.open(path, "w") { |f| 10.times { f.puts "yayness " } } tidy = Puppet::Type.type(:tidy).create :path => path, :size => "1b" - config = mk_configuration(tidy) - - config.apply + + assert_apply(tidy) + assert(! FileTest.exists?(path), "file did not get tidied") + + # Now try one with just an age attribute. + File.open(path, "w") { |f| 10.times { f.puts "yayness " } } + tidy = Puppet::Type.type(:tidy).create :path => path, :age => "5s" + + assert_apply(tidy) assert(! FileTest.exists?(path), "file did not get tidied") end diff --git a/test/util/filetype.rb b/test/util/filetype.rb index a53fb385f..6c7ede07b 100755 --- a/test/util/filetype.rb +++ b/test/util/filetype.rb @@ -85,7 +85,8 @@ class TestFileType < Test::Unit::TestCase assert_nothing_raised("Could not call backup with no buckets") do obj.backup end - puppet = Puppet::Type.type(:filebucket).create_default_resources + puppet = type["puppet"] + assert(puppet, "Did not create default filebucket") assert_equal("one", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup") |
