- From: Sean OMeara <
>
- To:
- Subject: [chef] Re: Re: Re: Re: Re: notifies on resource not notifying
- Date: Fri, 28 Dec 2012 12:49:44 -0500
Can you gist a code snippet?
-s
On Fri, Dec 28, 2012 at 12:47 PM, Seif Attar
<
>
wrote:
>
I seem to be getting the same problem with the template resource, the
>
resource runs, I can see in the log output that the content has been
>
updated, but the notifies don't trigger.
>
>
Is it possible that I am suffering from the same bug? I can't imagine that a
>
basic resource like template would have a problem with notifications, there
>
must be something with my setup.
>
>
I had a look at the source code of the template and file providers, but
>
couldn't see anywhere that it calls updated_by_last_action(true) :S
>
>
My gut feeling is that it is something that has to do with the windows file
>
provider.
>
>
>
On 27 December 2012 18:46, Seif Attar
>
<
>
>
wrote:
>
>
>
> Thank you both for taking the time to explain this, I get it now.
>
>
>
> To get the teamcity_build resource to notify, all I need to do is call
>
> @new_resource.updated_by_last_action(true)
>
>
>
> Thanks for the advice on the idempotency, I think I will need to take it
>
> with the original cookbook author as he had provided a parameter
>
> 'overwrite'
>
> on the resource, which currently throws an exception if overwrite is false
>
> and the file already existed. I guess to keep with current behaviour:
>
>
>
> If the files doesn't exist -> download and set updated
>
> files exists and override is false -> throw
>
> file exists, override is true and checksums differ -> download and set
>
> updated
>
> file exists, override is true and checksums differ -> do nothing and don't
>
> set updated.
>
>
>
> Had a quick look at adding basic auth to remote_file and it seems it would
>
> require changes to Chef::Rest as well, too risky for my basic ruby skills
>
> :)
>
> copying the checksum code into those recipes would be easier.
>
>
>
> Thanks again,
>
> Seif
>
>
>
>
>
> On 27 December 2012 18:12, Sean OMeara
>
> <
>
>
> wrote:
>
>>
>
>> Hi Seif.
>
>>
>
>> It turns out that I gave you the wrong advice, since I didn't actually
>
>> dig into the teamcity cookbook code (like I am now.)
>
>>
>
>> The gist I sent you was a workaround for when you're using nested Chef
>
>> resources in LWRP code. It would help in a situation like this:
>
>>
>
>> # cookbooks/custom/providers/foo.rb
>
>>
>
>> action :download do
>
>>
>
>> directory "/some/dir" do
>
>> action :create
>
>> owner "fonzi"
>
>>
>
>> remote_file "somefile" do
>
>> source "http://www.example.com/somefile.tgz"
>
>> checksum "123456"
>
>> end
>
>>
>
>> end
>
>>
>
>>
>
>> ^ In that example, "directory" and "remote_file" are Chef resources.
>
>> One of the contracts that a Chef provider has to fulfill is that it
>
>> will set the new_resource.updated_by_last_action(true) it they make a
>
>> change to the system.
>
>>
>
>> If 'directory[/some/dir]' had to be repaired in any way, the
>
>> directory provider setting that flag is what allows notifications to
>
>> happen.
>
>>
>
>> if 'remote_file[somefile]' had to be repaired, the same idea applies.
>
>>
>
>> The bug the gist worked around was that the custom_foo resource
>
>> defined in the LWRP code could not inherit the updated status of the
>
>> nested 'directory' or 'remote_file' resources.
>
>>
>
>>
>
>> While good to know, this is now the problem you have.
>
>>
>
>> The work you're doing is implemented in two pure-ruby library
>
>> functions that ship with the cookbook.
>
>>
>
>> initialize_connection
>
>> download_all
>
>>
>
>> Since these are not idempotent Chef resources, the work-around does not
>
>> apply.
>
>> Please feel free to un-cargo-cult your code. My bad.
>
>>
>
>>
>
>> What you really need to do is setup tests to determine if you need to
>
>> "fix" a teamcity_build resource on disk.
>
>>
>
>> If the resource needs to be repaired, THEN do the work:
>
>> initialize_connection
>
>> download_all
>
>> new_resource.updated_by_last_action(true)
>
>>
>
>> That will allow notifications to work in the default run_context
>
>>
>
>> This deck does a really good job at explaining how it all works.
>
>> http://www.slideshare.net/geekbri/lwrp-presentation#btnNext
>
>>
>
>> -s
>
>>
>
>> On Thu, Dec 27, 2012 at 12:32 PM, 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?
>
>> >
>
>> > Much appreciated,
>
>> >
>
>> > Seif
>
>> >
>
>> >
>
>> >
>
>> > On 27 December 2012 15:52, Sean OMeara
>
>> > <
>
>
>> > wrote:
>
>> >>
>
>> >> Hi Seif!
>
>> >>
>
>> >> This is a bug in the LWRP DSL.
>
>> >>
>
>> >> You can read about it here:
>
>> >> http://tickets.opscode.com/browse/CHEF-3681
>
>> >>
>
>> >> There is a fix coming in Chef 11 which will require a small changes to
>
>> >> the all LWRP code including teamcity and windows cookbooks to make
>
>> >> notifications work.
>
>> >>
>
>> >> In the meantime, you modify the teamcity_build LWRP and cargo-cult the
>
>> >> pattern referenced in the above ticket.
>
>> >>
>
>> >>
>
>> >>
>
>> >> https://gist.github.com/d85be145f3ff824ccc07/0e97d44f20ec65411b141cb46cbeb19bb34b44ad
>
>> >>
>
>> >> Good luck and let me know if you have any questions!
>
>> >>
>
>> >> -s
>
>> >>
>
>> >> On Thu, Dec 27, 2012 at 10:43 AM, Seif Attar
>
>> >> <
>
>
>> >> wrote:
>
>> >> > Hello,
>
>> >> >
>
>> >> > I am writing a recipe that calls 3 resources, the first resource has
>
>> >> > conditional execution and a notifies, goal being that the other 2
>
>> >> > dont
>
>> >> > run
>
>> >> > unless this one passed the condition.
>
>> >> >
>
>> >> > I can see the first resource being run, but it doesn't seem to be
>
>> >> > notifying,
>
>> >> > can someone help figure out what I am messing up? is there a better
>
>> >> > way
>
>> >> > to
>
>> >> > go about this?
>
>> >> >
>
>> >> > Here is a gist of the recipe, and the debug output from Chef
>
>> >> > 10.16.4:
>
>> >> >
>
>> >> > https://gist.github.com/4389024
>
>> >> >
>
>> >> > Any help appreciated.
>
>> >> >
>
>> >> > Thanks
>
>> >
>
>> >
>
>
>
>
>
- [chef] notifies on resource not notifying, Seif Attar, 12/27/2012
- [chef] Re: notifies on resource not notifying, Sean OMeara, 12/27/2012
- [chef] Re: Re: notifies on resource not notifying, Seif Attar, 12/27/2012
- [chef] Re: Re: Re: notifies on resource not notifying, Daniel DeLeo, 12/27/2012
- [chef] Re: Re: Re: notifies on resource not notifying, Sean OMeara, 12/27/2012
- [chef] Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/27/2012
- [chef] Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
- [chef] Re: Re: Re: Re: Re: notifies on resource not notifying, Sean OMeara, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Daniel DeLeo, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Daniel DeLeo, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Daniel DeLeo, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Sean OMeara, 12/28/2012
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: notifies on resource not notifying, Seif Attar, 12/28/2012
Archive powered by MHonArc 2.6.16.