Writing tests for clusters #451

Open
Fodoj opened this Issue Sep 24, 2015 · 4 comments

Projects

None yet

5 participants

@Fodoj
Fodoj commented Sep 24, 2015

kitchen-metal plugin is dead. What is the alternative? How do I write tests for chef-provisioning recipes?

@tyler-ball
Contributor

This is an issue we are aware of, and have some ideas to address it; but it is a big enough story that we haven't started on it yet (in favor of stability improvements).

You can look at the kitchen driver for chef-provisioning-vsphere to get an idea of how 1 community member solved the issue, if you want to play around with it.

@Afterglow

There is a tool called infrataster that can do some useful stuff as well. If you are using chef-provisioning then there is a plugin you can use to pull the node data from the json files it creates as well though its a bit of a hack I wrote https://rubygems.org/gems/infrataster-plugin-chef. You can do stuff like...

spec_helper.rb to iterate all the nodes in your chef-zero servers nodes dir and create a infrataster server for them...

nodes_dir = 'provision/repo/nodes'

Dir.foreach(nodes_dir) do |nodefile|
  next unless nodefile.end_with? '.json'
  node = Chef::Node.json_create(
    JSON.parse(IO.read("#{nodes_dir}/#{nodefile}"))
  ) rescue next

  ssh = {
    :host_name => node['ipaddress'],
    :user => 'ubuntu',
    :keys => ['/path/to/your/key']
  } unless Chef::Sugar::Vagrant.vagrant?(node)

  Infrataster::ChefServer.define(
    node.name,
    node['ipaddress'],
    :chefnode => "provision/repo/nodes/#{nodefile}",
    :vagrant => Chef::Sugar::Vagrant.vagrant?(node),
    :ssh => ssh
  )
end if ::Dir.exist? nodes_dir

Then you can do tests using any of the many infrataster plugins for ssh, http, mysql, dns and others such as...

describe server("myserver") do
    it "is GNU/Linux" do
      result = current_server.ssh_exec("uname -a")
      expect(result.chomp).to include "GNU/Linux"
    end
end

Obviously you can do more useful things as well 😄

@bhouse
bhouse commented May 20, 2016

hi @tyler-ball, any update on test kitchen support for chef provisioning?

@mrmarbury

+1 on the kitchen plugin ... We kind of rely on this feature. We tried terraform but it seems to have more bugs and missing features than anything that really works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment