- 1 Description
- 2 Commands
- 3 Initialize
- 4 List Instances
- 5 Create
- 6 Converge
- 7 Setup
- 8 Verify
- 9 Test
- 10 Run Command
- 11 Login
- 12 Delete VM
- 13 Local Override Config File
- 14 YAML Configuration Examples
- 15 Sources
- 16 Related Articles
This article gives information on using Test Kitchen for testing Chef automation.
Commands: kitchen console # Kitchen Console! kitchen converge [INSTANCE|REGEXP|all] # Change instance state to converge. Use a provisioner to configure one or more instances kitchen create [INSTANCE|REGEXP|all] # Change instance state to create. Start one or more instances kitchen destroy [INSTANCE|REGEXP|all] # Change instance state to destroy. Delete all information for one or more instances kitchen diagnose [INSTANCE|REGEXP|all] # Show computed diagnostic configuration kitchen driver # Driver subcommands kitchen driver create [NAME] # Create a new Kitchen Driver gem project kitchen driver discover # Discover Test Kitchen drivers published on RubyGems kitchen driver help [COMMAND] # Describe subcommands or one specific subcommand kitchen exec INSTANCE|REGEXP -c REMOTE_COMMAND # Execute command on one or more instance kitchen help [COMMAND] # Describe available commands or one specific command kitchen init # Adds some configuration to your cookbook so Kitchen can rock kitchen list [INSTANCE|REGEXP|all] # Lists one or more instances kitchen login INSTANCE|REGEXP # Log in to one instance kitchen setup [INSTANCE|REGEXP|all] # Change instance state to setup. Prepare to run automated tests. Install busser and related gems on one or more instances kitchen test [INSTANCE|REGEXP|all] # Test (destroy, create, converge, setup, verify and destroy) one or more instances kitchen verify [INSTANCE|REGEXP|all] # Change instance state to verify. Run automated tests on one or more instances kitchen version # Print Kitchen's version information
Create default files in Chef cookbook directory.
Instance Driver Provisioner Verifier Transport Last Action base-centos-511 Vagrant ChefZero Busser Ssh <Not Created> base-centos-67 Vagrant ChefZero Busser Ssh <Not Created> base-centos-72 Vagrant ChefZero Busser Ssh Created base-no-firewall-centos-511 Vagrant ChefZero Busser Ssh <Not Created> base-no-firewall-centos-67 Vagrant ChefZero Busser Ssh <Not Created> base-no-firewall-centos-72 Vagrant ChefZero Busser Ssh <Not Created>
KITCHEN_YAML=.kitchen.ec2.yml kitchen list
Instance Driver Provisioner Verifier Transport Last Action base-rhel6 Ec2 ChefZero Busser Ssh <Not Created> base-rhel7 Ec2 ChefZero Busser Ssh <Not Created> base-win2008r2 Ec2 ChefZero Busser Winrm <Not Created> base-win2012r2 Ec2 ChefZero Busser Winrm <Not Created>
Create Spins up the VM, but does not install Chef Solo or run your Chef code.
kitchen create base-centos-67
Install Chef Solo and run Chef Code. Similar to vagrant provision; can be used to re-run Chef code after making changes locally.
kitchen converge base-centos-67
Prepare to run automated tests. Install busser and related gems on one or more instances.
kitchen setup base-centos-67
Run automated tests on one or more instances
kitchen verify base-centos-67
Runs the following in order destroy, create, converge, setup, verify and destroy
kitchen test base-centos-67
kitchen exec -c '/bin/nodeinfo'
kitchen exec base-centos-67 -c '/bin/nodeinfo'
Login to the instance like vagrant ssh
kitchen login base-centos-67
kitchen destroy base-centos-67
Local Override Config File
You can create a test kitchen yaml file that you do not commit to the repo that will override the default section by section. I say section by section, because you can't just override one item of say the driver section. If you did; it would simply wipe out all the other driver settings in the default and only have your one entry. So you have to grab the who section and make your customizations. The easiest option is to simply make a copy of the default kitchen yaml and add in your personal settings. As you will see in my example below. This is good for adding your AWS settings, custom proxy settings, changing CPU/Mem on a local etc.
- Copy the default kitchen configuration file.
cp .kitchen.yml .kitchen.local.yml
- Edit the local override configuration.
- Now kitchen commands will default to first pulling setting from the .kitchen.local.yml and then if there are additional sections not in that local from the .kitchen.yml
Another option is to make a copy of any of the kitchen configurations and name it whatever you want. Add your customizations and then set the KITCHEN_YAML environment variable method to call it instead of the default kitchen configuration.
KITCHEN_YAML=.kitchen.mycoolconfig.yml kitchen <command>
YAML Configuration Examples