SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
Test Driven Development
and
Puppet
Puppet Camp Paris
April 8, 2014
Johan De Wit
(johan@open-future.be)
Whoami
● Open Source Consultant @ open-future
● Organiser Belgian Puppet User Group
● A Sys-Admin
● A very poor developer (but working on it)
● Love riding :
● Bikes
● horses
Do you test your modules ?
I did !!
● 1: write a module
● 2: puppet parser validate ?
● 3: puppet-lint ?
● 4: puppet apply tests/init.pp (smoke)
● 5: puppet agent -t --noop
– You use vagrant – right ??
Start over again
●
Me => devops
●
Should be DEVops
– Yes, we write code to manage our infrastructure.
– Learn from Developers
● UNIT TESTING
● INTEGRATION TESTING
● ACCEPTANCE TESTING
● .....
Testing is great
● Confidence changing things
● Discover breaking things before deploy
● Test against # puppet & # ruby versions
● Test many os'es without deploying them
● Test early - fast feedback
● Prevent regression of old problems
First thing first
● Unit testing
– Rspec-puppet
– Start with testing, then coding
● It is the beginning of ..
– Integration testing (beaker)
– Travis
– Jenkins
– ....
Think colors
4
Test Puppet
Code
GoTest Driven Development
Source http://centricconsulting.com/agile-test-driven-development/
Benefits of TDD
● Test case from the beginning
● Better code coverage
● Tests are maintained during life cycle
● Focus on the needed functionality, step by step
● Encourage simple design (avoid over
engineering)
● First step in test automation (unit testing)
TDD does not
● Replace integration testing
● Replace compliance testing
● .......
Great ... but
TDD and puppet modules
●Write the docs first (README.md)
● Explain your parameters
● Describe the defaults
● What is the function of your module
● What is it intended behaviour
●Write the first test from the README
●Run the tests, all should fail
●Write just enough code to pass the test
●Refactor and reiterate the process
(Ted Arroway: Small moves, Ellie, small moves. [Contact] )
The right tools for the right job
● http://www.rvm.io
– Switch easily between ruby version
● Rspec-puppet
– Written by tim :
● http:/rspec-puppet.com
● https://github.com/rodjek/rspec-puppet
● Puppet module skeleton
– https://github.com/ghoneycutt/puppet-module-skeleton
– https://github.com/garethr/puppet-module-skeleton
– ...
TDD and rspec-puppet
● Testing against the compiled catalog
– Are the right resources in the catalogue
– With the right attributes
● Is the rspec a duplicate of the manifest code
– When you start – yes, because we start simple
– But we can copy/paste ? Right !!
– Refactoring a basic module shows already the benefits.
● Adding parameters
● Adding logic (eg. Support for multiple OS)
● ...
● Puppet modules with proper rspec test are better candidates
● It should/will become common to do PR including rspec tests
Hands on TDD
● Based on the TDD tutorial Garrett Honeycutt
– https://github.com/ghoneycutt/learnpuppet-tdd-vagrant
– https://github.com/ghoneycutt/puppet-module-skeleton
● Why ?
– Followed the TDD session on LOADays
– Everything is configured out of the box
– Easy to start doing it the right way
– Garrett learned me puppet
Hands on TDD – the setup
● The module directory tree
[root@puppet motd]# tree -a
.
|-- .fixtures.yml
|-- Gemfile
|-- .gitignore
|-- LICENSE
|-- manifests
| `-- init.pp
|-- Modulefile
|-- Rakefile
|-- README.md
|-- spec
| |-- classes
| | `-- init_spec.rb
| `-- spec_helper.rb
`-- .travis.yml
Hands on TDD – the setup
● puppet generate module witjoh-motd
● mv witjoh-motd motd
● Rakefile
[root@puppet motd]# rake -T
rake build # Build puppet module package
rake clean # Clean a built module package
rake coverage # Generate code coverage information
rake help # Display the list of available rake tasks
rake lint # Check puppet manifests with puppet-lint / Run
puppet-lint
rake spec # Run spec tests in a clean fixtures directory
rake spec_clean # Clean up the fixtures directory
rake spec_prep # Create the fixtures directory
rake spec_standalone # Run spec tests on an existing fixtures
directory
rake validate # Validate manifests, templates, and ruby files
Hands on TDD – the setup
● spec_helper.rb
– Code that is run before your spectest
– Configures your spec testing environment
[root@puppet spec]# cat spec_helper.rb
require 'rubygems'
require
'puppetlabs_spec_helper/module_spec_helper'
Hands on TDD – the setup
● .fixtures.yml
– Catalog dependencies are taken care off
● Resolves dependencies to other modules
● Creates symlink to own module
● (does not support metadata.json from forge modules)
[root@puppet motd]# cat .fixtures.yml
fixtures:
repositories:
stdlib:
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '3.2.0'
symlinks:
motd: "#{source_dir}"
A Simple TDD Session
workflow
● Write README first
– Explain the function of your module
– Parameters
● Default values
● Valid values
● Write the test based on the readme
● Write the code
– Just enough code to pass the test
● Refactor and add more stuff
–
Hands on TDD – the test
● First test
– <module >/spec/classes/init_spec.rb
Rake validate
[root@puppet classes]# rake validate
(in /root/demos/motd)
puppet parser validate --noop
manifests/init.pp
ruby -c spec/classes/init_spec.rb
Syntax OK
ruby -c spec/spec_helper.rb
Syntax OK
[root@puppet classes]#
Hands on TDD – init_spec.rb
require 'spec_helper'
describe 'motd' do
context 'with defaults for all parameters' do
it { should contain_class('motd') }
it {
should contain_file('motd').with({
'ensure' => 'file',
'path' => '/etc/motd',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'content' => nil,
})
}
end
end
Hands on TDD – Rake Spec
Hands on TDD – The code
# == Class: motd
#
# Module to manage motd
#
class motd {
file { 'motd':
ensure => 'file',
path => '/etc/motd',
owner => 'root',
group => 'root',
mode => '0644',
content => undef,
}
}
Hands on TDD – The test
More rspec
describe 'with path specified' do
context 'as a valid path' do
let(:params){{ :path => '/usr/local/etc/motd'}}
it {
should contain_file('motd').with({
'path' => '/usr/local/etc/motd',
})
}
end
context 'as an invalid path' do
let(:params) { { :path => 'invalid/path' } }
it 'should fail' do
expect {
should contain_class('motd')
}.to raise_error(Puppet::Error)
end
end
end
More rspec
['666','66666','invalid',true].each do |mode|
context "as invalid value #{mode}" do
let(:params) { { :motd_mode => mode } }
it 'should fail' do
expect {
should contain_class('motd')
}.to
raise_error(Puppet::Error,/^motd::mode must be
a four digit string./)
end
end
end
# package
it {
should contain_package('ntp_package').with({
... })
}
# file
it {
should contain_file('ntp_config').with({
...
'require' => 'Package[ntp]',
})
}
# service
it {
should contain_service('ntp_service').with({
...
'subscribe' => 'File[ntp_config]',
})
More rspec
# check for a specific line
it { should contain_file('ntp_conf').with_content(/^tinker
panic 0$/) }
# Check that some content is not include
it { should_not contain_file('ntp_conf').with_content(/^tinker
panic 0$/) }
More rspec
context 'with default values for parameters on EL 6' do
let(:facts) do
{ :osfamily => 'RedHat',
:lsbmajdistrelease => '6',
}
end
end
More rspec – defined resources
# spec/defines/mkdir_p_spec.rb
require 'spec_helper'
describe 'common::mkdir_p' do
context 'should create new directory' do
let(:title) { '/some/dir/structure' }
it {
should
contain_exec('mkdir_p-/some/dir/structure').with({
'command' => 'mkdir -p /some/dir/structure',
'unless' => 'test -d /some/dir/structure',
})
}
end
More rspec – defined resources
context 'should fail with a path that is not absolute' do
let(:title) { 'not/a/valid/absolute/path' }
it do
expect {
should contain_exec('mkdir_p-
not/a/valid/absolute/path').with({
'command' => 'mkdir -p
not/a/valid/absolute/path',
'unless' => 'test -d
not/a/valid/absolute/path',
})
}.to raise_error(Puppet::Error)
end
end
end
What should be tested
● All resources should be in the catalog
– 100% code coverage
● Parameters
– Proper defaults
– Setting params, does that work ?
– Logic of params
– Parameter validation
What should be tested
● Module logic
– Based on facts (eg: ::osfamily)
– Multiple os support
● Dynamic content
– Test your templates
Unit testing is the beginning
● Integration testing
● Acceptance testing
● ....
?
Puppet Camp Paris 2014: Test Driven Development

Mais conteúdo relacionado

Mais procurados

Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Graham Dumpleton
 
Pytest - testing tips and useful plugins
Pytest - testing tips and useful pluginsPytest - testing tips and useful plugins
Pytest - testing tips and useful pluginsAndreu Vallbona Plazas
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicGraham Dumpleton
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistAnton Arhipov
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...Andrzej Jóźwiak
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversBrian Gesiak
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)William Farrell
 
How to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsHow to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsJarrod Overson
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!Jason Feinstein
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistAnton Arhipov
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for DummiesElizabeth Smith
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Andrea Francia
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentalscbcunc
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeIan Robertson
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Criticolegmmiller
 

Mais procurados (20)

Testing con spock
Testing con spockTesting con spock
Testing con spock
 
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
 
Pytest - testing tips and useful plugins
Pytest - testing tips and useful pluginsPytest - testing tips and useful plugins
Pytest - testing tips and useful plugins
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New Relic
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
How to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsHow to Reverse Engineer Web Applications
How to Reverse Engineer Web Applications
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Critic
 

Destaque

HandsOn TestDriven Infrastructure As Code Development
HandsOn TestDriven Infrastructure As Code DevelopmentHandsOn TestDriven Infrastructure As Code Development
HandsOn TestDriven Infrastructure As Code Developmentpingworks
 
Containerized End-2-End-Testing - ContainerConf Mannheim
Containerized End-2-End-Testing - ContainerConf MannheimContainerized End-2-End-Testing - ContainerConf Mannheim
Containerized End-2-End-Testing - ContainerConf MannheimTobias Schneck
 
Container Orchestrator Smackdown @ContinousLifecycle
Container Orchestrator Smackdown @ContinousLifecycleContainer Orchestrator Smackdown @ContinousLifecycle
Container Orchestrator Smackdown @ContinousLifecycleMichael Mueller
 
Test-Driven Infrastructure with CloudFormation and Cucumber.
Test-Driven Infrastructure with CloudFormation and Cucumber. Test-Driven Infrastructure with CloudFormation and Cucumber.
Test-Driven Infrastructure with CloudFormation and Cucumber. Stelligent
 
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecMartin Etmajer
 
14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital Economy14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital EconomyCognizant
 

Destaque (7)

HandsOn TestDriven Infrastructure As Code Development
HandsOn TestDriven Infrastructure As Code DevelopmentHandsOn TestDriven Infrastructure As Code Development
HandsOn TestDriven Infrastructure As Code Development
 
Containerized End-2-End-Testing - ContainerConf Mannheim
Containerized End-2-End-Testing - ContainerConf MannheimContainerized End-2-End-Testing - ContainerConf Mannheim
Containerized End-2-End-Testing - ContainerConf Mannheim
 
Test & Dev on the AWS Cloud
Test & Dev on the AWS CloudTest & Dev on the AWS Cloud
Test & Dev on the AWS Cloud
 
Container Orchestrator Smackdown @ContinousLifecycle
Container Orchestrator Smackdown @ContinousLifecycleContainer Orchestrator Smackdown @ContinousLifecycle
Container Orchestrator Smackdown @ContinousLifecycle
 
Test-Driven Infrastructure with CloudFormation and Cucumber.
Test-Driven Infrastructure with CloudFormation and Cucumber. Test-Driven Infrastructure with CloudFormation and Cucumber.
Test-Driven Infrastructure with CloudFormation and Cucumber.
 
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
 
14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital Economy14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital Economy
 

Semelhante a Puppet Camp Paris 2014: Test Driven Development

TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07garrett honeycutt
 
20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorialgarrett honeycutt
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamAutomated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamPuppet
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2nottings
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to railsGo Asgard
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Brian Sam-Bodden
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringAlessandro Franceschi
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)p3castro
 
PuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPhil Zimmerman
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratiehcderaad
 
Orchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorOrchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorRaphaël PINSON
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Puppet
 
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Puppet
 
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?NETWAYS
 
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Puppet
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet SystemPuppet
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...Yury Bushmelev
 
Testing your infallibleness
Testing your infalliblenessTesting your infallibleness
Testing your infalliblenessCorey Osman
 
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T Puppet
 

Semelhante a Puppet Camp Paris 2014: Test Driven Development (20)

TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
 
20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamAutomated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoring
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
PuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With Notes
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Orchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorOrchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and Mspectator
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
 
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
 
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
 
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet System
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
Testing your infallibleness
Testing your infalliblenessTesting your infallibleness
Testing your infallibleness
 
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
 

Mais de Puppet

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyamlPuppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)Puppet
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscodePuppet
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twentiesPuppet
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codePuppet
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approachPuppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationPuppet
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliancePuppet
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowPuppet
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Puppet
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppetPuppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkPuppet
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping groundPuppet
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy SoftwarePuppet
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User GroupPuppet
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsPuppet
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyPuppet
 

Mais de Puppet (20)

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 

Último

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Puppet Camp Paris 2014: Test Driven Development

  • 1. Test Driven Development and Puppet Puppet Camp Paris April 8, 2014 Johan De Wit (johan@open-future.be)
  • 2. Whoami ● Open Source Consultant @ open-future ● Organiser Belgian Puppet User Group ● A Sys-Admin ● A very poor developer (but working on it) ● Love riding : ● Bikes ● horses
  • 3. Do you test your modules ? I did !! ● 1: write a module ● 2: puppet parser validate ? ● 3: puppet-lint ? ● 4: puppet apply tests/init.pp (smoke) ● 5: puppet agent -t --noop – You use vagrant – right ??
  • 4.
  • 5. Start over again ● Me => devops ● Should be DEVops – Yes, we write code to manage our infrastructure. – Learn from Developers ● UNIT TESTING ● INTEGRATION TESTING ● ACCEPTANCE TESTING ● .....
  • 6. Testing is great ● Confidence changing things ● Discover breaking things before deploy ● Test against # puppet & # ruby versions ● Test many os'es without deploying them ● Test early - fast feedback ● Prevent regression of old problems
  • 7. First thing first ● Unit testing – Rspec-puppet – Start with testing, then coding ● It is the beginning of .. – Integration testing (beaker) – Travis – Jenkins – ....
  • 9. GoTest Driven Development Source http://centricconsulting.com/agile-test-driven-development/
  • 10. Benefits of TDD ● Test case from the beginning ● Better code coverage ● Tests are maintained during life cycle ● Focus on the needed functionality, step by step ● Encourage simple design (avoid over engineering) ● First step in test automation (unit testing)
  • 11. TDD does not ● Replace integration testing ● Replace compliance testing ● .......
  • 13. TDD and puppet modules ●Write the docs first (README.md) ● Explain your parameters ● Describe the defaults ● What is the function of your module ● What is it intended behaviour ●Write the first test from the README ●Run the tests, all should fail ●Write just enough code to pass the test ●Refactor and reiterate the process (Ted Arroway: Small moves, Ellie, small moves. [Contact] )
  • 14. The right tools for the right job ● http://www.rvm.io – Switch easily between ruby version ● Rspec-puppet – Written by tim : ● http:/rspec-puppet.com ● https://github.com/rodjek/rspec-puppet ● Puppet module skeleton – https://github.com/ghoneycutt/puppet-module-skeleton – https://github.com/garethr/puppet-module-skeleton – ...
  • 15. TDD and rspec-puppet ● Testing against the compiled catalog – Are the right resources in the catalogue – With the right attributes ● Is the rspec a duplicate of the manifest code – When you start – yes, because we start simple – But we can copy/paste ? Right !! – Refactoring a basic module shows already the benefits. ● Adding parameters ● Adding logic (eg. Support for multiple OS) ● ... ● Puppet modules with proper rspec test are better candidates ● It should/will become common to do PR including rspec tests
  • 16. Hands on TDD ● Based on the TDD tutorial Garrett Honeycutt – https://github.com/ghoneycutt/learnpuppet-tdd-vagrant – https://github.com/ghoneycutt/puppet-module-skeleton ● Why ? – Followed the TDD session on LOADays – Everything is configured out of the box – Easy to start doing it the right way – Garrett learned me puppet
  • 17. Hands on TDD – the setup ● The module directory tree [root@puppet motd]# tree -a . |-- .fixtures.yml |-- Gemfile |-- .gitignore |-- LICENSE |-- manifests | `-- init.pp |-- Modulefile |-- Rakefile |-- README.md |-- spec | |-- classes | | `-- init_spec.rb | `-- spec_helper.rb `-- .travis.yml
  • 18. Hands on TDD – the setup ● puppet generate module witjoh-motd ● mv witjoh-motd motd ● Rakefile [root@puppet motd]# rake -T rake build # Build puppet module package rake clean # Clean a built module package rake coverage # Generate code coverage information rake help # Display the list of available rake tasks rake lint # Check puppet manifests with puppet-lint / Run puppet-lint rake spec # Run spec tests in a clean fixtures directory rake spec_clean # Clean up the fixtures directory rake spec_prep # Create the fixtures directory rake spec_standalone # Run spec tests on an existing fixtures directory rake validate # Validate manifests, templates, and ruby files
  • 19. Hands on TDD – the setup ● spec_helper.rb – Code that is run before your spectest – Configures your spec testing environment [root@puppet spec]# cat spec_helper.rb require 'rubygems' require 'puppetlabs_spec_helper/module_spec_helper'
  • 20. Hands on TDD – the setup ● .fixtures.yml – Catalog dependencies are taken care off ● Resolves dependencies to other modules ● Creates symlink to own module ● (does not support metadata.json from forge modules) [root@puppet motd]# cat .fixtures.yml fixtures: repositories: stdlib: repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' ref: '3.2.0' symlinks: motd: "#{source_dir}"
  • 21. A Simple TDD Session workflow ● Write README first – Explain the function of your module – Parameters ● Default values ● Valid values ● Write the test based on the readme ● Write the code – Just enough code to pass the test ● Refactor and add more stuff –
  • 22. Hands on TDD – the test ● First test – <module >/spec/classes/init_spec.rb
  • 23. Rake validate [root@puppet classes]# rake validate (in /root/demos/motd) puppet parser validate --noop manifests/init.pp ruby -c spec/classes/init_spec.rb Syntax OK ruby -c spec/spec_helper.rb Syntax OK [root@puppet classes]#
  • 24. Hands on TDD – init_spec.rb require 'spec_helper' describe 'motd' do context 'with defaults for all parameters' do it { should contain_class('motd') } it { should contain_file('motd').with({ 'ensure' => 'file', 'path' => '/etc/motd', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'content' => nil, }) } end end
  • 25. Hands on TDD – Rake Spec
  • 26. Hands on TDD – The code # == Class: motd # # Module to manage motd # class motd { file { 'motd': ensure => 'file', path => '/etc/motd', owner => 'root', group => 'root', mode => '0644', content => undef, } }
  • 27. Hands on TDD – The test
  • 28. More rspec describe 'with path specified' do context 'as a valid path' do let(:params){{ :path => '/usr/local/etc/motd'}} it { should contain_file('motd').with({ 'path' => '/usr/local/etc/motd', }) } end context 'as an invalid path' do let(:params) { { :path => 'invalid/path' } } it 'should fail' do expect { should contain_class('motd') }.to raise_error(Puppet::Error) end end end
  • 29. More rspec ['666','66666','invalid',true].each do |mode| context "as invalid value #{mode}" do let(:params) { { :motd_mode => mode } } it 'should fail' do expect { should contain_class('motd') }.to raise_error(Puppet::Error,/^motd::mode must be a four digit string./) end end end
  • 30. # package it { should contain_package('ntp_package').with({ ... }) } # file it { should contain_file('ntp_config').with({ ... 'require' => 'Package[ntp]', }) } # service it { should contain_service('ntp_service').with({ ... 'subscribe' => 'File[ntp_config]', })
  • 31. More rspec # check for a specific line it { should contain_file('ntp_conf').with_content(/^tinker panic 0$/) } # Check that some content is not include it { should_not contain_file('ntp_conf').with_content(/^tinker panic 0$/) }
  • 32. More rspec context 'with default values for parameters on EL 6' do let(:facts) do { :osfamily => 'RedHat', :lsbmajdistrelease => '6', } end end
  • 33. More rspec – defined resources # spec/defines/mkdir_p_spec.rb require 'spec_helper' describe 'common::mkdir_p' do context 'should create new directory' do let(:title) { '/some/dir/structure' } it { should contain_exec('mkdir_p-/some/dir/structure').with({ 'command' => 'mkdir -p /some/dir/structure', 'unless' => 'test -d /some/dir/structure', }) } end
  • 34. More rspec – defined resources context 'should fail with a path that is not absolute' do let(:title) { 'not/a/valid/absolute/path' } it do expect { should contain_exec('mkdir_p- not/a/valid/absolute/path').with({ 'command' => 'mkdir -p not/a/valid/absolute/path', 'unless' => 'test -d not/a/valid/absolute/path', }) }.to raise_error(Puppet::Error) end end end
  • 35. What should be tested ● All resources should be in the catalog – 100% code coverage ● Parameters – Proper defaults – Setting params, does that work ? – Logic of params – Parameter validation
  • 36. What should be tested ● Module logic – Based on facts (eg: ::osfamily) – Multiple os support ● Dynamic content – Test your templates
  • 37. Unit testing is the beginning ● Integration testing ● Acceptance testing ● ....
  • 38. ?