Skip to content

Testing with Vagrant

haf edited this page Sep 2, 2012 · 1 revision

Testing puppet-riak with Vagrant

You will have three aims; get the required gems into a development environment of yours (where you are developing your application), get the virtual machine into a state where it will accept the puppet module and let you test it and creating the configuration that you need for your application.

The first aim, to get the gems, is accomplshed by running bundle in your folder. I will assume that you are using RVM, because that's the way to roll nowadays. By running bundle you are telling bundler that you want to download the required gems as specified in Gemfile. Furthermore, the Gemfile has two comments on top: #ruby=1.8.7 and ruby-gemset=puppet-riak - you can and should make similar comments in your own.

Now, run once, gem regenerate_binstubs; it will run for your current gemset and make it possible to run things like rake vagrant:up rather than bundle exec rake vagrant:up. I.e. it sets the correct binstubs on your gems' executables for your current gemset, and makes sure that all bin invocations are consistent with your Gemfile.

The reason that you run rake vagrant:up comes from inspecting that task:

require 'puppetlabs_spec_helper/rake_tasks'
desc 'Bring the VM up'
task :up => [:spec_prep] do
  system 'vagrant up'
end

The helper from PuppetLabs gives the task spec_prep:

task :spec_prep do
  fixtures("repositories").each do |repo, target|
    File::exists?(target) || system("git clone #{repo} #{target}")
  end

  FileUtils::mkdir_p("spec/fixtures/modules")
  fixtures("symlinks").each do |source, target|
    File::exists?(target) || FileUtils::ln_s(source, target)
  end

  FileUtils::mkdir_p("spec/fixtures/manifests")
  FileUtils::touch("spec/fixtures/manifests/site.pp")
end

This copies all of the module's dependencies into the fixtures folder, so that you can run the tests with them.

Now, everything is set up for you to hack on the project. You can run rake specs, for example, and all specs will be run. At the time of writing, there's a bug in hiera that keeps some specs from passing, and another in rspec-puppet that makes all specs fail! :) Awesome, but I'll see if I can help or get helped to fix that.

When you have modified something and want to test it, you run rake vagrant:provision (assuming you've run :up once). You can modify the verbosity of puppet through the Vagrantfile.

TL; DR

  1. git clone https://github.com/haf/puppet-riak.git
  2. cd puppet-riak
  3. Install RVM and bundler. curl -L https://get.rvm.io | bash -s stable --ruby --gems=bundler,rubygems-bundler
  4. rvm requirements: follow these instructions. I'm using RMI 1.9.3.
  5. bundle install
  6. gem regenerate_binstubs
  7. rake vagrant:up
  8. HACK!
  9. rake vagrant:provision

Swoosh through the links to become skilled at ninja arts in distributed systems provisioning.

Clone this wiki locally