diff options
-rw-r--r-- | lib/puppet/parser/scope.rb | 23 | ||||
-rw-r--r-- | lib/puppet/type.rb | 20 | ||||
-rwxr-xr-x | lib/puppet/type/exec.rb | 3 | ||||
-rw-r--r-- | lib/puppet/type/service.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util.rb | 20 |
5 files changed, 46 insertions, 22 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 996a497d5..93d97e396 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -542,16 +542,21 @@ module Puppet if obj == :undefined or obj.nil? # Make sure it's not defined elsewhere in the configuration if tmp = self.objectdefined?(name, type) - msg = "Duplicate definition: %s[%s] is already defined" % - [type, name] - error = Puppet::ParseError.new(msg) - if tmp.line - error.line = tmp.line - end - if tmp.file - error.file = tmp.file + typeklass = Puppet::Type.type(type) + if typeklass and ! typeklass.isomorphic? + Puppet.info "Allowing duplicate %s" % type + else + msg = "Duplicate definition: %s[%s] is already defined" % + [type, name] + error = Puppet::ParseError.new(msg) + if tmp.line + error.line = tmp.line + end + if tmp.file + error.file = tmp.file + end + raise error end - raise error end # And if it's not, then create it anew diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 528453f1a..5282076d5 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -209,7 +209,7 @@ class Type < Puppet::Element raise Puppet::DevError, "must pass a Puppet::Type object" end - if @objects.has_key?(newobj.name) + if @objects.has_key?(newobj.name) and self.isomorphic? raise Puppet::Error.new( "Object '%s' of type '%s' already exists with id '%s' vs. '%s'" % [newobj.name,newobj.class.name, @@ -644,7 +644,8 @@ class Type < Puppet::Element end } unless tmpstates.length == @states.length - raise "Something went very wrong with tmpstates creation" + raise Puppet::DevError, + "Something went very wrong with tmpstates creation" end return tmpstates end @@ -672,11 +673,11 @@ class Type < Puppet::Element self.to_s end # if the object already exists - if retobj = self[name] + if self.isomorphic? and retobj = self[name] # 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.warning "Removing implicit %s" % retobj.name + Puppet.notice "Removing implicit %s" % retobj.name # Remove all of the objects, but do not remove their subscriptions. retobj.remove(false) @@ -732,6 +733,17 @@ class Type < Puppet::Element return obj end + # Is this type's name isomorphic with the object? That is, if the + # name conflicts, does it necessarily mean that the objects conflict? + # Defaults to true. + def self.isomorphic? + if defined? @isomorphic + return @isomorphic + else + return true + end + end + # and then make 'new' private class << self private :new diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 59c7c40e4..fff3aeee2 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -161,6 +161,9 @@ module Puppet @name = :exec @namevar = :command + # Exec names are not isomorphic with the objects. + @isomorphic = false + def initialize(hash) # default to erroring on a non-zero return if hash.include?("returns") diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 04c1bc904..a89d56e12 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -174,7 +174,7 @@ module Puppet end unless @defsvctype - self.notice "Defaulting to base service type" + Puppet.notice "Defaulting to base service type" @defsvctype = Puppet::ServiceTypes::BaseSvc end end diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index da52791cb..50f488905 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -19,10 +19,12 @@ module Util if group.is_a?(Integer) gid = group else - obj = Puppet::Type::Group.create( - :name => user, - :check => [:gid] - ) + unless obj = Puppet::Type::Group[user] + obj = Puppet::Type::Group.create( + :name => user, + :check => [:gid] + ) + end obj.retrieve gid = obj.is(:gid) unless gid.is_a?(Integer) @@ -45,10 +47,12 @@ module Util if user.is_a?(Integer) uid = user else - obj = Puppet::Type::User.create( - :name => user, - :check => [:uid, :gid] - ) + unless obj = Puppet::Type::User[user] + obj = Puppet::Type::User.create( + :name => user, + :check => [:uid, :gid] + ) + end obj.retrieve uid = obj.is(:uid) unless uid.is_a?(Integer) |