[chef] Re: Re: Re: [ANN] execute a single Chef recipe with chef-recipe command


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: [ANN] execute a single Chef recipe with chef-recipe command
  • Date: Sun, 18 Nov 2012 12:20:57 -0800


On Sunday, November 18, 2012 at 12:04 PM, Bryan Berry wrote:

I would be happy to try. Forgive me if I ask dumb questions, working w/ real Ruby libraries is still a new experience for me.

To be honest, the part of this code that I understand the least is the monkey-patch from your orginal gist

class Chef::Client
    attr_reader :events
 end

I assume that to get rid of the monkey patch, I would just add `attr_reader :events` directly to lib/chef/client.rb, correct?
Short answer: yes. Longer answer:

Recall that in ruby, classes are "open" so you can add or overwrite methods/constants at any time. Here you're just adding Client#events (which returns @events) to the class.

Chef::Client#initialize runs `EventDispatch::Dispatcher.new(formatter)` to create the event dispatcher, and later creates the RunContext with the event dispatcher, but since we need to customize RunContext compared to what Chef::Client normally does, we need to get the event dispatcher out of the client so it can be passed in to RunContext#initialize. This could have been done with `instance_variable_get` in the original, but I like that even less than monkey patching.

 
  
by tests, are you looking for something like this? https://github.com/opscode/chef/blob/master/spec/unit/application/solo_spec.rb

Ideally we'd have a few levels of tests. Making sure that the command line options effect the desired config changes via unit tests is good. I'd also like to see a functional (in spec/functional) test that runs a simple recipe (single file resource is fine) to ensure that everything is correctly wired up all the way through.
 

tks again for the original gist.

I would also like to merge in my changes from chef-rewind. Keep meaning to do that

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§