test-kitchen using OpenNebula

Introduction

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 https://github.com/megamsys/chef-repo.git

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

Kitchen::Opennebula

A Test Kitchen Driver for Opennebula.

Installation

Download and install latest ChefDK.

$ wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.8.0-1_amd64.deb

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

Configuration

opennebula_endpoint

URL where the OpenNebula daemon is listening. The default value is taken from the ONE_XMLRPC environment variable, or https://127.0.0.1:2633/RPC2 if unset.

oneauth_file

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.

template_name

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.

vm_hostname

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

username

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

memory

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.

wait_for

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.

 driver:
   name: opennebula
   opennebula_endpoint: 'https://127.0.0.1:2633/RPC2'
   oneauth_file: ./.one_auth
   template_name: TEMPLATE_NAME
   vm_hostname: HOSTNAME
   username: USERNAME
   memory: 2048
   wait_for: 1000

provisioner:
   name: chef_solo

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

 suites:
   - name: default
   run_list:
    - 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

VirtEngine by DET.io

VirtEngine by DET.io
VirtEngine specializes in building Virtualization Software and powering Cloud Service Providers / Hosting Providers..

Meet VirtEngine at HostingCon India 2016!

Virtualization platform VirtEngine will be exhibiting in HostingCon India 2016! Continue reading

Installing VirtEngine on CentOS

Published on October 18, 2016

Cassandra Replication - HA

Published on July 14, 2016