summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2010-09-11 10:23:38 -0500
committerJames Turnbull <james@lovedthanlost.net>2010-09-14 09:22:19 +1000
commit9bdfe694bc6c60a48b45f8dd49c20c6da31445f7 (patch)
tree70e91e31b36bdc27e4338cde6d0a6656b9ffbbb0
parent14b33402812756dc0cd3e84619afa211d449d59f (diff)
downloadpuppet-9bdfe694bc6c60a48b45f8dd49c20c6da31445f7.tar.gz
puppet-9bdfe694bc6c60a48b45f8dd49c20c6da31445f7.tar.xz
puppet-9bdfe694bc6c60a48b45f8dd49c20c6da31445f7.zip
Fix for Bug #4756 - Providers no longer respect missing features
Restored deleted lines from type.rb and reinstated unit tests
-rw-r--r--lib/puppet/type.rb6
-rwxr-xr-xspec/unit/type/service_spec.rb8
-rwxr-xr-xtest/ral/manager/attributes.rb5
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 291179a02..ccb2b492a 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -472,6 +472,12 @@ class Type
raise Puppet::Error, "Resource type #{self.class.name} does not support parameter #{name}"
end
+ if provider and ! provider.class.supports_parameter?(klass)
+ missing = klass.required_features.find_all { |f| ! provider.class.feature?(f) }
+ info "Provider %s does not support features %s; not managing attribute %s" % [provider.class.name, missing.join(", "), name]
+ return nil
+ end
+
return @parameters[name] if @parameters.include?(name)
@parameters[name] = klass.new(:resource => self)
diff --git a/spec/unit/type/service_spec.rb b/spec/unit/type/service_spec.rb
index 0f4a50750..0958a69fa 100755
--- a/spec/unit/type/service_spec.rb
+++ b/spec/unit/type/service_spec.rb
@@ -76,10 +76,18 @@ describe Puppet::Type.type(:service), "when validating attribute values" do
it "should allow setting the :enable parameter if the provider has the :enableable feature" do
Puppet::Type.type(:service).defaultprovider.stubs(:supports_parameter?).returns(true)
+ Puppet::Type.type(:service).defaultprovider.expects(:supports_parameter?).with(Puppet::Type.type(:service).attrclass(:enable)).returns(true)
svc = Puppet::Type.type(:service).new(:name => "yay", :enable => true)
svc.should(:enable).should == :true
end
+ it "should not allow setting the :enable parameter if the provider is missing the :enableable feature" do
+ Puppet::Type.type(:service).defaultprovider.stubs(:supports_parameter?).returns(true)
+ Puppet::Type.type(:service).defaultprovider.expects(:supports_parameter?).with(Puppet::Type.type(:service).attrclass(:enable)).returns(false)
+ svc = Puppet::Type.type(:service).new(:name => "yay", :enable => true)
+ svc.should(:enable).should be_nil
+ end
+
it "should split paths on ':'" do
FileTest.stubs(:exist?).returns(true)
FileTest.stubs(:directory?).returns(true)
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb
index 74a4d0708..6d0284d9e 100755
--- a/test/ral/manager/attributes.rb
+++ b/test/ral/manager/attributes.rb
@@ -229,7 +229,10 @@ class TestTypeAttributes < Test::Unit::TestCase
end
yes.each { |a| assert(resource.should(a), "Did not get value for #{a} in #{prov.name}") }
no.each do |a|
- # These may or may not get passed to the provider. We shouldn't care.
+ assert_nil(resource.should(a), "Got value for unsupported %s in %s" % [a, prov.name])
+ if Puppet::Util::Log.sendlevel?(:info)
+ assert(@logs.find { |l| l.message =~ /not managing attribute #{a}/ and l.level == :info }, "No warning about failed %s" % a)
+ end
end
@logs.clear