diff options
author | Stefan Schulte <stefan.schulte@taunusstein.net> | 2010-12-23 18:08:37 +0100 |
---|---|---|
committer | Stefan Schulte <stefan.schulte@taunusstein.net> | 2010-12-23 21:49:05 +0100 |
commit | 02b311113df84646406737ccfad961c5b6df4ae8 (patch) | |
tree | 9ef1ec49f00c3df9891bd7a203f5ab05b1bb4dfa /spec/unit | |
parent | cc1f2b39a65e8b74c8e59a2bf7d8f47a35985ee4 (diff) | |
download | puppet-02b311113df84646406737ccfad961c5b6df4ae8.tar.gz puppet-02b311113df84646406737ccfad961c5b6df4ae8.tar.xz puppet-02b311113df84646406737ccfad961c5b6df4ae8.zip |
(#5605) Prefetch doesnt work with composite keys
The uniqueness_key method of a type or resource object should return a
key that can be used to identify this resource. In fact puppet seldomly
uses this method and instead uses resource[:name] as an identifier.
While this is totally fine for resourcetypes with a single
key_attribute (and resource[:name] returning the namevar), it breaks
things as soon as one creates a type with a composite key (prefetching
for example is broken). To ease the process of replacing calls to
resource[:name] to resource.uniqueness_key, the method uniqueness_key now
just returns name_var if there is only one key_attribute (immitating
self[:name]) and only returns an array of all the values of all the
key_attributes if we have more than one key_attribute.
The resourcehash which is passed to providers in their prefetch method
is now build with uniqueness_key as the hashkey. Because of the new
behaviour of uniqueness_key we hopefully wont break existing providers
while allowing new providers for types with composite keys to implement
correct prefetch methods.
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/resource_spec.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index e65e8a13a..092ae8ce0 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -268,7 +268,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 @@ -770,7 +770,14 @@ describe Puppet::Resource do 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} ] ] ] ] |