On Sat, 11 Sep 2010 19:38:32 -0500, James Cammarata <[email protected]> wrote:
> My bad, I think I just missed those were modified as well. I can
reinstate
> those changes as well.
> 
> As for the architectural issue, yeah it would probably be better for
> providers to warn/ignore this on their own rather than generalizing it in
> type.rb, but that may be much more work so I think it's important to get
> this check back in rather than causing errors or random behavior on
> systems.

Restored the unit tests, also pushed to github:
git://github.com/jimi1283/puppet.git

---
 lib/puppet/type.rb             |    6 ++++++
 spec/unit/type/service_spec.rb |    8 ++++++++
 test/ral/manager/attributes.rb |    5 ++++-
 3 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 53c23aa..39dcf03 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 0f4a507..0958a69 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 74a4d07..6d0284d 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
--
1.5.5.6


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to