[chef] Re: Re: Re: notifies on resource not notifying


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: notifies on resource not notifying
  • Date: Thu, 27 Dec 2012 11:07:57 -0700


On Thursday, December 27, 2012 at 10:32 AM, Seif Attar wrote:

Thanks Sean,

My ruby skills are limited, and I didn't quite get that gist or what it was doing, but I did manage to get something working:

https://github.com/seif/teamcity/commit/125633db4ccd62a43f3946feae00ba358b5d75b1

I am not sure what
if sub_run_context.resource_collection.any?(&:updated?)


Is supposed to do, as it was always returning false for me. What effects will removing it do? does the provider look sane to you now?

I think Sean was assuming your LWRP was built upon a collection of core chef resources, in which case the bug he described would likely be your issue. Looking at your provider code, I see that it's all plain ruby code, so it's not relevant to you. If you'd created resources in your provider's `action` block, then the line above would iterate through them and see if any had been marked updated. I wrote an explanation of how the two approaches differ on our page about changes in Chef 11 (near the bottom of the page in the LWRP section): http://wiki.opscode.com/display/chef/Breaking+Changes+in+Chef+11


Much appreciated,
Seif
Backing up a bit, the thing that's making this work now is the line that does (true)`. This sets a flag on the resource that indicates that the resource was updated and its notifications should be fired.

In your provider code (as now written), your resource will always be marked updated. If you expect your LWRP to make changes to the system every time it runs, then this is the right thing to do. 

In general, providers are expected to be idempotent, that is, they will not take any action if the system is already in the desired state. When this happens, the provider should not mark the resource as updated. Looks to me like you'd want to do this based on whether the artifacts you've downloaded previously match the one that you're fetching from the server. The `remote_file` resource currently does this: https://github.com/opscode/chef/blob/master/lib/chef/provider/remote_file.rb

It looks like you need HTTP basic auth for your LWRP, and I'm not sure if you can use a hack (like putting auth info in the URL) to make remote_file to use basic auth or not. If you can make it work, using remote_file would provide idempotent behavior for you. If not, I'd encourage you to submit a patch for remote_file to add a basic auth option.

HTH,

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§