[chef-dev] Re: Guidance on Ohai Plugin Test


Chronological Thread 
  • From: David Petzel < >
  • To: Chef Dev < >
  • Subject: [chef-dev] Re: Guidance on Ohai Plugin Test
  • Date: Wed, 7 May 2014 09:35:10 -0400

Responding to the list rather than directly this time...
Thanks to Ranjib and Ryans I got this working. I couldn't make it work in Chefspec and in hindsight I'm not sure that made sense. Using some of the spec examples in the ohai project I ended up using rspec directly and mocking the network plugin data.

Thanks again


On Tue, May 6, 2014 at 4:30 PM, David Petzel < " target="_blank"> > wrote:
I believe I'm only interested in testing the plugin. 
Unfortunately test-kitchen isn't an option currently. Given our environment I have nodes in a lot of VLANs and we don't have the ability to spawn instances in all those VLANS. So My goal was to stub out some IP information, and then make sure the plugin is properly detects the appropriate information (IE based on this IP, it should report itself in VLAN XYZ). Due to the amount of stubbing I was hoping to leverage ChefSpec for this (unless of course its totally the wrong approach :) )



On Tue, May 6, 2014 at 4:12 PM, Ranjib Dey < " target="_blank"> > wrote:
do you want to test only the plugin ? or the plugin as part of the whole chef run?

You can tell chefspec to execute a  provider body (i.e. step_into => ['ohai_plugin']), but this can be risky if you dont know what the provider does (i have not used ohai_plugin, i only used step_into with our own lwrps.
you can also use test-kitchen (or even chef metal and serverspec)  to do this safely ,


i run linux and i test all such scenarios using raw lxc. if i want to test an individual plugin i would do this:
1. spawn an lxc container
2. load ohai on host (including your plugin.. ohai 7 simplifies this) 
3, fork inside lxc,  and run pluguin, return the ohai data as json (IPC)
4. assert against the return data on host

as you can see, this wont let you test cross platform stuff.
cheers
ranjib



On Tue, May 6, 2014 at 12:30 PM, David Petzel < " target="_blank"> > wrote:
Hey Folks,
I have a cookbook which contains an Ohai plugin. In a nutshell the plugin leverages some Ohai attributes related to networking to make some decisions about its locations in our environment. From those decisions it populates some additional attributes. (pretty simple).

The plugin works, however I need to make some adjustments so I am attempting to back fill some testing before I get started. I'm a little stumped on how to do this, and I can find any test examples outside of the Ohai project itself.

I was hoping to leverage Chefspec to do the testing, however I can't figure out how to tell Chefspec to "go run this ohai plugin". I had thought I could just add the plugin call somehow in my before block, but I can't seem to figure out the right syntax.

Does anyone have an example, or guidance on how I can/should add these types of tests?






Archive powered by MHonArc 2.6.16.

§