diff options
-rw-r--r-- | lib/puppet/metatype/closure.rb | 52 | ||||
-rw-r--r-- | lib/puppet/metatype/instances.rb | 16 | ||||
-rw-r--r-- | lib/puppet/node/configuration.rb | 20 | ||||
-rw-r--r-- | lib/puppet/type.rb | 11 | ||||
-rwxr-xr-x | lib/puppet/type/tidy.rb | 1 | ||||
-rwxr-xr-x | spec/unit/node/configuration.rb | 22 | ||||
-rwxr-xr-x | spec/unit/other/transbucket.rb | 3 | ||||
-rwxr-xr-x | spec/unit/ral/type.rb | 4 | ||||
-rwxr-xr-x | spec/unit/ral/types/file.rb | 12 | ||||
-rwxr-xr-x | test/lib/puppettest.rb | 6 | ||||
-rwxr-xr-x | test/ral/types/tidy.rb | 7 |
11 files changed, 64 insertions, 90 deletions
diff --git a/lib/puppet/metatype/closure.rb b/lib/puppet/metatype/closure.rb index 46e3c873f..259854411 100644 --- a/lib/puppet/metatype/closure.rb +++ b/lib/puppet/metatype/closure.rb @@ -42,56 +42,4 @@ class Puppet::Type return @managed end end - - # Merge new information with an existing object, checking for conflicts - # and such. This allows for two specifications of the same object and - # the same values, but it's pretty limited right now. The result of merging - # properties is very different from the result of merging parameters or - # metaparams. This is currently unused. - def merge(hash) - hash.each { |param, value| - if param.is_a?(String) - param = param.intern - end - - # Of course names are the same, duh. - next if param == :name or param == self.class.namevar - - unless value.is_a?(Array) - value = [value] - end - - if @parameters.include?(param) and oldvals = @parameters[param].shouldorig - unless oldvals.is_a?(Array) - oldvals = [oldvals] - end - # If the values are exactly the same, order and everything, - # then it's okay. - if oldvals == value - return true - end - # take the intersection - newvals = oldvals & value - if newvals.empty? - self.fail "No common values for %s on %s(%s)" % - [param, self.class.name, self.title] - elsif newvals.length > 1 - self.fail "Too many values for %s on %s(%s)" % - [param, self.class.name, self.title] - else - self.debug "Reduced old values %s and new values %s to %s" % - [oldvals.inspect, value.inspect, newvals.inspect] - @parameters[param].should = newvals - #self.should = newvals - return true - end - else - self[param] = value - end - } - - # Set the defaults again, just in case. - self.setdefaults - end end - diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb index 8cc648e8f..16dd28433 100644 --- a/lib/puppet/metatype/instances.rb +++ b/lib/puppet/metatype/instances.rb @@ -126,8 +126,6 @@ class Puppet::Type # XXX This will have to change when transobjects change to using titles title = hash.name - #Puppet.debug "Creating %s[%s]" % [self.name, title] - # 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 @@ -142,19 +140,7 @@ class Puppet::Type Puppet.debug "Ignoring implicit %s[%s]" % [self.name, title] return nil else - # If only one of the objects is being managed, then merge them - if retobj.managed? - raise Puppet::Error, "%s '%s' is already being managed" % - [self.name, title] - else - retobj.merge(hash) - return retobj - end - # We will probably want to support merging of some kind in - # the future, but for now, just throw an error. - #retobj.merge(hash) - - #return retobj + raise Puppet::Error, "%s is already being managed" % retobj.ref end end diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb index 804f357d1..393f23913 100644 --- a/lib/puppet/node/configuration.rb +++ b/lib/puppet/node/configuration.rb @@ -442,10 +442,18 @@ class Puppet::Node::Configuration < Puppet::PGraph def to_configuration(convert) result = self.class.new(self.name) + map = {} vertices.each do |resource| next if resource.respond_to?(:virtual?) and resource.virtual? - result.add_resource resource.send(convert) + newres = resource.send(convert) + + # We can't guarantee that resources don't munge their names + # (like files do with trailing slashes), so we have to keep track + # of what a resource got converted to. + map[resource.ref] = newres + + result.add_resource newres end message = convert.to_s.gsub "_", " " @@ -454,17 +462,19 @@ class Puppet::Node::Configuration < Puppet::PGraph next if edge.source.respond_to?(:virtual?) and edge.source.virtual? next if edge.target.respond_to?(:virtual?) and edge.target.virtual? - unless source = result.resource(edge.source.ref) - raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.source.ref, message] + unless source = map[edge.source.ref] + raise Puppet::DevError, "Could not find resource %s when converting %s resources" % [edge.source.ref, message] end - unless target = result.resource(edge.target.ref) - raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.target.ref, message] + unless target = map[edge.target.ref] + raise Puppet::DevError, "Could not find resource %s when converting %s resources" % [edge.target.ref, message] end result.add_edge!(source, target, edge.label) end + map.clear + result.add_class *self.classes result.tag(*self.tags) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index f5dd0f8dd..39a26f1fa 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -45,9 +45,6 @@ class Type # the method name, or whether it operates on a specific type of attributes. attr_accessor :file, :line - # The configuration that this resource is stored in. - attr_accessor :configuration - attr_writer :title attr_writer :noop @@ -119,6 +116,9 @@ class Type define_method(:validate, &block) #@validate = block end + + # The configuration that this resource is stored in. + attr_accessor :configuration # create a log at specified level def log(msg) @@ -181,6 +181,9 @@ class Type # If we got passed a transportable object, we just pull a bunch of info # directly from it. This is the main object instantiation mechanism. if hash.is_a?(Puppet::TransObject) + # XXX This will need to change when transobjects change to titles. + self.title = hash.name + #self[:name] = hash[:name] [:file, :line, :tags, :configuration].each { |getter| if hash.respond_to?(getter) @@ -191,8 +194,6 @@ class Type end } - # XXX This will need to change when transobjects change to titles. - @title = hash.name hash = hash.to_hash else if hash[:title] diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index f235d2e55..27456f7d6 100755 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -139,7 +139,6 @@ module Puppet type = @resource[:type] || :atime end - #return Integer(Time.now - stat.send(type)) return stat.send(type).to_i end diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index 5780d4fbb..0a8b47fc5 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -292,6 +292,28 @@ describe Puppet::Node::Configuration, " when converting to a RAL configuration" @config.vertices.each { |v| v.configuration.object_id.should equal(@config.object_id) } end + # This tests #931. + it "should not lose track of resources whose names vary" do + changer = Puppet::TransObject.new 'changer', 'test' + + config = Puppet::Node::Configuration.new('test') + config.add_resource(changer) + config.add_resource(@top) + + config.add_edge!(@top, changer) + + resource = stub 'resource', :name => "changer2", :title => "changer2", :ref => "Test[changer2]", :configuration= => nil, :remove => nil + + changer.expects(:to_type).returns(resource) + + newconfig = nil + + Puppet::Type.allclear + + proc { @config = config.to_ral }.should_not raise_error + @config.resource("Test[changer2]").should equal(resource) + end + after do # Remove all resource instances. @config.clear(true) diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb index 0da808460..241529ebe 100755 --- a/spec/unit/other/transbucket.rb +++ b/spec/unit/other/transbucket.rb @@ -99,11 +99,13 @@ describe Puppet::TransBucket, " when generating a configuration" do it "should only call to_type on each resource once" do @topobj.expects(:to_type) @bottomobj.expects(:to_type) + Puppet::Type.allclear @top.to_configuration end it "should set each TransObject's configuration before converting to a RAL resource" do @middleobj.expects(:configuration=).with { |c| c.is_a?(Puppet::Node::Configuration) } + Puppet::Type.allclear @top.to_configuration end @@ -111,6 +113,7 @@ describe Puppet::TransBucket, " when generating a configuration" do # each bucket is seen twice in the loop, so we have to handle the case where the config # is set twice @bottom.expects(:configuration=).with { |c| c.is_a?(Puppet::Node::Configuration) }.at_least_once + Puppet::Type.allclear @top.to_configuration end diff --git a/spec/unit/ral/type.rb b/spec/unit/ral/type.rb index c8bf8c9b4..adb40595e 100755 --- a/spec/unit/ral/type.rb +++ b/spec/unit/ral/type.rb @@ -22,4 +22,8 @@ describe Puppet::Type, " when in a configuration" do it "should set its parent to its in edge" do @one.parent.ref.should equal(@container.ref) end + + after do + @configuration.clear(true) + end end diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb index 823d643b0..1e20b06f4 100755 --- a/spec/unit/ral/types/file.rb +++ b/spec/unit/ral/types/file.rb @@ -1,18 +1,15 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' -require 'tempfile' -describe Puppet::type(:file), " when used with replace=>false and content" do +require 'puppet/type/pfile' +describe Puppet::Type::File, " when used with replace=>false and content" do before do @path = Tempfile.new("puppetspec") @path.close!() @path = @path.path - @file = Puppet::type(:file).create( { :name => @path, :content => "foo", :replace => :false } ) - end - - after do + @file = Puppet::Type::File.create( { :name => @path, :content => "foo", :replace => :false } ) end it "should be insync if the file exists and the content is different" do @@ -29,4 +26,7 @@ describe Puppet::type(:file), " when used with replace=>false and content" do @file.property(:content).insync?(:nil).should be_false end + after do + Puppet::Type::File.clear + end end diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 6447b80fb..76ae96e02 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -307,12 +307,6 @@ module PuppetTest # just move on end mocha_verify - if File.stat("/dev/null").mode & 007777 != 0666 - File.open("/tmp/nullfailure", "w") { |f| - f.puts self.class - } - exit(74) - end end def logstore diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb index 8813fcd3f..8220d9974 100755 --- a/test/ral/types/tidy.rb +++ b/test/ral/types/tidy.rb @@ -207,7 +207,14 @@ class TestTidy < Test::Unit::TestCase assert_apply(tidy) assert(! FileTest.exists?(path), "file did not get tidied") + tidy.class.clear + # Now try one with just an age attribute. + time = Time.now - 10 + stat = stub 'stat', :mtime => time, :atime => time, :ftype => "file" + File.stubs(:lstat) + File.stubs(:lstat).with(path).returns(stat) + File.open(path, "w") { |f| 10.times { f.puts "yayness " } } tidy = Puppet::Type.type(:tidy).create :path => path, :age => "5s" |