diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2011-03-15 17:04:49 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2011-03-15 17:04:49 -0700 |
| commit | 658bdb72bee3ad664627a71793213e6540afd5cb (patch) | |
| tree | cd2199f12d9bfc7e72da0fed6198c0f6060b38fb | |
| parent | 4c9bd43bc2f5fde9d86196e8689dced929d39aad (diff) | |
| parent | 02b311113df84646406737ccfad961c5b6df4ae8 (diff) | |
Merge branch 'ticket/2.6.x/5605' of git://github.com/stschulte/puppet into 2.6.next
| -rw-r--r-- | lib/puppet/resource.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/transaction.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/resource_spec.rb | 11 |
4 files changed, 24 insertions, 6 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 214516908..0f4e24cc4 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -243,11 +243,16 @@ class Puppet::Resource h = self.to_hash h[namevar] ||= h[:name] h[:name] ||= h[namevar] - h.values_at(*key_attributes.sort_by { |k| k.to_s }) + # Simulate the same behaviour like Type#uniqueness_key + if key_attributes.size == 1 + h[namevar] + else + h.values_at(*key_attributes) + end end def key_attributes - return(resource_type.respond_to? :key_attributes) ? resource_type.key_attributes : [:name] + resource_type.respond_to?(:key_attributes) ? resource_type.key_attributes : [:name] end # Convert our resource to Puppet code. diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index aa650eea1..6c816f130 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -245,7 +245,7 @@ class Puppet::Transaction @catalog.vertices.each do |resource| if provider = resource.provider and provider.class.respond_to?(:prefetch) prefetchers[provider.class] ||= {} - prefetchers[provider.class][resource.name] = resource + prefetchers[provider.class][resource.uniqueness_key] = resource end end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 205d809c1..c8d8688b0 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -200,7 +200,13 @@ class Type end def uniqueness_key - to_resource.uniqueness_key + # If we have only one namevar use that one (res.uniqueness_key behaves + # like res[:name] in that case). Otherwise use an array of all keyattributes + if name_var + self[:name] + else + @parameters.values_at(*self.class.key_attributes).collect {|p| p.value } + end end # Create a new parameter. Requires a block and a name, stores it in the diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 345ccd06e..6f94409ab 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -276,7 +276,7 @@ describe Puppet::Resource do describe "when referring to a resource with name canonicalization" do it "should canonicalize its own name" do res = Puppet::Resource.new("file", "/path/") - res.uniqueness_key.should == ["/path"] + res.uniqueness_key.should == "/path" res.ref.should == "File[/path/]" end end @@ -800,7 +800,14 @@ type: File end describe "when generating the uniqueness key" do - it "should include all of the key_attributes in alphabetical order by attribute name" do + + it "should use namevar if there is only one key_attribute" do + Puppet::Type.type(:file).stubs(:key_attributes).returns [:path] + res = Puppet::Resource.new("file", "/my/file", :parameters => {:owner => 'root', :content => 'hello'}) + res.uniqueness_key.should == '/my/file' + end + + it "should include all of the key_attributes" do Puppet::Type.type(:file).stubs(:key_attributes).returns [:myvar, :owner, :path] Puppet::Type.type(:file).stubs(:title_patterns).returns( [ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ] |
