It is recommended to have basic understanding of CHEF and its components. In case you want to go through the basics of CHEF click here
If you are already using CHEF in your environment, you often write new cookbooks and for testing those you either need to start new virtual machines or cloud instances. This activity usually takes few minutes but there is additional cost associated with launching new cloud instances. CHEF test kitchen has enabled us to reduce new cookbook/recipes testing time to minutes by provisioning VAGRANT box on our local workstation.
In this blog, I will be using mongodb-docker cookbook for demonstrating CHEF test kitchen
Install Test Kitchen, VAGRANT and VirtualBox:
- Chef Test Kitchen: Test Kitchen is a testing tool that can execute your CHEF recipes on one or more platforms in isolation. A driver plugin architecture is used which lets you run your recipes on various cloud providers and virtualization technologies.
$ gem install test-kitchen
- Virtualbox: VirtualBox is powerful Cross-platform Virtualization Software for x86-based systems. “Cross-platform” means that it can be installed on Windows, Linux, Mac OS X and Solaris x86 computers.
$ sudo apt-get install virtualbox
- VAGRANT: VAGRANT not only creates virtual machines, it mainly automates the work of setting up development environment.
$ sudo apt-get install vagrant
Steps to test MongoDB Replica Set Cookbook recipe with CHEF Test Kitchen:
Kitchen.yml can be created in chef-repo directory or in the recipe directory. If you initialize kitchen in recipe directory, recipe name will be automatically added to the kitchen.yml.
- You can create kitchen.yml file in the chef-repo directory (as shown below) or in specific cookbook directory.
$ kitchen init
- Add the below mentioned content to the kitchen.yml file, in this file you can configure basic details like driver name (vagrant or docker), provisioner, base OS image, memory and recipe name.
--- driver: name: vagrant provisioner: name: chef_zero platforms: - name: ubuntu-14.04 driver: customize: memory: 256 suites: - name: default run_list: - recipe[mongodb-docker::default] attributes:
- To create VAGRANT machine use below-mentioned command:
$ kitchen list
$ kitchen create
- To execute recipe on the VAGRANT virtual machine, use the below-mentioned command:
$ kitchen converge
- To login to the VAGRANT vm, use kitchen login command as shown below:
$ kitchen login
- And after testing if you want to delete the setup i.e. vagrant vm, use the command mentioned-below:
$ kitchen destroy
Get in touch with our Chef devOps in case of any query.