Please review pull request #562: (#12960) Fix puppet resource <type> if type has no providers opened by (stschulte)
Description:
puppet resource type calls the instances method of the type class. The
instances method then calls providers_by_source which can fail if the
following conditions are true
1) there is at least one provider defined for the type
2) all providers are unsuitable
If both requirements are met, the method self.defaultprovider will
return nil and we get the following error message (provided by Ben Ford)# puppet resource maillist puppet/type.rb:902:in `providers_by_source': undefined method `source' for nil:NilClass (NoMethodError)The fix handles the case where defaultprovider can be nil
- Opened: Mon Mar 05 22:01:58 UTC 2012
- Based on: puppetlabs:2.7.x (3c422310c05e884c65b24c9af76e56a8d625d6c7)
- Requested merge: stschulte:ticket/2.7.x/12960 (9686de4ad6a0d9c29be67a7d0d9c2f502cb56789)
Diff follows:
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 111af32..867936c 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -905,9 +905,10 @@ def self.instances
# Return a list of one suitable provider per source, with the default provider first.
def self.providers_by_source
- # Put the default provider first, then the rest of the suitable providers.
+ # Put the default provider first (can be nil), then the rest of the suitable providers.
sources = []
[defaultprovider, suitableprovider].flatten.uniq.collect do |provider|
+ next if provider.nil?
next if sources.include?(provider.source)
sources << provider.source
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index 10fe474..d66c097 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -611,6 +611,30 @@
end
end
+ describe "::instances" do
+ before :each do
+ @fake_type = Puppet::Type.newtype(:foo) do
+ newparam(:name) do
+ isnamevar
+ end
+ newproperty(:prop1) do
+ end
+ end
+ @unsuitable_provider = Puppet::Type.type(:foo).provide(:fake1) do
+ confine :exists => '/no/such/file'
+ mk_resource_methods
+ def instances
+ []
+ end
+ end
+ end
+
+ it "should not fail if no suitable providers are found" do
+ lambda { @fake_type.instances }.should_not raise_error
+ end
+ end
+
+
describe "::ensurable?" do
before :each do
class TestEnsurableType < Puppet::Type
-- 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.
