Ask Your Question

Under which conditions does @resource exist in a custom provider?

asked 2015-09-17 10:46:47 -0500

roidelapluie gravatar image

In certains conditions @resource is nil in custom providers. When can I safely use it and how can I get parameters otherwise?

Code is there

Failing travis test is there

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-09-21 05:16:46 -0500

roidelapluie gravatar image

updated 2015-09-21 06:55:00 -0500

He is the final answer -

@resounce is present when the resource is in the catalog - resources auto-discovered by self.instances that are not in the catalog won't have @resource

In this case my tests are wrong.

edit flag offensive delete link more

answered 2015-09-18 10:14:58 -0500

Jeremiah Powell gravatar image

The provided code is using @property_hash and @resource both with brackets to reference a hashed property. Either one could be the reported symptom of derefrencing [] on nil.

@resource should exist once the type is instantiated. You can see this by comparing with rspec nil with the return of instances or Type(:yourtype).new($somedata) and seeing the failure results. The diff should contain a tree of available data and symbols including the always present @resource and any getter or setter methods.

Since you have self.instances I would check that it did not return nothing as well. Checking your code I see that it does not call new in self.instances on the data it collects. I would not expect that to work. (Also since you have self.instances you might be able to leverage mkresourcemethods instead of the wall of getter/setter used here. See Building a Provider that uses Self.instances.)

@property_hash is only populated when self.instances exists in a provider. It is created on the return value of that function which should have passed through the call to new to instantiate a new instance of the type. See the Puppet provider.rb for the documentation (350-379 in

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-09-17 10:46:47 -0500

Seen: 531 times

Last updated: Sep 21 '15