Garrett Honeycutt
gh@learnpuppet.com
learnpuppet.com
@learnpuppet
Functional testing for
configuration management
spec vs
functional
http://www.structuretech1.com/wp-content/uploads/2012/11/Gate-valve-exploded1.jpg
what is
functional
testing?
Functional test for ntp module
1. set time incorrectly
2. apply ntp class
3. check that time is correct
#/bin/sh
#
puppet agent -t
while [ $? -ne 0 ]
do
puppet agent -t
done
Functional test for
idempotency
1. start with a blank system
2. apply class
3. changes should occur
4. apply class again
5. no changes occur
why write
tests at
all?
tooling
https://github.com/unixmonkey/learngit
http://serverspec.org/
how to
approach
functionally test
each module
functionally test
each role
role: repo
* main entry point is the class
yum::server
role: repo
* main entry point is the class
yum::server
* simple apache web server with a
DocumentRoot set to serve packages
role: repo
* main entry point is the class
yum::server
* simple apache web server with a
DocumentRoot set to serve packages
* manages only a couple files and
packages
apache hosts rsyslog
apache::mod::cache inittab selinux
apache::mod::cgi motd ssh
apache::mod::dav network sysklogd
apache::mod::dav_fs nsswitch timezone
apache::mod::default ntp types
apache::mod::proxy pam utils
apache::mod::ssl pam::accesslogin vim
apache::params pam::limits wget
common papertrail yum
dnsclient puppet::agent yum::server
facter redhat yum::updatesd
apache hosts rsyslog
apache::mod::cache inittab selinux
apache::mod::cgi motd ssh
apache::mod::dav network sysklogd
apache::mod::dav_fs nsswitch timezone
apache::mod::default ntp types
apache::mod::proxy pam utils
apache::mod::ssl pam::accesslogin vim
apache::params pam::limits wget
common papertrail yum
dnsclient puppet::agent yum::server
facter redhat yum::updatesd
36 classes in 23 modules
Monitoring
$ ping -c1 example.com
PING example.com (93.184.216.119): 56
data bytes
64 bytes from 93.184.216.119: icmp_seq=0
ttl=58 time=4.947 ms
--- example.com ping statistics ---
1 packets transmitted, 1 packets
received, 0.0% packet loss
round-trip min/avg/max/stddev =
4.947/4.947/4.947/0.000 ms
$ curl example.com -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Thu, 13 Nov 2014 03:52:15 GMT
Etag: "359670651"
Expires: Thu, 20 Nov 2014 03:52:15 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35
GMT
Server: ECS (pae/3796)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270
1. set the role
2. converge on model
3. seed a package on the
system
4. on another system, set it to
use the first as a repo
5. install the seeded package
from the repo
who does
what?
how to
automate
&&
Garrett Honeycutt
gh@learnpuppet.com
learnpuppet.com
@learnpuppet

20150314 - Functional Testing for Configuration Management @ Cascadia IT Conference