From 3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Jan 2008 09:23:34 -0600 Subject: Lots o' bug-fixes toward getting rid of global resources. We still have about 60 failing tests, but some of them are the failing directory service tests (probably 20 or so), and most are simple fixes to the tests themselves. --- test/language/compile.rb | 4 +- test/network/client/master.rb | 18 ------ test/network/handler/fileserver.rb | 4 -- test/other/relationships.rb | 2 +- test/ral/types/basic.rb | 7 --- test/ral/types/cron.rb | 6 +- test/ral/types/exec.rb | 2 + test/ral/types/file.rb | 117 +++++++++++++------------------------ test/ral/types/file/target.rb | 24 ++++---- test/ral/types/filebucket.rb | 51 +--------------- test/ral/types/filesources.rb | 31 +++++----- test/ral/types/host.rb | 3 +- test/ral/types/parameter.rb | 2 +- test/util/filetype.rb | 4 +- 14 files changed, 78 insertions(+), 197 deletions(-) (limited to 'test') diff --git a/test/language/compile.rb b/test/language/compile.rb index 298493c0a..082b37a1c 100755 --- a/test/language/compile.rb +++ b/test/language/compile.rb @@ -64,7 +64,7 @@ class TestCompile < Test::Unit::TestCase end assert_instance_of(Scope, compile.topscope, "Did not create a topscope") graph = compile.instance_variable_get("@scope_graph") - assert_instance_of(GRATR::Digraph, graph, "Did not create scope graph") + assert_instance_of(Puppet::SimpleGraph, graph, "Did not create scope graph") assert(graph.vertex?(compile.topscope), "Did not add top scope as a vertex in the graph") end @@ -111,7 +111,7 @@ class TestCompile < Test::Unit::TestCase compile = mkcompile graph = compile.instance_variable_get("@scope_graph") assert_instance_of(Scope, compile.topscope, "Did not create top scope") - assert_instance_of(GRATR::Digraph, graph, "Did not create graph") + assert_instance_of(Puppet::SimpleGraph, graph, "Did not create graph") assert(graph.vertex?(compile.topscope), "The top scope is not a vertex in the graph") diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 696d08bfd..48be3cafa 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -519,24 +519,6 @@ 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::Catalog.new - config.add_resource(file) - - config.expects :apply - - client.catalog = 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 233e705c6..e4b1ac3df 100755 --- a/test/network/handler/fileserver.rb +++ b/test/network/handler/fileserver.rb @@ -146,10 +146,6 @@ 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 diff --git a/test/other/relationships.rb b/test/other/relationships.rb index bf83caf4a..dd51e3165 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -166,6 +166,7 @@ class TestRelationships < Test::Unit::TestCase exec = Puppet::Type.newexec(:title => "myexec", :cwd => path, :command => "/bin/echo") + catalog = mk_catalog(file, exec) reqs = nil assert_nothing_raised do reqs = exec.autorequire @@ -176,7 +177,6 @@ class TestRelationships < Test::Unit::TestCase # Now make sure that these relationships are added to the # relationship graph - config = mk_catalog(file, exec) config.apply do |trans| assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created") end diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb index 7bbadc5bc..daffabf58 100755 --- a/test/ral/types/basic.rb +++ b/test/ral/types/basic.rb @@ -68,13 +68,6 @@ 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 73e941894..644494bcc 100755 --- a/test/ral/types/cron.rb +++ b/test/ral/types/cron.rb @@ -153,13 +153,13 @@ class TestCron < Test::Unit::TestCase def test_makeandretrievecron %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name| cron = mkcron(name) - comp = mk_catalog(name, cron) - trans = assert_events([:cron_created], comp, name) + catalog = mk_catalog(name, cron) + trans = assert_events([:cron_created], catalog, name) cron.provider.class.prefetch cron = nil - assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron") + assert(cron = catalog.resource(:cron, name), "Could not retrieve named cron") assert_instance_of(Puppet.type(:cron), cron) end end diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb index f718f944e..396d27839 100755 --- a/test/ral/types/exec.rb +++ b/test/ral/types/exec.rb @@ -242,6 +242,8 @@ class TestExec < Test::Unit::TestCase :command => "cat %s %s" % [exe, oexe], :path => ENV["PATH"] ) + + catalog = mk_catalog(file, baseobj, ofile, exec, cat) rels = nil assert_nothing_raised do diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index aa2e63a89..1d523aa40 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -503,7 +503,7 @@ class TestFile < Test::Unit::TestCase # Create a test directory path = tempfile() dir = @file.create :path => path, :mode => 0755, :recurse => true - config = mk_catalog(dir) + catalog = mk_catalog(dir) Dir.mkdir(path) @@ -516,7 +516,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 = @file[test] + fileobj = catalog.resource(:file, test) assert(fileobj, "child object was not created") assert_equal([fileobj], ret, "child object was not returned") @@ -560,7 +560,7 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised() { ret = dir.localrecurse(true) } assert_equal([bad], ret.collect { |f| f.title }, "purge failed") - badobj = @file[bad] + badobj = catalog.resource(:file, bad) assert(badobj, "did not create bad object") end @@ -756,43 +756,6 @@ 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_catalog 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() @@ -812,15 +775,13 @@ class TestFile < Test::Unit::TestCase :check => %w{mode owner group} ) } - mk_catalog dirobj + catalog = mk_catalog dirobj assert_nothing_raised { dirobj.eval_generate } - assert_nothing_raised { - file = dirobj.class[path] - } + file = catalog.resource(:file, path) assert(file, "Could not retrieve file object") @@ -840,6 +801,7 @@ class TestFile < Test::Unit::TestCase :name => subfile, :ensure => "file" ) + catalog = mk_catalog(baseobj, subobj) edge = nil assert_nothing_raised do edge = subobj.autorequire.shift @@ -1133,14 +1095,11 @@ class TestFile < Test::Unit::TestCase File.open(file, "w", 0411) { |f| f.puts "yayness" } - obj = nil - assert_nothing_raised { - obj = Puppet::Type.type(:file).create( - :path => file, :content => "rahness\n", :backup => ".puppet-bak" - ) - } - - assert_apply(obj) + obj = Puppet::Type.type(:file).create( + :path => file, :content => "rahness\n", :backup => ".puppet-bak" + ) + catalog = mk_catalog(obj) + catalog.apply backupfile = file + obj[:backup] @@tmpfiles << backupfile @@ -1150,16 +1109,16 @@ class TestFile < Test::Unit::TestCase assert_equal(0411, filemode(backupfile), "File mode is wrong for backupfile") - bucket = "bucket" + name = "bucket" bpath = tempfile() Dir.mkdir(bpath) - Puppet::Type.type(:filebucket).create( - :title => bucket, :path => bpath - ) + bucket = Puppet::Type.type(:filebucket).create(:title => name, :path => bpath) + catalog.add_resource(bucket) - obj[:backup] = bucket + obj[:backup] = name obj[:content] = "New content" - assert_apply(obj) + catalog.finalize + catalog.apply md5 = "18cc17fa3047fcc691fdf49c0a7f539a" dir, file, pathfile = Puppet::Network::Handler.filebucket.paths(bpath, md5) @@ -1371,7 +1330,6 @@ class TestFile < Test::Unit::TestCase end assert_equal("/my/file/for/testing", file.title) - assert_equal(file, Puppet::Type.type(:file)["/my/file/for/testing"]) Puppet::Type.type(:file).clear end end @@ -1390,7 +1348,9 @@ class TestFile < Test::Unit::TestCase obj = Puppet::Type.newfile :path => link, :ensure => :link, :target => file, :recurse => false, :backup => "main" - assert_apply(obj) + catalog = mk_catalog(bucket, obj) + + catalog.apply assert_equal(file, File.readlink(link)) end @@ -1438,6 +1398,8 @@ class TestFile < Test::Unit::TestCase obj = Puppet::Type.newfile :path => path, :force => true, :links => :manage + catalog = mk_catalog(obj, bucket) + Puppet[:trace] = true ["main", false].each do |backup| obj[:backup] = backup @@ -1566,8 +1528,11 @@ class TestFile < Test::Unit::TestCase ) assert(dipper, "did not receive bucket client") file = Puppet::Type.newfile :path => dest, :source => source, :recurse => true, :backup => "rtest" + + catalog = mk_catalog(bucket, file) - assert_apply(file) + catalog.apply + dfiles.each do |f| assert(FileTest.exists?(f), "destfile %s was not created" % f) end @@ -1577,7 +1542,7 @@ class TestFile < Test::Unit::TestCase f.puts "boo: %s" % File.basename(sf) } } - assert_apply(file) + catalog.apply dfiles.each do |f| assert_equal("boo: %s\n" % File.basename(f), File.read(f), "file was not copied correctly") @@ -1603,6 +1568,9 @@ class TestFile < Test::Unit::TestCase def test_backup path = tempfile() file = Puppet::Type.newfile :path => path, :content => "yay" + + catalog = mk_catalog(file) + catalog.finalize # adds the default resources. [false, :false, "false"].each do |val| assert_nothing_raised do @@ -1632,6 +1600,7 @@ class TestFile < Test::Unit::TestCase # And then an existing bucket obj = Puppet::Type.type(:filebucket).create :name => "testing" + catalog.add_resource(obj) bucket = obj.bucket assert_nothing_raised do @@ -1647,12 +1616,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 - mk_catalog obj + catalog = mk_catalog obj assert_equal("/%s" % obj.ref, obj.path) list = obj.eval_generate - fileobj = obj.class[file] + fileobj = catalog.resource(:file, file) assert(fileobj, "did not generate file object") assert_equal("/%s" % fileobj.ref, fileobj.path, "did not generate correct subfile path") end @@ -1667,14 +1636,6 @@ class TestFile < Test::Unit::TestCase assert(! FileTest.exists?(path), "File was not removed") end - # Testing #434 - def test_stripping_extra_slashes_during_lookup - 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 - end - # Testing #438 def test_creating_properties_conflict file = tempfile() @@ -1758,20 +1719,20 @@ 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_catalog(obj) + catalog = mk_catalog(obj) children = nil assert_nothing_raised("Failure when recursing") do children = obj.eval_generate end - assert(obj.class[subdir], "did not create subdir object") + assert(catalog.resource(:file, subdir), "did not create subdir object") children.each do |c| assert_nothing_raised("Failure when recursing on %s" % c) do - c.catalog = config + c.catalog = catalog others = c.eval_generate end end - oobj = obj.class[other] + oobj = catalog.resource(:file, other) assert(oobj, "did not create other object") assert_nothing_raised do @@ -1799,12 +1760,12 @@ class TestFile < Test::Unit::TestCase obj = Puppet::Type.newfile(:path => dir, :ensure => :directory, :recurse => true) - config = mk_catalog(obj) + catalog = mk_catalog(obj) children = nil assert_nothing_raised do children = obj.eval_generate end - fobj = obj.class[file] + fobj = catalog.resource(:file, 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 035ea905b..b6c84df99 100755 --- a/test/ral/types/file/target.rb +++ b/test/ral/types/file/target.rb @@ -46,7 +46,7 @@ class TestFileTarget < Test::Unit::TestCase def test_linkrecurse dest = tempfile() link = @file.create :path => tempfile(), :recurse => true, :ensure => dest - mk_catalog link + catalog = mk_catalog(link) ret = nil @@ -64,7 +64,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 = @file[File.join(link.title, "one")] + oneobj = catalog.resource(:file, File.join(link.title, "one")) assert_equal(one, oneobj.should(:target), "target was not set correctly") oneobj.remove @@ -83,7 +83,7 @@ class TestFileTarget < Test::Unit::TestCase "Did not get links back") returns.each do |path| - obj = @file[path] + obj = catalog.resource(:file, path) assert(path, "did not get obj for %s" % path) sdest = File.join(dest, File.basename(path)) assert_equal(sdest, obj.should(:target), @@ -100,16 +100,14 @@ class TestFileTarget < Test::Unit::TestCase system("mkdir -p %s" % subdir) system("touch %s" % file) - link = nil - assert_nothing_raised { - link = Puppet.type(:file).create( - :ensure => source, - :path => path, - :recurse => true - ) - } + link = Puppet.type(:file).create( + :ensure => source, + :path => path, + :recurse => true + ) - assert_apply(link) + catalog = mk_catalog(link) + catalog.apply 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(@file[sublink], "objects were not removed") + assert_nil(catalog.resource(: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 f9706663b..28be67b0c 100755 --- a/test/ral/types/filebucket.rb +++ b/test/ral/types/filebucket.rb @@ -65,12 +65,9 @@ class TestFileBucket < Test::Unit::TestCase def test_simplebucket name = "yayness" bucketpath = tempfile() - mkbucket(name, bucketpath) + resource = mkbucket(name, bucketpath) - bucket = nil - assert_nothing_raised { - bucket = Puppet.type(:filebucket).bucket(name) - } + bucket = resource.bucket assert_instance_of(Puppet::Network::Client.dipper, bucket) @@ -109,49 +106,5 @@ class TestFileBucket < Test::Unit::TestCase assert_equal(md5, newmd5) end - - def test_fileswithbuckets - name = "yayness" - mkbucket(name, tempfile()) - - bucket = nil - assert_nothing_raised { - bucket = Puppet.type(:filebucket).bucket(name) - } - - file = mktestfile() - assert_nothing_raised { - file[:backup] = name - } - - opath = tempfile() - @@tmpfiles << opath - File.open(opath, "w") { |f| f.puts "yaytest" } - - origmd5 = File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) } - - file[:source] = opath - #assert_nothing_raised { - # file[:backup] = true - #} - - assert_apply(file) - - # so, we've now replaced the file with the opath file - assert_equal( - File.open(opath) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }, - File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) } - ) - - #File.chmod(0644, file.name) - assert_nothing_raised { - bucket.restore(file.name, origmd5) - } - - assert_equal( - origmd5, - File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) } - ) - end end diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb index 02bf8a5b3..511065c45 100755 --- a/test/ral/types/filesources.rb +++ b/test/ral/types/filesources.rb @@ -69,7 +69,7 @@ class TestFileSources < Test::Unit::TestCase :name => path ) } - config = mk_catalog(file) + catalog = mk_catalog(file) child = nil assert_nothing_raised { child = file.newchild("childtest", true) @@ -283,7 +283,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_catalog(obj) + catalog = mk_catalog(obj) result = nil sourced = nil @@ -292,12 +292,12 @@ class TestFileSources < Test::Unit::TestCase end assert_equal([destfile], sourced, "Did not get correct list of sourced objects") - dfileobj = @file[destfile] + dfileobj = catalog.resource(:file, destfile) assert(dfileobj, "Did not create destfile object") assert_equal([dfileobj], result) # Clean this up so it can be recreated - config.remove_resource(dfileobj) + catalog.remove_resource(dfileobj) # Make sure we correctly iterate over the sources nosource = tempfile() @@ -308,7 +308,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 = @file[destfile] + dfileobj = catalog.resource(:file, destfile) assert(dfileobj, "Did not create destfile object with a missing source") assert_equal([dfileobj], result) dfileobj.remove @@ -369,18 +369,16 @@ class TestFileSources < Test::Unit::TestCase tofile = nil trans = nil - assert_nothing_raised { - tofile = Puppet.type(:file).create( - :path => todir, - :recurse => true, - :backup => false, - :source => fromdir - ) - } - assert_apply(tofile) + tofile = Puppet.type(:file).create( + :path => todir, + :recurse => true, + :backup => false, + :source => fromdir + ) + catalog = mk_catalog(tofile) + catalog.apply assert(FileTest.exists?(todir), "Created dir %s does not exist" % todir) - Puppet::Type.allclear end def run_complex_sources(networked = false) @@ -422,9 +420,6 @@ 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) diff --git a/test/ral/types/host.rb b/test/ral/types/host.rb index 088f93c1f..19bc6b4bd 100755 --- a/test/ral/types/host.rb +++ b/test/ral/types/host.rb @@ -153,12 +153,13 @@ class TestHost < Test::Unit::TestCase def test_puppetalias host = mkhost() + catalog = mk_catalog(host) assert_nothing_raised { host[:alias] = "testing" } - same = host.class["testing"] + same = catalog.resource(:host, "testing") assert(same, "Could not retrieve by alias") end end diff --git a/test/ral/types/parameter.rb b/test/ral/types/parameter.rb index e1b8e00b3..04c4b0ce1 100755 --- a/test/ral/types/parameter.rb +++ b/test/ral/types/parameter.rb @@ -131,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(type["foo"], "Did not retrieve object by its alias") + assert(config.resource(type.name, "foo"), "Did not retrieve object by its alias") # Now try it during initialization other = nil diff --git a/test/util/filetype.rb b/test/util/filetype.rb index 6c7ede07b..24a968552 100755 --- a/test/util/filetype.rb +++ b/test/util/filetype.rb @@ -85,7 +85,7 @@ class TestFileType < Test::Unit::TestCase assert_nothing_raised("Could not call backup with no buckets") do obj.backup end - puppet = type["puppet"] + puppet = type.mkdefaultbucket 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") @@ -99,7 +99,7 @@ class TestFileType < Test::Unit::TestCase assert_equal("two", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup") end - if Facter["operatingsystem"].value == "Darwin" + if Facter["operatingsystem"].value == "Darwin" and Facter["operatingsystemrelease"] != "9.1.0" def test_ninfotoarray obj = nil type = nil -- cgit