ServerSpec
ServerSpec gives you RSpec tests for your infrastructure. Test Kitchen’s legacy busser verifier runs them through the busser-serverspec plugin.
Busser installs ServerSpec on the machine under test the first time a suite runs, then executes the suite’s serverspec directory against it. Because the tests run on the machine itself, they use ServerSpec’s exec backend rather than SSH.
kitchen.yml and need no Busser layer. kitchen-verifier-shell with ServerSpec covers similar ground if you specifically need ServerSpec.Requirements
Ruby 3.2 or newer, and busser 0.9.0 or newer.
Installation
Select the Busser verifier in your kitchen.yml:
verifier:
name: busser
Busser installs the plugin for you when the suite runs. To install it by hand:
busser plugin install busser-serverspec
Directory layout
Put your specs in a subdirectory of the suite’s serverspec directory:
test
`-- integration
`-- default # suite name
`-- serverspec
|-- Gemfile # optional
|-- spec_helper.rb
`-- localhost
`-- httpd_spec.rb
Specs are collected recursively as **/*_spec.rb, so any depth works; the localhost/ directory is convention, not a requirement. The suite directory is added to the load path and set as RSpec’s default path, so require "spec_helper" works without a relative path.
serverspec is what selects this plugin. There is nothing else to configure.Writing a test
require "spec_helper"
describe package('httpd') do
it { should be_installed }
end
describe command("echo hello") do
its(:exit_status) { should eq 0 }
its(:stdout) { should eq "hello\n" }
end
Backend
The tests run on the machine under test, after Test Kitchen has logged in, so the exec backend is the right one:
require "serverspec"
set :backend, :exec
set :backend, :ssh. That would have ServerSpec connect back out over the network from a machine that is already the target.Pinning the ServerSpec version
A Gemfile in the suite directory is bundle installed before the run:
source "https://rubygems.org"
gem "serverspec", "~> 2.43"
Without one, the plugin installs ServerSpec 2.43 or newer.
When nothing runs
If the suite files do not match what this plugin looks for, the run prints one line and exits 0 — no tests ran, and nothing said so:
-----> Running serverspec test suite
This is the most common problem with this verifier, and because it exits zero, CI reports success. Work through these in order:
- Is the directory named
serverspec? That name alone selects this plugin.serverspecs/,tests/, or anything else is not picked up. - Do the filenames match? Only
*_spec.rbis run, searched recursively. Note the underscore —default-spec.rbis not picked up. - Is the plugin installed?
busser plugin listshows what is available. - Is
BUSSER_ROOTwhat you think?busser suite pathprints where suites are actually being looked for.
kitchen verify that finishes suspiciously fast is the signal. Add a deliberately failing test once to confirm your suite is actually being executed.