Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Test Kitchen in Travis

Sam Pikesley edited this page May 9, 2014 · 2 revisions

First add kitchen-rackspace to the Gemfile:

gem 'kitchen-rackspace'

Then run bundle install

Next, create a .kitchen.cloud.yml file:

---
driver:
  name: rackspace
  rackspace_username: <%= ENV['RACKSPACE_USERNAME'] %>
  rackspace_api_key: <%= ENV['RACKSPACE_API_KEY'] %>
  rackspace_region: lon
  require_chef_omnibus: latest

provisioner:
  name: chef_zero

platforms:
  - name: ubuntu-12.04

Then add your run list to the file from your existing .kitchen.yml file. You may want to tweak some of the settings above to suit your needs. See the kitchen-rackspace docs for more.

Then encrypt and add the Rackspace creds to your .travis.yml file on the command line like so:

travis encrypt RACKSPACE_USERNAME=YOUR_RACKSPACE_USERNAME --add
travis encrypt RACKSPACE_API_KEY=YOUR_RACKSPACE_API_KEY --add

Next, make sure the Travis VM has an SSH key (they don't by default)

before_script:
	- ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''

Add KITCHEN_YAML=.kitchen.cloud.yml to the .travis.yml global env

Next, tell Travis what to run to make the tests happen:

script: 
  - travis_wait 35 kitchen test --destroy=always

travis_wait is a special Travis command that stops Travis from timing out. The second parameter is the timeout we want in minutes. 35 minutes is usually enough for a complete test run. (Note: We'll usually have a Rake task here instead of kitchen test).

The --destroy=always tag is important because by default, Test Kitchen only destroys your box after a successful test. We don't want additional servers hanging around and costing us money, so we'll kill them every time.

Encrypting stuff

Sometimes, we'll want our test boxes to speak to live services (in the case of ServerDensity for example). As we can't embed Ruby into the data bags, we need to encrypt these.

export DATA_BAG_KEY=SOME-UNIQUE-KEY

openssl aes-256-cbc -k "$DATA_BAG_KEY" -in test/data_bags/serverdensity/credentials.json -out test/data_bags/serverdensity/credentials.enc.json -a -e

openssl aes-256-cbc -k "$DATA_BAG_KEY" -d -a -in test/data_bags/serverdensity/credentials.enc.json -out test/data_bags/serverdensity/credentials.json

travis encrypt DATA_BAG_KEY=SOME-UNIQUE-KEY
Clone this wiki locally