[PUP-7062] Exception thrown when implementing create in both child and parent provider Created: 2017/01/04  Updated: 2017/01/05  Resolved: 2017/01/05

Status: Closed
Project: Puppet
Component/s: Types and Providers
Affects Version/s: PUP 3.8.7
Fix Version/s: None

Type: Bug Priority: Normal
Reporter: Nicolai Marck Ødum Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 14.0.4


Template:
Acceptance Criteria:

mytype{ "test":
   standard => "x",
   special => "y"
 }

Info: Applying configuration version '1483531010'
child
parent
Notice: /Stage[main]/test/MyType['test']/ensure: created

QA Risk Assessment: Needs Assessment

 Description   

Given this pseudo code

Puppet::Type.newtype(:mytype) do
 ensurable do
    defaultvalues
    defaultto :present
  end
  feature :myfeature, 'Something important.'
  newproperty(:standard) do
  end
 
  newproperty(:special, :required_features => :myfeature) do
  end
end
 
Puppet::Type.type(:mytype).provide(:myProvider) do
 
  mk_resource_methods
 
  def create
    #do something
    puts parent
  end
end
 
Puppet::Type.type(:mytype).provide(:myOtherProvider,, :parent => :myProvider) do
 
  has_feature :myfeature
  def create
    #do something
    puts child
    super.create
  end
end

When I call it

 
 mytype{ "test":
   standard => "x",
   special => "y"
 }

I see the following in the log

Info: Applying configuration version '1483531010'
child
parent
Error: Could not set 'present' on ensure: undefined method `create' for nil:NilClass at 4:/etc/puppet/manifests/test.pp
Error: Could not set 'present' on ensure: undefined method `create' for nil:NilClass at 4:/etc/puppet/manifests/test.pp
Wrapped exception:
undefined method `create' for nil:NilClass



 Comments   
Comment by Moses Mendoza [ 2017/01/04 ]

Hi Nicolai Marck Ødum - thanks for filing.

In the definition of myOtherProvider, I believe you'll want to change super.create to just super. I.e.,

Puppet::Type.type(:mytype).provide(:myOtherProvider, :parent => :myProvider) do
 
  has_feature :myfeature
  def create
    #do something
    puts "child"
    super
  end
end

super is a special keyword in ruby, and when invoked will call the current method name on the parent class - in this case, the create method of the parent class. It's not an object and doesn't have attributes on it's own, so it has no create method defined, itself.

Comment by Nicolai Marck Ødum [ 2017/01/05 ]

Solution suggested by Moses Mendoza worked - it was a error in my code and not puppet

Generated at Sat Dec 14 17:59:24 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.