diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-07-25 15:34:56 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-07-25 16:47:14 -0700 |
commit | fb2ffd6879f4c885fe29f70e3cf9bcde89cdc8e9 (patch) | |
tree | 29787d6e0161e876f1b2c194f5231171891d9f89 /lib/puppet | |
parent | c7361629dff08d506209f806f0d903a0e968da06 (diff) | |
download | puppet-fb2ffd6879f4c885fe29f70e3cf9bcde89cdc8e9.tar.gz puppet-fb2ffd6879f4c885fe29f70e3cf9bcde89cdc8e9.tar.xz puppet-fb2ffd6879f4c885fe29f70e3cf9bcde89cdc8e9.zip |
(#8596) Detect resource alias conflicts when titles do not match
The introduction of composite namevars caused the resource title used in
resource aliases to be set as an array, even when the resource only had one
namevar. This would fail to conflict with non-alias entries in the resource
table, which used a string for the title, even though the single element array
contained the same string.
Now, we flatten the key used in the resource table, so that single element
arrays are represented as strings, and will properly conflict with resource
titles.
Paired-With: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/resource/catalog.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb index 0a63ff172..2fdd19b0c 100644 --- a/lib/puppet/resource/catalog.rb +++ b/lib/puppet/resource/catalog.rb @@ -98,7 +98,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph resource.ref =~ /^(.+)\[/ class_name = $1 || resource.class.name - newref = [class_name, key] + newref = [class_name, key].flatten if key.is_a? String ref_string = "#{class_name}[#{key}]" @@ -111,7 +111,10 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph # isn't sufficient. if existing = @resource_table[newref] return if existing == resource - raise(ArgumentError, "Cannot alias #{resource.ref} to #{key.inspect}; resource #{newref.inspect} already exists") + resource_definition = " at #{resource.file}:#{resource.line}" if resource.file and resource.line + existing_definition = " at #{existing.file}:#{existing.line}" if existing.file and existing.line + msg = "Cannot alias #{resource.ref} to #{key.inspect}#{resource_definition}; resource #{newref.inspect} already defined#{existing_definition}" + raise ArgumentError, msg end @resource_table[newref] = resource @aliases[resource.ref] ||= [] @@ -377,7 +380,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph res = Puppet::Resource.new(nil, type) end title_key = [res.type, res.title.to_s] - uniqueness_key = [res.type, res.uniqueness_key] + uniqueness_key = [res.type, res.uniqueness_key].flatten @resource_table[title_key] || @resource_table[uniqueness_key] end |