Custom LWRP Initialise Error

Morning Guys

Got a question about LWRP’s. I’m writing a library cookbook and testing components of it as I go.
I’ve written an LWRP to perform a dll drop on a server.
Everything seems ok, I’ve done a lot of reading online about this and managed to narrow it down to this last error.
The error is:
"[2014-07-24T06:59:57-04:00] FATAL: NameError: AW_DLLDrop_dlldrop[7.1_HF05_Overlay_SAML_fix.zip] (AW_DLLDrop::default line 25) had an error: NameError: uninitialized constant Chef::Resource::DllDrop"

The code from the LWRP in question is:
"
def whyrun_supported?
true
end

  action :drop do
    converge_by("Drop #{ @new_resource}") do
      perform_dll_drop
    end
  end

  action :undo do
    converge_by("Undo #{ @new_resource}") do
      undo_dll_drop
    end
  end

  def load_current_resource
    @current_resource = Chef::Resource::DllDrop.new(@new_resource.name)
    @current_resource.name(@new_resource.name)
  end"

Can anyone shed any light on what I’m missing with this? One of my colleagues has pointed out that there may be an issue with @new_resource.name retuning null? Any way I can check this?

Any pointers would be great as I’m struggling a little with this.

Thanks
Chris

I assume your custom resource is in a cookbook called "dll" with the
filename "drop.rb", right?

  • Julian

On Thu, Jul 24, 2014 at 7:10 AM, ChristopherHall@air-watch.com
ChristopherHall@air-watch.com wrote:

Morning Guys

Got a question about LWRP’s. I’m writing a library cookbook and testing
components of it as I go.

I’ve written an LWRP to perform a dll drop on a server.

Everything seems ok, I’ve done a lot of reading online about this and
managed to narrow it down to this last error.

The error is:

“[2014-07-24T06:59:57-04:00] FATAL: NameError:
AW_DLLDrop_dlldrop[7.1_HF05_Overlay_SAML_fix.zip] (AW_DLLDrop::default line
25) had an error: NameError: uninitialized constant Chef::Resource::DllDrop”

The code from the LWRP in question is:

  def whyrun_supported?

    true

  end



  action :drop do

    converge_by("Drop #{ @new_resource}") do

      perform_dll_drop

    end

  end



  action :undo do

    converge_by("Undo #{ @new_resource}") do

      undo_dll_drop

    end

  end



  def load_current_resource

    @current_resource = Chef::Resource::DllDrop.new(@new_resource.name)

    @current_resource.name(@new_resource.name)

  end”

Can anyone shed any light on what I’m missing with this? One of my
colleagues has pointed out that there may be an issue with
@new_resource.name retuning null? Any way I can check this?

Any pointers would be great as I’m struggling a little with this.

Thanks

Chris

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Hi Julian,
Resource file is called dlldrop.rb, provider is the same name.
Cookbook is called AW_DllDrop

I think I was over-complicating it with the current-resource blocks, this cookbook is only run in the event of a dll drop needing to be performed so idempotence is not that important.
I've trimmed it a bit and got it working, I think my mistake was using Chef::Resource::dlldrop when there appears to be no need at all to do that.

I'm working on a similar one to find services and stop them and running into the same thing.

Thanks

-----Original Message-----
From: Julian C. Dunn [mailto:jdunn@aquezada.com]
Sent: 24 July 2014 14:27
To: chef@lists.opscode.com
Subject: [chef] Re: Custom LWRP Initialise Error

I assume your custom resource is in a cookbook called "dll" with the filename "drop.rb", right?

  • Julian

On Thu, Jul 24, 2014 at 7:10 AM, ChristopherHall@air-watch.com ChristopherHall@air-watch.com wrote:

Morning Guys

Got a question about LWRP’s. I’m writing a library cookbook and
testing components of it as I go.

I’ve written an LWRP to perform a dll drop on a server.

Everything seems ok, I’ve done a lot of reading online about this and
managed to narrow it down to this last error.

The error is:

“[2014-07-24T06:59:57-04:00] FATAL: NameError:
AW_DLLDrop_dlldrop[7.1_HF05_Overlay_SAML_fix.zip] (AW_DLLDrop::default
line
25) had an error: NameError: uninitialized constant Chef::Resource::DllDrop”

The code from the LWRP in question is:

  def whyrun_supported?

    true

  end



  action :drop do

    converge_by("Drop #{ @new_resource}") do

      perform_dll_drop

    end

  end



  action :undo do

    converge_by("Undo #{ @new_resource}") do

      undo_dll_drop

    end

  end



  def load_current_resource

    @current_resource = 

Chef::Resource::DllDrop.new(@new_resource.name)

    @current_resource.name(@new_resource.name)

  end”

Can anyone shed any light on what I’m missing with this? One of my
colleagues has pointed out that there may be an issue with
@new_resource.name retuning null? Any way I can check this?

Any pointers would be great as I’m struggling a little with this.

Thanks

Chris

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

If you want to explicitly name the resource instead of having it
auto-inferred by the LWRP DSL, you'll have to make a library and do
this:

https://github.com/opscode-cookbooks/motd-tail/blob/master/libraries/resource_motd_tail.rb#L22-L23

-s

On Thu, Jul 24, 2014 at 8:46 AM, ChristopherHall@air-watch.com
ChristopherHall@air-watch.com wrote:

Hi Julian,
Resource file is called dlldrop.rb, provider is the same name.
Cookbook is called AW_DllDrop

I think I was over-complicating it with the current-resource blocks, this cookbook is only run in the event of a dll drop needing to be performed so idempotence is not that important.
I've trimmed it a bit and got it working, I think my mistake was using Chef::Resource::dlldrop when there appears to be no need at all to do that.

I'm working on a similar one to find services and stop them and running into the same thing.

Thanks

-----Original Message-----
From: Julian C. Dunn [mailto:jdunn@aquezada.com]
Sent: 24 July 2014 14:27
To: chef@lists.opscode.com
Subject: [chef] Re: Custom LWRP Initialise Error

I assume your custom resource is in a cookbook called "dll" with the filename "drop.rb", right?

  • Julian

On Thu, Jul 24, 2014 at 7:10 AM, ChristopherHall@air-watch.com ChristopherHall@air-watch.com wrote:

Morning Guys

Got a question about LWRP’s. I’m writing a library cookbook and
testing components of it as I go.

I’ve written an LWRP to perform a dll drop on a server.

Everything seems ok, I’ve done a lot of reading online about this and
managed to narrow it down to this last error.

The error is:

“[2014-07-24T06:59:57-04:00] FATAL: NameError:
AW_DLLDrop_dlldrop[7.1_HF05_Overlay_SAML_fix.zip] (AW_DLLDrop::default
line
25) had an error: NameError: uninitialized constant Chef::Resource::DllDrop”

The code from the LWRP in question is:

  def whyrun_supported?

    true

  end



  action :drop do

    converge_by("Drop #{ @new_resource}") do

      perform_dll_drop

    end

  end



  action :undo do

    converge_by("Undo #{ @new_resource}") do

      undo_dll_drop

    end

  end



  def load_current_resource

    @current_resource =

Chef::Resource::DllDrop.new(@new_resource.name)

    @current_resource.name(@new_resource.name)

  end”

Can anyone shed any light on what I’m missing with this? One of my
colleagues has pointed out that there may be an issue with
@new_resource.name retuning null? Any way I can check this?

Any pointers would be great as I’m struggling a little with this.

Thanks

Chris

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

On Thu, Jul 24, 2014 at 9:46 AM, ChristopherHall@air-watch.com
ChristopherHall@air-watch.com wrote:

Hi Julian,
Resource file is called dlldrop.rb, provider is the same name.
Cookbook is called AW_DllDrop

Hi Christopher,

The LWRP framework will create a class that's generated from a
combination of your cookbook name and resource name. So in this
situation the generated classname will be
Chef::Resource::AWDllDropDllDrop (something like that, I probably have
the capitalization wrong)

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Thanks Julian, I've got it working now, I had to remove the first AWDllDrop for it to pick the resource ok.
Another question I have, is it possible to use Chef resources within a custom resource (such as calling batch for example?)
I have tried using just 'batch' then Chef::Resource::Batch but I've had no success. I've had to move it to the default.rb now for it to work which is not what I wanted to do.
I'm pretty sure this is a namespace issue with how I'm trying to call batch, but all I get are 'unitialised class or method not recognised' errors.

Thanks
Chris

-----Original Message-----
From: Julian C. Dunn [mailto:jdunn@aquezada.com]
Sent: 25 July 2014 01:39
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: Custom LWRP Initialise Error

On Thu, Jul 24, 2014 at 9:46 AM, ChristopherHall@air-watch.com ChristopherHall@air-watch.com wrote:

Hi Julian,
Resource file is called dlldrop.rb, provider is the same name.
Cookbook is called AW_DllDrop

Hi Christopher,

The LWRP framework will create a class that's generated from a combination of your cookbook name and resource name. So in this situation the generated classname will be Chef::Resource::AWDllDropDllDrop (something like that, I probably have the capitalization wrong)

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

On Mon, Jul 28, 2014 at 4:36 AM, ChristopherHall@air-watch.com
ChristopherHall@air-watch.com wrote:

Thanks Julian, I've got it working now, I had to remove the first AWDllDrop for it to pick the resource ok.
Another question I have, is it possible to use Chef resources within a custom resource (such as calling batch for example?)

Yes, it's possible. Can you post the exact error you are getting along
with the code?

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

I'm hitting the same question with the notifies resource and can provide a
code sample/error message.

provider.rb · GitHub shows an example
provider, resource and a wrapper recipe that can call the notifies without
issue. Moving the notifies call into the provider, as illustrated in
resource.rb · GitHub, causes the error.

Seems like I'm not including something I should be, but it escapes me.

On Wed, Jul 30, 2014 at 8:21 AM, Julian C. Dunn jdunn@aquezada.com wrote:

On Mon, Jul 28, 2014 at 4:36 AM, ChristopherHall@air-watch.com
ChristopherHall@air-watch.com wrote:

Thanks Julian, I've got it working now, I had to remove the first
AWDllDrop for it to pick the resource ok.
Another question I have, is it possible to use Chef resources within a
custom resource (such as calling batch for example?)

Yes, it's possible. Can you post the exact error you are getting along
with the code?

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

On Wednesday, July 30, 2014 at 2:02 PM, Kevin Bridges wrote:

I'm hitting the same question with the notifies resource and can provide a code sample/error message.

provider.rb · GitHub shows an example provider, resource and a wrapper recipe that can call the notifies without issue. Moving the notifies call into the provider, as illustrated in resource.rb · GitHub, causes the error.

Seems like I'm not including something I should be, but it escapes me.

Notifications are a property of a resource, so the method is defined for resources but not providers. You could do something like new_resource.notifies(ARGS) I think. Be sure to test that though, there is a possible gotcha involving looking up the actual ruby object that matches the 'service[apache2]’ string.

--
Daniel DeLeo

What you describe sounds accurate ... it is now seems to be raising the
gotcha you mention. The error moved from no resource for notifies to:

INFO: apache2_web_app[/etc/httpd/sites-available/basic_web_app.conf]
sending reload action to service[apache2] (delayed)
DEBUG: Re-raising exception: NoMethodError - undefined method `run_action'
for "service[apache2]":String

Is there a way around this or should I consider a different approach?

Thanks

On Wed, Jul 30, 2014 at 4:47 PM, Daniel DeLeo dan@kallistec.com wrote:

On Wednesday, July 30, 2014 at 2:02 PM, Kevin Bridges wrote:

I'm hitting the same question with the notifies resource and can provide
a code sample/error message.

provider.rb · GitHub shows an example
provider, resource and a wrapper recipe that can call the notifies without
issue. Moving the notifies call into the provider, as illustrated in
resource.rb · GitHub, causes the error.

Seems like I'm not including something I should be, but it escapes me.

Notifications are a property of a resource, so the method is defined for
resources but not providers. You could do something like
new_resource.notifies(ARGS) I think. Be sure to test that though, there
is a possible gotcha involving looking up the actual ruby object that
matches the 'service[apache2]’ string.

--
Daniel DeLeo