diff options
-rw-r--r-- | lib/puppet/provider.rb | 2 | ||||
-rw-r--r-- | lib/puppet/reports/store.rb | 4 | ||||
-rw-r--r-- | lib/puppet/resource/reference.rb | 11 | ||||
-rw-r--r-- | lib/puppet/type.rb | 23 | ||||
-rw-r--r-- | lib/puppet/type/file.rb | 2 | ||||
-rwxr-xr-x | spec/unit/resource/reference.rb | 8 | ||||
-rwxr-xr-x | spec/unit/type.rb | 18 | ||||
-rwxr-xr-x | test/network/handler/resource.rb | 2 | ||||
-rwxr-xr-x | test/other/events.rb | 6 | ||||
-rwxr-xr-x | test/other/relationships.rb | 132 | ||||
-rwxr-xr-x | test/other/transactions.rb | 16 | ||||
-rwxr-xr-x | test/ral/manager/attributes.rb | 21 | ||||
-rwxr-xr-x | test/ral/manager/type.rb | 62 | ||||
-rwxr-xr-x | test/ral/providers/parsedfile.rb | 8 | ||||
-rwxr-xr-x | test/ral/type/exec.rb | 5 | ||||
-rwxr-xr-x | test/util/settings.rb | 85 |
16 files changed, 59 insertions, 346 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index c02e15029..ce195c086 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -260,7 +260,7 @@ class Puppet::Provider # use the hash here for later events. @property_hash = resource elsif resource - @resource = resource if resource + @resource = resource # LAK 2007-05-09: Keep the model stuff around for backward compatibility @model = resource @property_hash = {} diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb index dfc992820..0c7f8cea9 100644 --- a/lib/puppet/reports/store.rb +++ b/lib/puppet/reports/store.rb @@ -12,7 +12,7 @@ Puppet::Reports.register_report(:store) do def mkclientdir(client, dir) config = Puppet::Util::Settings.new - config.setdefaults("reportclient-#{client}", + config.setdefaults("reportclient-#{client}".to_sym, "client-#{client}-dir" => { :default => dir, :mode => 0750, :desc => "Client dir for %s" % client, @@ -21,7 +21,7 @@ Puppet::Reports.register_report(:store) do } ) - config.use("reportclient-#{client}") + config.use("reportclient-#{client}".to_sym) end def process diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb index 7f33160bd..750c10e41 100644 --- a/lib/puppet/resource/reference.rb +++ b/lib/puppet/resource/reference.rb @@ -23,9 +23,14 @@ class Puppet::Resource::Reference def initialize(argtype, argtitle = nil) if argtitle.nil? - self.title = argtype - if self.title == argtype - raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype + if argtype.is_a?(Puppet::Type) + self.title = argtype.title + self.type = argtype.class.name + else + self.title = argtype + if self.title == argtype + raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype.inspect + end end else # This will set @type if it looks like a resource reference. diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 4bf28d97b..f8aa701f0 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1722,20 +1722,6 @@ class Type end end.flatten.reject { |r| r.nil? } end - - # Does this resource have a relationship with the other? We have to - # check each object for both directions of relationship. - def requires?(other) - them = [other.class.name, other.title] - me = [self.class.name, self.title] - self.class.relationship_params.each do |param| - case param.direction - when :in: return true if v = self[param.name] and v.include?(them) - when :out: return true if v = other[param.name] and v.include?(me) - end - end - return false - end ############################### # All of the scheduling code. @@ -1943,6 +1929,8 @@ class Type @original_parameters = resource.to_hash + set_name(@original_parameters) + set_default(:provider) set_parameters(@original_parameters) @@ -1952,6 +1940,13 @@ class Type private + # Set our resource's name. + def set_name(hash) + n = self.class.namevar + self[n] = hash[n] + hash.delete(n) + end + # Set all of the parameters from a hash, in the appropriate order. def set_parameters(hash) # Use the order provided by allattrs, but add in any diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 91458934e..3d721ac69 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -28,7 +28,7 @@ module Puppet validate do |value| unless value =~ /^#{File::SEPARATOR}/ - raise Puppet::Error, "File paths must be fully qualified" + raise Puppet::Error, "File paths must be fully qualified, not '%s'" % value end end end diff --git a/spec/unit/resource/reference.rb b/spec/unit/resource/reference.rb index fa2d87bd5..fef48bb13 100755 --- a/spec/unit/resource/reference.rb +++ b/spec/unit/resource/reference.rb @@ -53,6 +53,14 @@ describe Puppet::Resource::Reference do ref.title.should =="baz" end + it "should be able to extract its information from a Puppet::Type instance" do + ral = Puppet::Type.type(:file).new :path => "/foo" + ref = Puppet::Resource::Reference.new(ral) + ref.type.should == "File" + ref.title.should == "/foo" + end + + it "should fail if the title is nil and the type is not a valid resource reference string" do lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError) end diff --git a/spec/unit/type.rb b/spec/unit/type.rb index 672de9eb0..3523d4e8b 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -57,8 +57,8 @@ describe Puppet::Type do end it "should set its title to the resource reference if the resource type is not equal to the current type" do - resource = Puppet::Resource.new(:file, "/foo") - Puppet::Type.type(:mount).new(resource).title.should == "File[/foo]" + resource = Puppet::Resource.new(:user, "foo") + Puppet::Type.type(:mount).new(resource).title.should == "User[foo]" end [:line, :file, :catalog, :implicit].each do |param| @@ -152,10 +152,11 @@ describe Puppet::Type do Puppet::Type.type(:mount).new(resource) - set[1..-1].should == [:name, :atboot, :noop] + set[-1].should == :noop + set[-2].should == :atboot end - it "should always set the default provider before anything else" do + it "should always set the name and then default provider before anything else" do Puppet::Type.type(:mount).stubs(:allattrs).returns([:provider, :name, :atboot]) resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot") @@ -167,7 +168,8 @@ describe Puppet::Type do end Puppet::Type.type(:mount).new(resource) - set[0].should == :provider + set[0].should == :name + set[1].should == :provider end # This one is really hard to test :/ @@ -181,11 +183,11 @@ describe Puppet::Type do end it "should retain a copy of the originally provided parameters" do - Puppet::Type.type(:mount).new(:name => "foo", :atboot => true, :noop => false).original_parameters.should == {:name => "foo", :atboot => true, :noop => false} + Puppet::Type.type(:mount).new(:name => "foo", :atboot => true, :noop => false).original_parameters.should == {:atboot => true, :noop => false} end - it "should store the name via the namevar in the originally provided parameters" do - Puppet::Type.type(:file).new(:name => "/foo").original_parameters[:path].should == "/foo" + it "should delete the name via the namevar from the originally provided parameters" do + Puppet::Type.type(:file).new(:name => "/foo").original_parameters[:path].should be_nil end end diff --git a/test/network/handler/resource.rb b/test/network/handler/resource.rb index d766c685d..48e812913 100755 --- a/test/network/handler/resource.rb +++ b/test/network/handler/resource.rb @@ -209,7 +209,7 @@ class TestResourceServer < Test::Unit::TestCase } bucket = Puppet::TransBucket.new - bucket.type = "file" + bucket.type = "class" bucket.name = "test" bucket.push filetrans diff --git a/test/other/events.rb b/test/other/events.rb index c4c2a53e6..3f02575d9 100755 --- a/test/other/events.rb +++ b/test/other/events.rb @@ -19,7 +19,7 @@ class TestEvents < Test::Unit::TestCase :name => "echo true", :path => "/usr/bin:/bin", :refreshonly => true, - :subscribe => [[file.class.name, file.name]] + :subscribe => Puppet::Resource::Reference.new(file.class.name, file.name) ) comp = mk_catalog("eventtesting", file, exec) @@ -39,7 +39,7 @@ class TestEvents < Test::Unit::TestCase :name => "echo true", :path => "/usr/bin:/bin", :refreshonly => true, - :require => [[file.class.name, file.name]] + :require => Puppet::Resource::Reference.new(file.class.name, file.name) ) @@ -71,7 +71,7 @@ class TestEvents < Test::Unit::TestCase ) exec[:subscribe] = files.collect { |f| - ["file", f.name] + Puppet::Resource::Reference.new(:file, f.name) } comp = mk_catalog(exec, *files) diff --git a/test/other/relationships.rb b/test/other/relationships.rb index f007ca1c1..b3a70eeae 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -53,116 +53,11 @@ class TestRelationships < Test::Unit::TestCase end end - # Make sure our various metaparams work correctly. We're just checking - # here whether they correctly set up the callbacks and the direction of - # the relationship. - def test_relationship_metaparams - out = {:require => false, :subscribe => false, - :notify => true, :before => true} - refreshers = [:subscribe, :notify] - [:require, :subscribe, :notify, :before].each do |param| - # Create three files to generate our events and three - # execs to receive them - files = [] - execs = [] - 3.times do |i| - files << Puppet::Type.newfile( - :title => "file#{i}", - :path => tempfile(), - :ensure => :file - ) - - path = tempfile() - execs << Puppet::Type.newexec( - :title => "notifytest#{i}", - :path => "/usr/bin:/bin", - :command => "touch #{path}", - :refreshonly => true - ) - end - - catalog = mk_catalog(*files) - catalog.add_resource(*execs) - - # Add our first relationship - if out[param] - files[0][param] = execs[0] - sources = files[0] - targets = [execs[0]] - else - execs[0][param] = files[0] - sources = [files[0]] - targets = execs[0] - end - check_relationship(sources, targets, out[param], refreshers.include?(param)) - - # Now add another relationship - if out[param] - files[0][param] = execs[1] - targets << execs[1] - assert_equal(targets.collect { |t| [t.class.name, t.title]}, - files[0][param], "Incorrect target list") - else - execs[0][param] = files[1] - sources << files[1] - assert_equal(sources.collect { |t| [t.class.name, t.title]}, - execs[0][param], "Incorrect source list") - end - check_relationship(sources, targets, out[param], refreshers.include?(param)) - end - end - - def test_munge_relationship - file = Puppet::Type.newfile :path => tempfile(), :mode => 0755 - execs = [] - 3.times do |i| - execs << Puppet::Type.newexec(:title => "yay#{i}", :command => "/bin/echo yay") - end - - # First try it with one object, specified as a reference and an array - result = nil - [execs[0], [:exec, "yay0"], ["exec", "yay0"]].each do |target| - assert_nothing_raised do - result = file.send(:munge_relationship, :require, target) - end - - assert_equal([[:exec, "yay0"]], result) - end - - # Now try it with multiple objects - symbols = execs.collect { |e| [e.class.name, e.title] } - strings = execs.collect { |e| [e.class.name.to_s, e.title] } - [execs, symbols, strings].each do |target| - assert_nothing_raised do - result = file.send(:munge_relationship, :require, target) - end - - assert_equal(symbols, result) - end - - # Make sure we can mix it up, even though this shouldn't happen - assert_nothing_raised do - result = file.send(:munge_relationship, :require, [execs[0], [execs[1].class.name, execs[1].title]]) - end - - assert_equal([[:exec, "yay0"], [:exec, "yay1"]], result) - - # Finally, make sure that new results get added to old. The only way - # to get rid of relationships is to delete the parameter. - file[:require] = execs[0] - - assert_nothing_raised do - result = file.send(:munge_relationship, :require, [execs[1], execs[2]]) - end - - assert_equal(symbols, result) - end - def test_autorequire # We know that execs autorequire their cwd, so we'll use that path = tempfile() - file = Puppet::Type.newfile(:title => "myfile", :path => path, + file = Puppet::Type.type(:file).new(:title => "myfile", :path => path, :ensure => :directory) exec = Puppet::Type.newexec(:title => "myexec", :cwd => path, :command => "/bin/echo") @@ -183,32 +78,9 @@ class TestRelationships < Test::Unit::TestCase end end - def test_requires? - # Test the first direction - file1 = Puppet::Type.newfile(:title => "one", :path => tempfile, - :ensure => :directory) - file2 = Puppet::Type.newfile(:title => "two", :path => tempfile, - :ensure => :directory) - - file1[:require] = file2 - assert(file1.requires?(file2), "requires? failed to catch :require relationship") - file1.delete(:require) - assert(! file1.requires?(file2), "did not delete relationship") - file1[:subscribe] = file2 - assert(file1.requires?(file2), "requires? failed to catch :subscribe relationship") - file1.delete(:subscribe) - assert(! file1.requires?(file2), "did not delete relationship") - file2[:before] = file1 - assert(file1.requires?(file2), "requires? failed to catch :before relationship") - file2.delete(:before) - assert(! file1.requires?(file2), "did not delete relationship") - file2[:notify] = file1 - assert(file1.requires?(file2), "requires? failed to catch :notify relationship") - end - # Testing #411. It was a problem with builddepends. def test_missing_deps - file = Puppet::Type.newfile :path => tempfile, :require => ["file", "/no/such/file"] + file = Puppet::Type.type(:file).new :path => tempfile, :require => Puppet::Resource::Reference.new("file", "/no/such/file") assert_raise(Puppet::Error) do file.builddepends diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 568660848..6145b19c5 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -158,12 +158,12 @@ class TestTransactions < Test::Unit::TestCase file = Puppet::Type.type(:file).new(:title => "file", :path => path, :content => "yayness") first = Puppet::Type.type(:exec).new(:title => "first", :command => "/bin/echo first > #{firstpath}", - :subscribe => [:file, path], + :subscribe => Puppet::Resource::Reference.new(:file, path), :refreshonly => true ) second = Puppet::Type.type(:exec).new(:title => "second", :command => "/bin/echo second > #{secondpath}", - :subscribe => [:exec, "first"], + :subscribe => Puppet::Resource::Reference.new(:exec, "first"), :refreshonly => true ) @@ -301,7 +301,7 @@ class TestTransactions < Test::Unit::TestCase @@tmpfiles << execfile # 'subscribe' expects an array of arrays - exec[:subscribe] = [[file.class.name,file.name]] + exec[:subscribe] = Puppet::Resource::Reference.new(file.class.name,file.name) exec[:refreshonly] = true assert_nothing_raised() { @@ -385,13 +385,13 @@ class TestTransactions < Test::Unit::TestCase :path => ENV["PATH"], :command => "touch %s" % file1, :refreshonly => true, - :subscribe => [:file, path] + :subscribe => Puppet::Resource::Reference.new(:file, path) ) exec2 = Puppet::Type.type(:exec).new( :path => ENV["PATH"], :command => "touch %s" % file2, :refreshonly => true, - :subscribe => [:file, path] + :subscribe => Puppet::Resource::Reference.new(:file, path) ) assert_apply(file, exec1, exec2) @@ -444,7 +444,7 @@ class TestTransactions < Test::Unit::TestCase :name => "touch %s" % fname, :path => "/usr/bin:/bin", :schedule => "monthly", - :subscribe => ["file", file.name] + :subscribe => Puppet::Resource::Reference.new("file", file.name) ) config = mk_catalog(file, exec) @@ -791,6 +791,10 @@ class TestTransactions < Test::Unit::TestCase attr_accessor :refreshed, :testing newparam(:name) {} newproperty(:testing) do + def retrieve + :eh + end + def sync # noop :ran_testing diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb index cad0f2f7a..05f8bc97f 100755 --- a/test/ral/manager/attributes.rb +++ b/test/ral/manager/attributes.rb @@ -184,27 +184,6 @@ class TestTypeAttributes < Test::Unit::TestCase end end - # Make sure eachattr is called in the parameter order. - def test_eachattr - type = mktype - name = type.newparam(:name) {} - one = type.newparam(:one) {} - two = type.newproperty(:two) {} - type.provide(:testing) {} - provider = type.attrclass(:provider) - should = [[name, :param], [provider, :param], [two, :property], [one, :param]] - assert_nothing_raised do - result = nil - type.eachattr do |obj, name| - result = [obj, name] - shouldary = should.shift - assert_equal(shouldary, result, "Did not get correct parameter") - break if should.empty? - end - end - assert(should.empty?, "Did not get all of the parameters.") - end - # Make sure newattr handles required features correctly. def test_newattr_and_required_features # Make a type with some features diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index d6b7b2a1d..0a0e13e39 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -137,36 +137,6 @@ class TestType < Test::Unit::TestCase } end - # Verify that requirements don't depend on file order - def test_prereqorder - one = tempfile() - two = tempfile() - - twoobj = nil - oneobj = nil - assert_nothing_raised("Could not create prereq that doesn't exist yet") { - twoobj = Puppet::Type.type(:file).new( - :name => two, - :require => [:file, one] - ) - } - - assert_nothing_raised { - oneobj = Puppet::Type.type(:file).new( - :name => one - ) - } - - comp = mk_catalog(twoobj, oneobj) - - assert_nothing_raised { - comp.finalize - } - - - assert(twoobj.requires?(oneobj), "Requirement was not created") - end - def test_ensuredefault user = nil assert_nothing_raised { @@ -337,17 +307,6 @@ class TestType < Test::Unit::TestCase assert_equal(path, file[:name], "Did not get correct name") end - def test_multiplenames - obj = nil - path = tempfile() - assert_raise ArgumentError do - obj = Puppet::Type.type(:file).new( - :name => path, - :path => path - ) - end - end - # Make sure default providers behave correctly def test_defaultproviders # Make a fake type @@ -507,27 +466,6 @@ class TestType < Test::Unit::TestCase assert_equal("//Good[bad]/Exec[exec6]", exec.path) end - def test_evaluate - faketype = Puppet::Type.newtype(:faketype) do - newparam(:name) {} - end - cleanup { Puppet::Type.rmtype(:faketype) } - faketype.provide(:fake) do - def prefetch - end - end - - obj = faketype.create :name => "yayness", :provider => :fake - assert(obj, "did not create object") - - obj.provider.expects(:prefetch) - obj.expects(:retrieve) - obj.expects(:propertychanges).returns([]) - obj.expects(:cache) - - obj.evaluate - end - # Partially test #704, but also cover the rest of the schedule management bases. def test_schedule schedule = Puppet::Type.type(:schedule).new(:name => "maint") diff --git a/test/ral/providers/parsedfile.rb b/test/ral/providers/parsedfile.rb index aef2a5492..d57a873ea 100755 --- a/test/ral/providers/parsedfile.rb +++ b/test/ral/providers/parsedfile.rb @@ -608,13 +608,9 @@ class TestParsedFile < Test::Unit::TestCase prov.prefetch # Now make a resource - bill = nil - assert_nothing_raised do - bill = @type.new :name => "bill" - end + bill = @type.new :name => "bill" - assert_equal("a", bill.provider.one, - "Record was not found in memory") + assert_equal("a", bill.provider.one, "Record was not found in memory") end # Make sure invalid fields always show up as insync diff --git a/test/ral/type/exec.rb b/test/ral/type/exec.rb index f04b3c908..e156beaae 100755 --- a/test/ral/type/exec.rb +++ b/test/ral/type/exec.rb @@ -195,7 +195,7 @@ class TestExec < Test::Unit::TestCase exec = Puppet::Type.type(:exec).new( :command => oexe, - :require => [:file, oexe] + :require => Puppet::Resource::Reference.new(:file, oexe) ) comp = mk_catalog("Testing", file, exec) @@ -254,7 +254,6 @@ class TestExec < Test::Unit::TestCase # Verify we don't require ourselves assert(! rels.detect { |r| r.source == ofile }, "Exec incorrectly required mentioned file") - assert(!exec.requires?(ofile), "Exec incorrectly required file") # We not longer autorequire inline files assert_nothing_raised do @@ -419,7 +418,7 @@ class TestExec < Test::Unit::TestCase :path => basedir, :recurse => true, :mode => "755", - :require => ["exec", "mkdir"] + :require => Puppet::Resource::Reference.new("exec", "mkdir") ) } diff --git a/test/util/settings.rb b/test/util/settings.rb index 286b14800..c4096f0bc 100755 --- a/test/util/settings.rb +++ b/test/util/settings.rb @@ -468,91 +468,6 @@ yay = /a/path assert_equal(should, result, "Add args functional test failed") end - def test_usesection - # We want to make sure that config processes do not result in graphing. - Puppet[:graphdir] = tempfile() - Puppet[:graph] = true - Dir.mkdir(Puppet[:graphdir]) - c = mkconfig - - dir = tempfile() - file = "$mydir/myfile" - realfile = File.join(dir, "myfile") - otherfile = File.join(dir, "otherfile") - section = "testing" - assert_nothing_raised { - @config.setdefaults(section, - :mydir => [dir, "A dir arg"], - :otherfile => { - :default => "$mydir/otherfile", - :create => true, - :desc => "A file arg" - }, - :myfile => [file, "A file arg"] - ) - } - - assert_nothing_raised("Could not use a section") { - @config.use(section) - } - - assert_nothing_raised("Could not reuse a section") { - @config.use(section) - } - - # Make sure it didn't graph anything, which is the only real way - # to test that the transaction was marked as a configurator. - assert(Dir.entries(Puppet[:graphdir]).reject { |f| f =~ /^\.\.?$/ }.empty?, "Graphed config process") - - assert(FileTest.directory?(dir), "Did not create directory") - assert(FileTest.exists?(otherfile), "Did not create file") - assert(!FileTest.exists?(realfile), "Created file") - end - - def test_setdefaultsarray - c = mkconfig - - assert_nothing_raised { - @config.setdefaults("yay", - :a => [false, "some value"], - :b => ["/my/file", "a file"] - ) - } - - assert_equal(false, @config[:a], "Values are not equal") - assert_equal("/my/file", @config[:b], "Values are not equal") - end - - def test_setdefaultshash - c = mkconfig - - assert_nothing_raised { - @config.setdefaults("yay", - :a => {:default => false, :desc => "some value"}, - :b => {:default => "/my/file", :desc => "a file"} - ) - } - - assert_equal(false, @config[:a], "Values are not equal") - assert_equal("/my/file", @config[:b], "Values are not equal") - end - - def test_notmanagingdev - c = mkconfig - path = "/dev/testing" - @config.setdefaults(:test, - :file => { - :default => path, - :mode => 0640, - :desc => 'yay' - } - ) - - config = @config.to_catalog - - assert(! config.resource(:file, "/dev/testing"), "Created dev file") - end - def test_groupsetting cfile = tempfile() |