From 2a0c970b8f91c9687d3f2a1dea5adac44b5f96fb Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Sun, 5 Dec 2010 16:25:06 +0100 Subject: (#5662) Parsedfile doesnt work with mult keyattr When one wants to use the parsedfile provider for a type with more than one key_attribute (e.g. a type for entries in /etc/services with name and protocol as key_attributes) the provider will not store all key_attributes in property_hash and not all keyattributes will be visible in the to_line function. The create method of parsedfile will only put validproperties into the propertyhash. As result :name and all the other key_attributes will not be set. In the flush method however the :name parameter is put in the property_hash but the method does not handle other keyattributes. This patch modifies flush to put all key_attributes into the property hash (Note: @resource.name is basically just an alias for @resource[:name]) --- lib/puppet/provider/parsedfile.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index ffd36e59f..75a215f4b 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -334,7 +334,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider @property_hash[:target] = @resource.should(:target) || self.class.default_target self.class.modified(@property_hash[:target]) end - @property_hash[:name] ||= @resource.name + @resource.class.key_attributes.each do |attr| + @property_hash[attr] ||= @resource[attr] + end self.class.flush(@property_hash) -- cgit From 8b98526b0f81d559fdf85fc8aaf370f75baa5919 Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Thu, 23 Dec 2010 22:11:49 +0100 Subject: (#5662) Fixed tests that didnt stub key_attributes The parsedfile provider calls the method key_attributes of the resource class to decide what resourceparameters must be put in the property_hash. Tests that uses fake resources and only stub resource[:name] must also stub resource.class.key_attributes --- spec/unit/provider/mount/parsed_spec.rb | 1 + spec/unit/provider/ssh_authorized_key/parsed_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb index 7d2e8a84c..3d37fc72e 100755 --- a/spec/unit/provider/mount/parsed_spec.rb +++ b/spec/unit/provider/mount/parsed_spec.rb @@ -51,6 +51,7 @@ module ParsedMountTesting #hash[:provider] = @provider_class.name fakeresource = stub :type => :mount, :name => hash[:name] + fakeresource.class.stubs(:key_attributes).returns([:name]) fakeresource.stubs(:[]).with(:name).returns(hash[:name]) fakeresource.stubs(:should).with(:target).returns(nil) diff --git a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb index 11e9233e0..2e5be165a 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb @@ -104,6 +104,7 @@ describe provider_class do before :each do @resource = stub("resource", :name => "foo") @resource.stubs(:[]).returns "foo" + @resource.class.stubs(:key_attributes).returns( [:name] ) @provider = provider_class.new(@resource) provider_class.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam) -- cgit