Missing Notification from LWRP

Chef 0.10.8. I have an LWRP for the package resource that doesn’t send
notifications. I have a very simple test case that demonstrates the
problem. Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info(“installing #{new_resource.name}”)
end

Here is my recipe:

package “the_package” do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block “the_observer” do
block do
Chef::Log.info(“the observer has been notified”)
end
action :nothing
end

Here is the result:


[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create notification to
the ruby block, which would print “the observer has been notified”. I have
tried a number of variations of this test case:

  • using subscribes instead of notifies (fails)
  • adding supports :create => true on the ruby block (fails)
  • using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen

Kevin,

I suspect you're hitting this bug:
http://tickets.opscode.com/browse/CHEF-2404.

Jake.

On Sat, Feb 11, 2012 at 10:09 AM, Kevin Christen
kevin.christen@gmail.com wrote:

Chef 0.10.8. I have an LWRP for the package resource that doesn't send
notifications. I have a very simple test case that demonstrates the problem.
Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info("installing #{new_resource.name}")
end

Here is my recipe:

package "the_package" do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

Here is the result:

...
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create notification to
the ruby block, which would print "the observer has been notified". I have
tried a number of variations of this test case:

using subscribes instead of notifies (fails)
adding supports :create => true on the ruby block (fails)
using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen

Jake,

Thanks for the quick response, but unless I misunderstand the ticket,
that's not my problem. I changed my recipe to use the old-style
notification syntax:

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

package "my_package" do
provider :test_my_package
action :install
notifies :create, resources(:ruby_block => "the_observer")
end

and the results are the same: no notification is sent to "the_observer".
Other ideas?

Thanks,
Kevin Christen

On Sat, Feb 11, 2012 at 9:31 AM, Jake Vanderdray
jvanderdray@customink.comwrote:

Kevin,

I suspect you're hitting this bug:
http://tickets.opscode.com/browse/CHEF-2404.

Jake.

On Sat, Feb 11, 2012 at 10:09 AM, Kevin Christen
kevin.christen@gmail.com wrote:

Chef 0.10.8. I have an LWRP for the package resource that doesn't send
notifications. I have a very simple test case that demonstrates the
problem.
Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info("installing #{new_resource.name}")
end

Here is my recipe:

package "the_package" do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

Here is the result:

...
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing
ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create notification
to
the ruby block, which would print "the observer has been notified". I
have
tried a number of variations of this test case:

using subscribes instead of notifies (fails)
adding supports :create => true on the ruby block (fails)
using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen

As far as I understand correctly you did not mark you resource as updated.
You have to do that in order to enforce notification to be sent

@new_resource.updated_by_last_action(true)

--max

On Sat, Feb 11, 2012 at 8:13 AM, Kevin Christen kevin.christen@gmail.comwrote:

Jake,

Thanks for the quick response, but unless I misunderstand the ticket,
that's not my problem. I changed my recipe to use the old-style
notification syntax:

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

package "my_package" do
provider :test_my_package
action :install
notifies :create, resources(:ruby_block => "the_observer")
end

and the results are the same: no notification is sent to "the_observer".
Other ideas?

Thanks,
Kevin Christen

On Sat, Feb 11, 2012 at 9:31 AM, Jake Vanderdray <
jvanderdray@customink.com> wrote:

Kevin,

I suspect you're hitting this bug:
http://tickets.opscode.com/browse/CHEF-2404.

Jake.

On Sat, Feb 11, 2012 at 10:09 AM, Kevin Christen
kevin.christen@gmail.com wrote:

Chef 0.10.8. I have an LWRP for the package resource that doesn't send
notifications. I have a very simple test case that demonstrates the
problem.
Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info("installing #{new_resource.name}")
end

Here is my recipe:

package "the_package" do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

Here is the result:

...
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing
ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create
notification to
the ruby block, which would print "the observer has been notified". I
have
tried a number of variations of this test case:

using subscribes instead of notifies (fails)
adding supports :create => true on the ruby block (fails)
using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen

+1
See e.g. https://github.com/opscode/chef/blob/master/chef/lib/chef/provider/file.rb#L63

On Feb 11, 2012, at 11:22 AM, Max Gorbul max@gorbul.net wrote:

As far as I understand correctly you did not mark you resource as updated. You have to do that in order to enforce notification to be sent

@new_resource.updated_by_last_action(true)

--max

On Sat, Feb 11, 2012 at 8:13 AM, Kevin Christen kevin.christen@gmail.com wrote:
Jake,

Thanks for the quick response, but unless I misunderstand the ticket, that's not my problem. I changed my recipe to use the old-style notification syntax:

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

package "my_package" do
provider :test_my_package
action :install
notifies :create, resources(:ruby_block => "the_observer")
end

and the results are the same: no notification is sent to "the_observer". Other ideas?

Thanks,
Kevin Christen

On Sat, Feb 11, 2012 at 9:31 AM, Jake Vanderdray jvanderdray@customink.com wrote:
Kevin,

I suspect you're hitting this bug:
http://tickets.opscode.com/browse/CHEF-2404.

Jake.

On Sat, Feb 11, 2012 at 10:09 AM, Kevin Christen
kevin.christen@gmail.com wrote:

Chef 0.10.8. I have an LWRP for the package resource that doesn't send
notifications. I have a very simple test case that demonstrates the problem.
Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info("installing #{new_resource.name}")
end

Here is my recipe:

package "the_package" do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

Here is the result:

...
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create notification to
the ruby block, which would print "the observer has been notified". I have
tried a number of variations of this test case:

using subscribes instead of notifies (fails)
adding supports :create => true on the ruby block (fails)
using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen

Max and Andi,

Thanks, that was it. And with that addition the new notification syntax
works as well. I'm going to update the wiki; this seems like a critical
thing to know when writing an LWRP.

Thanks again,
Kevin Christen

On Sat, Feb 11, 2012 at 10:24 AM, Andiabes andi.abes@gmail.com wrote:

+1
See e.g.
https://github.com/opscode/chef/blob/master/chef/lib/chef/provider/file.rb#L63

On Feb 11, 2012, at 11:22 AM, Max Gorbul max@gorbul.net wrote:

As far as I understand correctly you did not mark you resource as updated.
You have to do that in order to enforce notification to be sent

@new_resource.updated_by_last_action(true)

--max

On Sat, Feb 11, 2012 at 8:13 AM, Kevin Christen kevin.christen@gmail.comwrote:

Jake,

Thanks for the quick response, but unless I misunderstand the ticket,
that's not my problem. I changed my recipe to use the old-style
notification syntax:

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

package "my_package" do
provider :test_my_package
action :install
notifies :create, resources(:ruby_block => "the_observer")
end

and the results are the same: no notification is sent to "the_observer".
Other ideas?

Thanks,
Kevin Christen

On Sat, Feb 11, 2012 at 9:31 AM, Jake Vanderdray <
jvanderdray@customink.com> wrote:

Kevin,

I suspect you're hitting this bug:
http://tickets.opscode.com/browse/CHEF-2404.

Jake.

On Sat, Feb 11, 2012 at 10:09 AM, Kevin Christen
kevin.christen@gmail.com wrote:

Chef 0.10.8. I have an LWRP for the package resource that doesn't send
notifications. I have a very simple test case that demonstrates the
problem.
Here is the LWRP, from file cookbooks/test/providers/my_package.rb:

action :install do
Chef::Log.info("installing #{new_resource.name}")
end

Here is my recipe:

package "the_package" do
provider :test_my_package
notifies :create, "ruby_block[the_observer]"
end

ruby_block "the_observer" do
block do
Chef::Log.info("the observer has been notified")
end
action :nothing
end

Here is the result:

...
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing package[the_package]
action install (test::the_package line 1)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: installing the_package
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Processing
ruby_block[the_observer]
action nothing (test::the_package line 6)
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Chef Run complete in 0.006884
seconds
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Running report handlers
[Sat, 11 Feb 2012 09:02:04 -0600] INFO: Report handlers complete

I expect the install action of the package to send a create
notification to
the ruby block, which would print "the observer has been notified". I
have
tried a number of variations of this test case:

using subscribes instead of notifies (fails)
adding supports :create => true on the ruby block (fails)
using a built in provider instead of an LWRP (succeeds)

What am I missing?

Thanks,
Kevin Christen