New Gem Creates Test Boilerplate for Chef Cookbooks
Meez, written by Paul Czarkowski of Rackspace is a command line tool for creating new cookbooks with all the boilerplate necessary to start practicing TDD on your infrastructure. Originally a skeleton cookbook, meez has since evolved into a more flexible tool that allows you to start out with some of the metadata pre-filled in.
According to the author the name is slang for mise en place (putting in place), a French expression used in the kitchen that refers to the act of separating and arranging all the ingredients that will be used for the dish being cooked. As with other tools built around Chef, it uses food analogies to describe its purpose: a cookbook created with meez comes with many common tools in place to assess the quality of the code, helping solve the problem of how to get started testing infrastructure code. Without using it, the user would have to include each tool individually, and in many cases create directory structures and boilerplate manually before writing actual test code, which can be a tiring exercise of digging around the web for documentation and example code. By making all this tooling readily accessible it encourages best practices towards writing better code. It also takes away one point of failure to check when things go wrong. After all, the structure was created following known working patterns.
These are the tools included by meez in a cookbook:
- Berkshelf to manage cookbook dependencies
- RuboCop to check code style
- Foodcritic to lint cookbook code
- ChefSpec for unit testing
- Serverspec for acceptance testing
- Test Kitchen to run tests across multiple platforms
- Strainer which provides a single command to run all tests in isolation
The only required argument is the cookbook name, but optional arguments for cookbook license, author’s name and e-mail can be provided and will perform text substitution in the metadata file and others, a handy addition to the cookbook creation process.
It is also possible to run meez on top of existing cookbooks where the user wants to add tests. When doing so, the tool carefully asks what to do with each conflict as they arise. For instance, when run against the official apache2 cookbook, it stops execution before changing the existing Berksfile:
* Initializing Cookbook
** Creating cookbook apache2
** Creating README for cookbook: apache2
** Creating CHANGELOG for cookbook: apache2
** Creating metadata for cookbook: apache2
* Initializing Berkshelf
Overwrite /home/user/chef-repo/cookbooks/apache2/Berksfile? (enter "h" for help) [Ynaqdh]
The same happens for all conflicting files in the cookbook.
Last month on the #openstack-chef freenode channel, the author said it is not possible to customize the template, meaning that for the moment any special requirements, such as integration with other tools or using a different template for the metadata.rb file, a special file that serves as a high-level description of the cookbook, have to be added after the fact. That is not different from what happens when using more common tools such as Berkshelf or knife, to create a cookbook. He also mentioned plans to add a Rake task and integration with Travis CI.
James Wickett, proponent of Rugged DevOps, a flag under which he encourages the union of the InfoSec and DevOps communities advocating for both agile and more secure software deliveries, describes his experience with the gem:
Once you tell meez to create a cookbook for you, it sets up all the different frameworks and gets you ready to start actually writing your recipes and working on your cookbook. No more remembering how to setup all the testing tools and frameworks. Sweet!
The gem's README file on GitHub is the main source of information about its usage.
Eran Kinsbruner May 05, 2015