diff options
| author | Luke Kanies <luke@madstop.com> | 2008-02-11 18:08:15 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-02-11 18:08:15 -0600 |
| commit | d21416b534eaa5717eca850cfe848716a9b1dc09 (patch) | |
| tree | deba9647562710b69e63ec8096c4beca7cbe06fc /lib/puppet/node | |
| parent | fd0c5cbddec8dc53196a3b84e33e1000c3c0720f (diff) | |
| download | puppet-d21416b534eaa5717eca850cfe848716a9b1dc09.tar.gz puppet-d21416b534eaa5717eca850cfe848716a9b1dc09.tar.xz puppet-d21416b534eaa5717eca850cfe848716a9b1dc09.zip | |
Switching the Node Catalog to using a separate method
for validating that a given resource is unique
within the catalog. This no longer allows any
duplication, even with Execs.
Diffstat (limited to 'lib/puppet/node')
| -rw-r--r-- | lib/puppet/node/catalog.rb | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index f93d2786d..2b9291680 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -58,12 +58,12 @@ class Puppet::Node::Catalog < Puppet::PGraph raise ArgumentError, "Can only add objects that respond to :ref" end + fail_unless_unique(resource) + ref = resource.ref - if @resource_table.include?(ref) - raise ArgumentError, "Resource %s is already defined" % ref - else - @resource_table[ref] = resource - end + + @resource_table[ref] = resource + resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph add_vertex!(resource) end @@ -452,6 +452,28 @@ class Puppet::Node::Catalog < Puppet::PGraph end end + # Verify that the given resource isn't defined elsewhere. + def fail_unless_unique(resource) + # Short-curcuit the common case, + return unless existing_resource = @resource_table[resource.ref] + + # Either it's a defined type, which are never + # isomorphic, or it's a non-isomorphic type, so + # we should throw an exception. + msg = "Duplicate definition: %s is already defined" % resource.ref + + if existing_resource.file and existing_resource.line + msg << " in file %s at line %s" % + [existing_resource.file, existing_resource.line] + end + + if resource.line or resource.file + msg << "; cannot redefine" + end + + raise ArgumentError.new(msg) + end + # An abstracted method for converting one catalog into another type of catalog. # This pretty much just converts all of the resources from one class to another, using # a conversion method. @@ -496,28 +518,4 @@ class Puppet::Node::Catalog < Puppet::PGraph return result end - - # Verify that the given resource isn't defined elsewhere. - def verify_resource_uniqueness(resource) - # Short-curcuit the common case, - unless existing_resource = @resource_table[resource.ref] - return true - end - - # Either it's a defined type, which are never - # isomorphic, or it's a non-isomorphic type, so - # we should throw an exception. - msg = "Duplicate definition: %s is already defined" % resource.ref - - if existing_resource.file and existing_resource.line - msg << " in file %s at line %s" % - [existing_resource.file, existing_resource.line] - end - - if resource.line or resource.file - msg << "; cannot redefine" - end - - raise Puppet::ParseError.new(msg) - end end |
