what is test kitchen
DESCRIPTION
As presented to the Devops Montreal crowd, 2014-05-05.TRANSCRIPT
Test KitchenKeep your cookbook in order
Who’s cooking?
Who is this guy? Sysadmin @ La Presse Been using Chef since 2011 (0.8.0) in a
team of 2 or a team of 10 bencaron @
What is Test Kitchen?
• Doing Infrastructure as code?
• Code ❤️ tests
• Test Kitchen help you automate the testing of your cookbooks
But why tests?
Tests helps you work as a team
Tests allows you to move faster, with more confidence
Your infrastructure is now code: manage it as code, using modern development best practices
Test Kitchen helps you..
Test your cookbook under n platform, under m scenarios
Put your cookbooks under a CI pipeline
Use the best test framework for the job
Test Kitchen vs Vagrant
Prevents you to build yet another huge custom Vagrantfile
Allows you to tests on other targets (cloud!)
Add a sane abstraction layer over your VM config and your tests
Ok, how does this thing work?
Gem install test-kitchen
Use the kitchen command
Commands work like a pipeline where you can execute juste part of it
Kitchen test == kitchen create kitchen converge kitchen setup kitchen verify kitchen destroy
Kitchen init
Setup your cookbook
Configuration is done in .kitchen.yml
Your tests lives under:
test/ integration/ [suitename]/ [tool]
.kitchen.yml
Driver:How to launch your VM. Default is Vagrant
Provisioner:How to run your test Solo or Zero
Platforms: What to test
SuitesScenarios to test
More tricks
Exclude/include platforms in scenarios (for e.g. platform-specific recipes)
Uses environments, roles, data bags
Thin documentation: use kitchen diagnose for list of possible configs
Kitchen-*
There’s already a lot of drivers Kitchen-docker: fast
testing environment with docker, even on OSX
Lots of others
Ok, so what kind of tests? Bats Serverspecs Minitests Cucumber Others!
Bats
Bash Automated Testing System
https://github.com/sstephenson/bats
Serverspecs
RSpec tests for checking your servers are configured correctly
http://serverspec.org/
Follow rspec patterns and test your server state through SSH (or local) access
Rspec form
Serverspec tests are rspec tests
Serverspec example
A more typical serverspec example
More on serverspec
Reusable outside of Test Kitchen
Turn it into monitoring?
Reuse your tests on your current/old servers. Even on REAL hardware!
More testing
FoodcriticCheck your cookbook stylehttp://acrmp.github.io/foodcritic/
RubocopStatic code analyzerhttps://github.com/bbatsov/rubocop
Chefspec
ChefSpec Unit testing for Chef
cookbooks Rspec Check without
convergence Puppet users?
Check rspec-puppet rspec-puppet.com
Questions?
Photos credits – Thank you!
Crisco:http://en.wikipedia.org/wiki/File:Crisco_Cookbook_1912.jpgFront cover of the first Crisco cookbook, published in 1912. This file was obtained from the crisco website in the timeline section [1]. This work is in the public domain in the US per Wikipedia:Public domain because it was published before 1923.
Kitchen Scene-Joachim Wtewael.jpghttp://en.wikipedia.org/wiki/File:Kitchen_Scene-Joachim_Wtewael.jpgPublic Domain
http://en.wikipedia.org/wiki/Automatic_fire_suppressionhttp://en.wikipedia.org/wiki/File:COMPUTER_ROOM_DISCHARGE.JPGWikiCommon
Good Housekeepinghttp://en.wikipedia.org/wiki/File:Good_housekeeping_1908_08_a.jpgPublic Domain
Julia Child Kitchenhttp://en.wikipedia.org/wiki/File:Julia_Child%27s_kitchen_by_Matthew_Bisanz.JPGGNU Documentation License
Pig Slaughterhttp://en.wikipedia.org/wiki/File:Medieval_pig_slaughter.jpgPublic Domain
Gouteur de vinhttp://fr.wikipedia.org/wiki/Go%C3%BBteur#mediaviewer/Fichier:Jan_David_Col_%281822-1900%29%2C_Les_go%C3%BBteurs_de_vin.jpgDomaine public
Joan Post kitchen firehttps://www.flickr.com/photos/quinnanya/11698730705/11698730705_42e623db7c_z.jpghttps://creativecommons.org/licenses/by-sa/2.0/
Fire buildinghttp://en.wikipedia.org/wiki/File:FirePhotography.jpgby-sa 3.0
Lego kitchenhttps://www.flickr.com/photos/kwl/5527716890https://creativecommons.org/licenses/by/2.0/
Kitchen disasterhttps://www.flickr.com/photos/donnunn/165101829/165101829_cf087a4541_zhttps://creativecommons.org/licenses/by-sa/2.0/