Friday, January 21, 2011

Testing your chef cookbook while development

While developing chef cookbooks, it is really useful to run it and test its actual behavior and rectify the mistakes to match the expected behavior. Also the test needs to be performed across various platforms that you cookbook is supporting.

This can be done easily by running the cookbook with chef-solo against any environment which can be easily constructed and teared down. It is really important to bring back the test environment to its initial state before running the test again to avoid unexpected behaviors.

Amazon ec2 instances can be used for these purposes. You can instantiate an instance, run the cookbook, verify and then terminate the instance. And this is repeated until the development is complete.

What I use is a set of local virtualbox images for various platforms against which my recipe has to tested. I maintain these images with proper snapshots. So I have a snapshot taken before running the script basically in a clean state. After running the test, just I revert to the initial clean state so that my next run is not affected by the artifacts of the previous test runs.

In addition to the cost savings, it is much faster to revert to a snapshot in vmware/virtualbox than terminating and re-instantiating an ec2 instance. The snapshots can be taken in a live(running state) so that you can totally cutdown the boot time on every test run.


Jeroen said...

I'm actually looking for a good way to test my recipes as well.

So far the best automated solution I have seen is

However, I think this could be done slightly better by also using Vagrant (, it will do the Virtualbox management for you.

So still need a library that mixes cucumber nagios with Vagrant :)


Noorul Islam K M said...

Did you try Berkshelf and its vagrant plugin?