summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-02 04:14:38 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-02 04:14:38 +0000
commit42a9d9a3f8ac698370c36c4ca631e82797e01ece (patch)
tree7a4eb98ce6d9cf70b2538399aec0a206c9cb79aa /lib
parent300a1632432b5aa5e0221d28fe0a2ce90c422131 (diff)
downloadpuppet-42a9d9a3f8ac698370c36c4ca631e82797e01ece.tar.gz
puppet-42a9d9a3f8ac698370c36c4ca631e82797e01ece.tar.xz
puppet-42a9d9a3f8ac698370c36c4ca631e82797e01ece.zip
Adding "isomorphic?" method to classes, and testing for isomorphism before throwing a conflict
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@741 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/scope.rb23
-rw-r--r--lib/puppet/type.rb20
-rwxr-xr-xlib/puppet/type/exec.rb3
-rw-r--r--lib/puppet/type/service.rb2
-rw-r--r--lib/puppet/util.rb20
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)