chef-boneyard / chef-provisioning

A library for creating machines and infrastructures idempotently in Chef.
Apache License 2.0
524 stars 164 forks source link

Writing tests for clusters #451

Open Fodoj opened 9 years ago

Fodoj commented 9 years ago

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

tyler-ball commented 9 years ago

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 commented 8 years ago

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 :smile:

bhouse commented 8 years ago

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

mrmarbury commented 8 years ago

+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.