diff options
author | Luke Kanies <luke@madstop.com> | 2008-01-08 09:23:34 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-01-08 09:23:34 -0600 |
commit | 3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e (patch) | |
tree | 2d47761110c458f175f6483f0424a959cbcb3f34 | |
parent | fe9b453650755e66e29eca259075e2e7245a5219 (diff) | |
download | puppet-3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e.tar.gz puppet-3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e.tar.xz puppet-3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e.zip |
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.
28 files changed, 118 insertions, 308 deletions
diff --git a/lib/puppet/metatype/container.rb b/lib/puppet/metatype/container.rb index 2bbe3f546..dbc8a3dee 100644 --- a/lib/puppet/metatype/container.rb +++ b/lib/puppet/metatype/container.rb @@ -36,7 +36,6 @@ class Puppet::Type obj.remove end @parameters.clear - self.class.delete(self) @parent = nil diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb index 3f44413f8..9d4fce909 100644 --- a/lib/puppet/metatype/instances.rb +++ b/lib/puppet/metatype/instances.rb @@ -8,11 +8,13 @@ class Puppet::Type # retrieve a named instance of the current type def self.[](name) + raise "Global resource access is deprecated" @objects[name] || @aliases[name] end # add an instance by name to the class list of instances def self.[]=(name,object) + raise "Global resource storage is deprecated" newobj = nil if object.is_a?(Puppet::Type) newobj = object @@ -126,24 +128,6 @@ class Puppet::Type # XXX This will have to change when transobjects change to using titles title = hash.name - # if the object already exists - if self.isomorphic? and retobj = self[title] - # if only one of our objects is implicit, then it's easy to see - # who wins -- the non-implicit one. - if retobj.implicit? and ! implicit - Puppet.notice "Removing implicit %s" % retobj.title - # Remove all of the objects, but do not remove their subscriptions. - retobj.remove(false) - - # now pass through and create the new object - elsif implicit - Puppet.debug "Ignoring implicit %s[%s]" % [self.name, title] - return nil - else - raise Puppet::Error, "%s is already being managed" % retobj.ref - end - end - # create it anew # if there's a failure, destroy the object if it got that far, but raise # the error. @@ -153,8 +137,6 @@ class Puppet::Type Puppet.err "Could not create %s: %s" % [title, detail.to_s] if obj obj.remove(true) - elsif obj = self[title] - obj.remove(true) end raise end @@ -163,9 +145,6 @@ class Puppet::Type obj.implicit = true end - # Store the object by title - self[obj.title] = obj - return obj end @@ -258,10 +237,6 @@ class Puppet::Type provider_instances = {} providers_by_source.collect do |provider| provider.instances.collect do |instance| - # First try to get the resource if it already exists - # Skip instances that map to a managed resource with a different provider - next if resource = self[instance.name] and resource.provider.class != instance.class - # We always want to use the "first" provider instance we find, unless the resource # is already managed and has a different provider set if other = provider_instances[instance.name] @@ -271,12 +246,7 @@ class Puppet::Type end provider_instances[instance.name] = instance - if resource - resource.provider = instance - resource - else - create(:name => instance.name, :provider => instance, :check => :all) - end + create(:name => instance.name, :provider => instance, :check => :all) end end.flatten.compact end diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb index b35adae66..b0a4cfce5 100644 --- a/lib/puppet/metatype/metaparams.rb +++ b/lib/puppet/metatype/metaparams.rb @@ -277,6 +277,7 @@ class Puppet::Type # to an object... tname, name = value reference = Puppet::ResourceReference.new(tname, name) + reference.catalog = resource.catalog # Either of the two retrieval attempts could have returned # nil. diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb index 4fb78ae56..3433c4884 100644 --- a/lib/puppet/metatype/relationships.rb +++ b/lib/puppet/metatype/relationships.rb @@ -18,6 +18,8 @@ class Puppet::Type # Figure out of there are any objects we can automatically add as # dependencies. def autorequire + raise(Puppet::DevError, "You cannot add relationships without a catalog") unless catalog + reqs = [] self.class.eachautorequire { |type, block| # Ignore any types we can't find, although that would be a bit odd. @@ -35,7 +37,7 @@ class Puppet::Type # Support them passing objects directly, to save some effort. unless dep.is_a? Puppet::Type # Skip autorequires that we aren't managing - unless dep = typeobj[dep] + unless dep = catalog.resource(type, dep) next end end diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index e6378bf01..3ee4721f3 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -568,12 +568,14 @@ class Puppet::Network::Handler @path = nil end + @files = {} + super() end def fileobj(path, links, client) obj = nil - if obj = Puppet.type(:file)[file_path(path, client)] + if obj = @files[file_path(path, client)] # This can only happen in local fileserving, but it's an # important one. It'd be nice if we didn't just set # the check params every time, but I'm not sure it's worth @@ -584,6 +586,7 @@ class Puppet::Network::Handler :name => file_path(path, client), :check => CHECKPARAMS ) + @files[file_path(path, client)] = obj end if links == :manage @@ -600,7 +603,7 @@ class Puppet::Network::Handler # Read the contents of the file at the relative path given. def read_file(relpath, client) - File.read(file_path(relpath, client)) + File.read(file_path(relpath, client)) end # Cache this manufactured map, since if it's used it's likely diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 9601309d8..0dcfbaefc 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -293,7 +293,7 @@ class Puppet::Node::Catalog < Puppet::PGraph # And filebuckets if bucket = Puppet::Type.type(:filebucket).mkdefaultbucket - add_resource(bucket) + add_resource(bucket) unless resource(bucket.ref) end end diff --git a/lib/puppet/resource_reference.rb b/lib/puppet/resource_reference.rb index 3e92662b2..8af17918a 100644 --- a/lib/puppet/resource_reference.rb +++ b/lib/puppet/resource_reference.rb @@ -22,15 +22,8 @@ class Puppet::ResourceReference # Find our resource. def resolve - if catalog - return catalog.resource(to_s) - end - # If it's builtin, then just ask for it directly from the type. - if t = builtin_type - t[@title] - else # Else, look for a component with the full reference as the name. - Puppet::Type::Component[to_s] - end + return catalog.resource(to_s) if catalog + return nil end # If the title has square brackets, treat it like a reference and diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index def9e44e4..c7a6f4e40 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -231,14 +231,14 @@ class Type end # If the name and title differ, set up an alias - if self.name != self.title - if obj = self.class[self.name] + if self.name != self.title and self.catalog + if obj = catalog.resource(self.class.name, self.name) if self.class.isomorphic? raise Puppet::Error, "%s already exists with name %s" % [obj.title, self.name] end else - self.class.alias(self.name, self) + catalog.alias(self, self.name) end end diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 356205089..1d1bc9ee8 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -88,8 +88,8 @@ Puppet::Type.newtype(:component) do @reference = Puppet::ResourceReference.new(:component, @title) - unless self.class[@reference.to_s] - self.class.alias(@reference.to_s, self) + if catalog and ! catalog.resource[@reference.to_s] + catalog.alias(self, @reference.to_s) end end diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 7d928d959..c8e63b5ba 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -76,9 +76,8 @@ module Puppet munge do |value| # I don't really know how this is happening. - if value.is_a?(Array) - value = value.shift - end + value = value.shift if value.is_a?(Array) + case value when false, "false", :false: false @@ -90,7 +89,7 @@ module Puppet # We can't depend on looking this up right now, # we have to do it after all of the objects # have been instantiated. - if bucketobj = Puppet::Type.type(:filebucket)[value] + if resource.catalog and bucketobj = resource.catalog.resource(:filebucket, value) @resource.bucket = bucketobj.bucket bucketobj.title else @@ -304,30 +303,23 @@ module Puppet # We have to do some extra finishing, to retrieve our bucket if # there is one. def finish - # Let's cache these values, since there should really only be - # a couple of these buckets - @@filebuckets ||= {} - # Look up our bucket, if there is one if bucket = self.bucket case bucket when String: - if obj = @@filebuckets[bucket] - # This sets the @value on :backup, too - self.bucket = obj + if catalog and obj = catalog.resource(:filebucket, bucket) + self.bucket = obj.bucket elsif bucket == "puppet" obj = Puppet::Network::Client.client(:Dipper).new( :Path => Puppet[:clientbucketdir] ) self.bucket = obj - @@filebuckets[bucket] = obj - elsif obj = Puppet::Type.type(:filebucket).bucket(bucket) - @@filebuckets[bucket] = obj - self.bucket = obj else - self.fail "Could not find filebucket %s" % bucket + self.fail "Could not find filebucket '%s'" % bucket end when Puppet::Network::Client.client(:Dipper): # things are hunky-dorey + when Puppet::Type::Filebucket # things are hunky-dorey + self.bucket = bucket.bucket else self.fail "Invalid bucket type %s" % bucket.class end @@ -432,8 +424,7 @@ module Puppet end when "link": return true else - self.notice "Cannot backup files of type %s" % - File.stat(file).ftype + self.notice "Cannot backup files of type %s" % File.stat(file).ftype return false end end @@ -783,13 +774,9 @@ module Puppet def remove_existing(should) return unless s = stat(true) - unless handlebackup - self.fail "Could not back up; will not replace" - end + self.fail "Could not back up; will not replace" unless handlebackup - unless should.to_s == "link" - return if s.ftype.to_s == should.to_s - end + return if s.ftype.to_s == should.to_s unless should.to_s == "link" case s.ftype when "directory": diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb index b268610e9..872bded4e 100755 --- a/lib/puppet/type/pfilebucket.rb +++ b/lib/puppet/type/pfilebucket.rb @@ -54,21 +54,9 @@ module Puppet defaultto { Puppet[:clientbucketdir] } end - # get the actual filebucket object - def self.bucket(name) - if object = self[name] - return object.bucket - else - return nil - end - end - # Create a default filebucket. def self.mkdefaultbucket - unless default = self["puppet"] - return self.create(:name => "puppet", :path => Puppet[:clientbucketdir]) - end - return nil + self.create(:name => "puppet", :path => Puppet[:clientbucketdir]) end def self.instances diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb index c494c5d94..ecbf7d49a 100755 --- a/lib/puppet/type/schedule.rb +++ b/lib/puppet/type/schedule.rb @@ -316,8 +316,6 @@ module Puppet end def self.mkdefaultschedules - return [] if self["puppet"] - result = [] Puppet.debug "Creating default schedules" result << self.create( @@ -328,12 +326,10 @@ module Puppet # And then one for every period @parameters.find { |p| p.name == :period }.values.each { |value| - unless self[value.to_s] - result << self.create( - :name => value.to_s, - :period => value - ) - end + result << self.create( + :name => value.to_s, + :period => value + ) } result diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 1c7734cc4..cddfc4689 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -74,8 +74,10 @@ class Puppet::Util::FileType # Pick or create a filebucket to use. def bucket - filebucket = Puppet::Type.type(:filebucket) - (filebucket["puppet"] || filebucket.mkdefaultbucket).bucket + unless defined?(@bucket) + @bucket = Puppet::Type.type(:filebucket).mkdefaultbucket.bucket + end + @bucket end def initialize(path) diff --git a/spec/unit/resource_reference.rb b/spec/unit/resource_reference.rb index ef172d80a..e629d0b82 100755 --- a/spec/unit/resource_reference.rb +++ b/spec/unit/resource_reference.rb @@ -42,18 +42,6 @@ describe Puppet::ResourceReference do end end -describe Puppet::ResourceReference, "when resolving resources without a catalog" do - it "should be able to resolve builtin resources from their types" do - Puppet::Type.type(:file).expects(:[]).with("myfile").returns(:myfile) - Puppet::ResourceReference.new(:file, "myfile").resolve.should == :myfile - end - - it "should be able to resolve defined resources from Components" do - Puppet::Type.type(:component).expects(:[]).with("Foo::Bar[yay]").returns(:mything) - Puppet::ResourceReference.new("foo::bar", "yay").resolve.should == :mything - end -end - describe Puppet::ResourceReference, "when resolving resources with a catalog" do it "should resolve all resources using the catalog" do config = mock 'catalog' 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 |