HI!

Today I want to write a short post about my recent attempts to test chef cookbooks with test kitchen and swat.

I am not going to explain here what chef and test kitchen is. I believe most of us heard about this configuration management system and testing framework for it.

But in few words test kitchen provides some capabilities for chef cookbook developers rapidly test their recipes under various platforms and environments.

Recently a good idea came into my mind. Swat could be a good companion for all this eco system. As far as:

swat provides DSL for rapid web tests development

sparrow is a small swat infrastructure tool acting like cpan client for swat modules get installed from SparrowHub - central repository for shareable swat test suites

So I went ahead and created some useful test suites could be run as simple integration tests for 2 popular chef cookbooks:

apache2 - maintained by Sander van Zoest

httpd - maintained by Opscode itself

Here it is 2 sparrow plugins to test those cookbooks:

Ok, to make long story short. What do these plugins do?

Once test kitchen run test action:

kitchen test

A brand new instance gets created and converged by chef using one of mentioned cookbook (apache2 or httpd), then test part comes into play, and so swat plugins gets run. This is how it looks for example for apache2 cookbook:

$ kitchen verify swat-debian 10:32-----> Starting Kitchen (v1.4.2) -----> Verifying <swat-debian-76>... Preparing files for transfer -----> Busser installation detected (busser) Installing Busser plugins: busser-bash Plugin bash already installed Removing /tmp/verifier/suites/bash Transferring files to <swat-debian-76> -----> Running bash test suite -----> [bash] swat_test.bash project foo already exists - nothing to do here ... checkpoint foo/apache already exists at /usr/local/share/perl/5.14.2/Sparrow/Commands/CheckPoint.pm line 39 Sparrow::Commands::CheckPoint::check_add('foo', 'apache') called at /usr/local/bin/sparrow line 123 set base_url set plugin to public@swat-apache2-cookbook # running export swat_my=/home/vagrant/sparrow/projects/foo/checkpoints/apache/swat.my && cd /home/vagrant/sparrow/plugins/public/swat-apache2-cookbook && carton exec 'swat ./ working.computers.biz' ... /home/vagrant/.swat/.cache/18283/prove/00.GET.t .. ok 1 - GET working.computers.biz/ succeeded # response saved to /home/vagrant/.swat/.cache/18283/prove/drIQlxuYOf ok 2 - output match '200 OK' ok 3 - output match /Server: Apache/ ok 4 - output match 'Hello World' 1..4 ok All tests successful. Files=1, Tests=4, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.04 cusr 0.00 csys = 0.06 CPU) Result: PASS Finished verifying <swat-debian-76> (0m14.54s). -----> Kitchen is finished. (0m19.20s) zlib(finalizer): the stream was freed prematurely.

Very simple!

As far as I know ruby folks have no by hand rubygems for real integration tests under test kitchen, all I found:

(IMHO) Are not being competitive in web testing against a swat! I have just heard that ospcode guys run recently InSpec which does something similar as swat, but I still think swat/perl could have a good chance to be a real player on this field .

And , finally if you:

code on Perl

love web test automation

and ( perhaps ) interested in infrastructure automation

You could be one of perl community representative in a ( foreign ? ((: ) world of chef and ruby, it could be intrigues ...

Let me know if you need any help with swat tests development, so we could go together and promote Perl into configuration management.

PS For those who want to look at implementation - here are two pull requests for both cookbooks awaited for being reviewed: