We have been able to test our puppet modules using rspec-puppet and
serverspec for a while now and the quality of our code is improving because
of it. This talk will introduce the new kid on the block litmus. This talk will show you how
to use litmus to test puppet modules and how to convert your existing modules to make use of litmus.
7. Read out loud warning
“Unit testing is a software development
process in which the smallest testable parts
of an application, called units, are individually
and independently scrutinized for proper
operation”
9. Rspec test
require 'spec_helper'
describe 'ssh::server', type: :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts }
context 'with defaults for all parameters' do
it { is_expected.to contain_class('ssh::server') }
it { is_expected.to contain_class('ssh::params') }
it do
is_expected.to contain_package('openssh-server').with(
'ensure' => 'present',
)
end
10. Read out loud warning
“An acceptance test is a formal description of
the behavior of a software product, generally
expressed as an example or a usage
scenario”
13. Test Kitchen
●
Based on the chef toolchain
●
Puppet support via plugin
●
Multiple provider support
●
Inspec (and serverspec) support
https://github.com/neillturner/kitchen-puppet
14. inspec
control 'ports-1.0' do
impact 1.0
title 'Port 9000 should have a fpm pool listening'
describe port(9000) do
it { should be_listening }
its('processes') {should include 'php-fpm'}
end
end
https://www.inspec.io/
16. Highly Opinionated Awkward Bits
●
Designed for single node testing only *
●
Rage inducing CLI (beaker)
●
Weird CLI verbs (kitchen)
●
No orchestration (kitchen)
●
License issues (inspec)
17.
18. Litmus
●
Developed by puppet
●
Ruby based
●
Native puppet support
●
Docker & Vagrant providers
●
Server-spec
●
Build on puppet’s Bolt
●
Multi node support
https://github.com/puppetlabs/puppet_litmus
20. bootstrap
# Start a docker image
>bundle exec rake 'litmus:provision[docker, centos:7]'
# Start all nodes defined it the vagrant list
>bundle exec rake 'litmus:provision[vagrant]'
Provisioning centos_7-2222
{"status":"ok","node_name":"localhost"}
22. Batteries not included?
# Installs the latest Puppet Agent on all targets
> bundle exec rake "litmus:install_agent"
# Installs Puppet 5 on all targets
> bundle exec rake 'litmus:install_agent[puppet5]'
# Install the latest Puppet Agent on a specific target
> bundle exec rake 'litmus:install_agent[foo.bar.bbq]'
23. Bolt
> bolt command run 'puppet --version' -n localhost:2222 -i inventory.yaml
Started on localhost...
Finished on localhost:
STDOUT:
6.12.0
Successful on 1 node: localhost:2222
Ran on 1 node in 0.92 seconds
24. Multi-node Setup
> bundle exec bolt --modulepath $(pwd)/spec/fixtures/modules/
plan run provision::server_setup --inventoryfile inventory.yaml
> bundle exec bolt --modulepath $(pwd)/spec/fixtures/modules/
plan run provision::agents --inventoryfile inventory.yaml