Test kitchen using OpenNebula

Sep 30, 2015 Written by Ranjitha Platform Operations Engineer


Test Kitchen is a test harness tool to execute your configured code on one or more platforms in isolation.

We’re going to use Test Kitchen to help us write a simple Chef cookbook, complete with tests that verify that the cookbook does what it’s supposed to do.

To initialize the opennebula driver that it has a static and declarative configuration in .kitchen.yml file.

Installing Test Kitchen

Installing Test Kitchen from RubyGems goes like this:

$ gem install test-kitchen

Now let’s verify that Test Kitchen is installed. To get the currently installed version we type:

$ kitchen version

Test Kitchen version 1.0.0

Creating a Cookbook

We already have some cookbooks in github repository.

$ git clone

We can create a cookbook by using knife. knife is a tool used to configure most interactions with the Chef system. We can use it to perform work on our workstation and also to connect with the Chef server or individual nodes.

The general syntax for creating a cookbook is:

$ knife cookbook create cookbook_name


A Test Kitchen Driver for Opennebula.


Download and install latest ChefDK.

$ wget

Install chefdk

$ sudo dpkg -i chefdk_0.8.0-1_amd64.deb

Please add bin locations to your PATH:

/opt/chefdk/bin/:/opt/chefdk/embedded/bin (unix)

NOTE : Reopen console or reload your env PATH

Install kitchen with opennebula driver:

$ gem install kitchen-opennebula –no-user-install –no-ri –no-rdoc



URL where the OpenNebula daemon is listening. The default value is taken from the ONE_XMLRPC environment variable, or if unset.


Path to the file containing OpenNebula authentication information. It should contain a single line stating “username:password”. The default value is taken from the ONE_AUTH environment variable, or $HOME/.one/one_auth if unset.


Name of the VM definition file (OpenNebula template) registered with OpenNebula. Only one of template_name or template_id must be specified in the .kitchen.yml file. The default value is unset, or nil.


Hostname to set for the newly created VM. The default value is For example vm_hostname :xxxx


This is the username used for SSH authentication to the new VM. The default value is local.


The amount of memory to provision for the new VM. This parameter will override the memory settings provided in the VM template. The default value is 512MB.


This variable is used to override timeout for Fog’s common wait_for method which states that it “takes a block and waits for either the block to return true for the object or for a timeout (defaults to 10 minutes)”.

For more details to visit testkitchen/kitchen-opennebula

Now we’ll add Test Kitchen to our project by using the init subcommand:

$ kitchen init --driver=kitchen-opennebula
  create  .kitchen.yml
  create  chefignore
  create  test/integration/default
 Successfully installed kitchen-opennebula-0.1.2
 Parsing documentation for kitchen-opennebula-0.1.2
 Done installing documentation for kitchen-    opennebula after 0 seconds
1 gem installed

The kitchen init subcommand will create an initial configuration file for Test Kitchen called .kitchen.yml.

While Test Kitchen may have created the initial file automatically, it’s expected that you will read and edit this file.

   name: opennebula
   opennebula_endpoint: ''
   oneauth_file: ./.one_auth
   template_name: TEMPLATE_NAME
   vm_hostname: HOSTNAME
   username: USERNAME
   memory: 2048
   wait_for: 1000

   name: chef_solo

   - name: ubuntu-14.04
   - name: centos-7.0

   - name: default
    - recipe[git::default]

To see the results of our work, let’s run the kitchen list subcommand:

$ kitchen list
    Instance            Driver      Provisioner  Last Action
    default-ubuntu-1404  opennebula  ChefSolo     <Not Created>

Test Kitchen calls this the Create Action. We’re going to be painfully explicit and ask Test Kitchen to only create the default-ubuntu-1404 instance:

$ kitchen create default-ubuntu-1404

Let’s check the status of our instance now:

$ kitchen list
    Instance                 Driver     Provisioner   Last Action
     default-ubuntu-1404      opennebula  ChefSolo     Created
Running Kitchen Converge

Now start Test Kitchen to test the cookbook

$ kitchen converge default-ubuntu-1404

It will create a opennebula VM and run the cookbooks in run_list