SlideShare a Scribd company logo
@filippo
Test Driven Infrastructures
Filippo Liverani
@filippo
agile methods + IT operations?
photo credit: https://www.flickr.com/photos/kalexanderson/6354182139/
Test driven infrastructure
Test driven infrastructure
1. Test Driven Development
2. Infrastructure as code
3. From theory to practice
Test Driven Development
photo credit: https://www.flickr.com/photos/pagedooley/4308431673/
write a
failing unit
test
make it
pass
refactor
the 3 laws of TDD
photo credit: https://www.flickr.
1
You are not allowed to write
any production code unless it is
to make a failing unit test pass
2
You are not allowed to write any
more of a unit test than is
sufficient to fail
3
You are not allowed to write any
more production code than is
sufficient to pass the one failing
unit test
drives design
small incremental changes
continuous validation
rapid feedback
why it works?
reduces complexity
breaking down a difficult problem into smaller
pieces
listen to the tests
if it’s hard to write
the design is probably wrong
Test driven infrastructure
-> Acceptance Test Driven Development
acceptance criteria
examples
definition of done
write a failing
acceptance test
write a failing
acceptance test
write a
failing unit
test
make it
pass
refactor
write a failing
acceptance test
write a
failing unit
test
make it
pass
refactor
write a failing
acceptance test
benefits of TDD
higher code quality
regression test suite
feedback and confidence
more benefits of TDD
implicit acceptance criteria
executable documentation
prevent gold plating
challenges
takes time to learn
requires discipline
changing habits is hard
management does not perceive internal quality
infrastructure as code
photo credit: https://www.flickr.com/photos/mwichary/2348383457/
DevOps
+
virtualization and cloud
->
infrastructure is code too
programmatically configure and provision
everything versioned
business= code repository
+ data backup
+ compute resources
collaboration + automation
knowledge sharing
tooling
power of text
benefits
consistency and repeatability
scalability
testability
maintainability
challenges
spaghetti code
duplication
fear of change
low quality
side effects and chain reactions
TDD can help!
testing what?
Acceptance tests
Prototypes
Exploratory testing
Usability testing
Unit tests
Integration tests
Performance testing
Security testing
Business facing
Technology facing
Supporting
the
team
Critique
Product
credit: Brian Marik
testing what?
Acceptance tests
Prototypes
Exploratory testing
Usability testing
Unit tests
Integration tests
Performance testing
Security testing
Business facing
Technology facing
Supporting
the
team
Critique
Product
credit: Brian Marik
from theory to practice
photo credit: https://www.flickr.com/photos/jurvetson/489257240/
install and start Apache httpd server
exercise
tools needed
git
chefdk
vagrant
virtualbox
(packer)
Test driven infrastructure
$ git init httpd-cookbook
$ cd httpd-cookbook
Test driven infrastructure
$ chef generate cookbook httpd
Test Kitchen
$ kitchen init --driver=kitchen-vagrant
---
driver:
name: vagrant
provisioner:
name: chef_zero
platforms:
- name: ubuntu-14.04
suites:
- name: default
run_list:
- recipe[httpd::default]
httpd-cookbook/.kitchen.yml
write an acceptance test
Test driven infrastructure
require 'spec_helper'
describe service('apache2') do
it { should be_running }
describe port(80) do
it { should be_listening }
end
end
httpd-cookbook/test/integration/server/serverspec/default_spec.
rb
watch it fail
$ kitchen test
Service "apache2"
should be running (FAILED - 1)
Port "80"
should be listening (FAILED - 2)
write a unit test
require 'spec_helper'
describe 'httpd::default' do
let(:chef_run) {
ChefSpec::SoloRunner.converge(described_recipe)
}
it 'installs apache2 package' do
expect(chef_run).to install_package('apache2')
end
end
httpd-cookbook/spec/unit/recipes/default_spec.rb
watch it fail
$ chef exec rspec
F
Failures: 1) httpd::default installs apache2 package
Finished in 0.00957 seconds
1 example, 1 failure
make it pass
package 'apache2' do
action :install
end
httpd-cookbook/recipes/default.rb
$ chef exec rspec
.
Finished in 0.00946 seconds
1 example, 0 failures
refactor
write a unit test
require 'spec_helper'
describe 'httpd::default' do
let(:chef_run) {
ChefSpec::SoloRunner.converge(described_recipe)
}
it 'installs apache2 package' do
expect(chef_run).to install_package('apache2')
end
it 'starts apache2 service' do
expect(chef_run).to start_service('apache2')
end
end
httpd-cookbook/spec/unit/recipes/default_spec.rb
watch it fail
$ chef exec rspec
.F
Failures: 1) httpd::default starts apache2 service
Finished in 0.02133 seconds
2 example, 1 failure
make it pass
package 'apache2' do
action :install
end
service 'apache2' do
action :start
end
httpd-cookbook/recipes/default.rb
$ chef exec rspec
..
Finished in 0.02041 seconds
2 example, 0 failures
refactor
make acceptance test pass
$ kitchen test
Service "apache2"
should be running
Port "80"
should be listening
Finished in 0.09441 seconds
2 example, 0 failures
Finished verifying <default-ubuntu-1404> (0m6.52s).
-----> Kitchen is finished. (0m31.77s)
Test driven infrastructure
{
"variables": {
"aws_access_key": null,
"aws_secret_key": null
},
...
packer.json - 1
...
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "eu-west-1",
"ami_virtualization_type": "hvm",
"source_ami": "ami-28ff505f",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "httpd"
}]
...
packer.json - 2
...
"provisioners": [
{
"type": "chef-solo",
"cookbook_paths": ["berks-cookbooks"],
"run_list": ["httpd::default"]
}
]
}
packer.json - 3
source 'https://api.berkshelf.com'
cookbook 'httpd', path: './httpd-cookbook'
Berksfile
$ berks vendor
$ packer build 
-var 'aws_access_key=YOUR ACCESS KEY' 
-var 'aws_secret_key=YOUR SECRET KEY' 
packer.json
==> Builds finished. The artifacts of successful
builds are:
--> amazon-ebs: AMIs were created:
eu-west-1: ami-ac3199db
next steps
manage whole stack:
Terraform
Cloudformation
Heat
continuous delivery
TDD is a powerful technique
Treat your infrastructure as code
You can start now
risorse
Test driven infrastructure
Test driven infrastructure
Test driven infrastructure
thank you

More Related Content

PDF
Test Driven Infrastructure with Docker, Test Kitchen and Serverspec
PPTX
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
PDF
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
PPTX
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
PDF
Continuous infrastructure testing
PPTX
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
PPTX
OSDC2014: Testing Server Infrastructure with #serverspec
PDF
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Test Driven Infrastructure with Docker, Test Kitchen and Serverspec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Continuous infrastructure testing
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
OSDC2014: Testing Server Infrastructure with #serverspec
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014

What's hot (19)

PDF
Testable Infrastructure with Chef, Test Kitchen, and Docker
PDF
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
PDF
Portland PUG April 2014: Beaker 101: Acceptance Test Everything
PDF
Introduction to Ansible (Pycon7 2016)
PDF
Take control of your Jenkins jobs via job DSL.
PDF
Getting started with Ansible
PDF
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
PPTX
Testing Ansible
PDF
Test Driven Development with Puppet - PuppetConf 2014
PDF
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
PDF
Antons Kranga Building Agile Infrastructures
PDF
Cookbook testing with KitcenCI and Serverrspec
PPTX
DevOps Hackathon: Session 3 - Test Driven Infrastructure
PDF
Testing Your Automation Code (Docker Version)
PPTX
Automated Deployments with Ansible
PPTX
How to Write Chef Cookbook
PPTX
2019 Chef InSpec Jumpstart Part 2 of 2
PDF
Chef for beginners module 5
PDF
Puppet Camp Düsseldorf 2014: Continuously Deliver Your Puppet Code with Jenki...
Testable Infrastructure with Chef, Test Kitchen, and Docker
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Portland PUG April 2014: Beaker 101: Acceptance Test Everything
Introduction to Ansible (Pycon7 2016)
Take control of your Jenkins jobs via job DSL.
Getting started with Ansible
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Testing Ansible
Test Driven Development with Puppet - PuppetConf 2014
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Antons Kranga Building Agile Infrastructures
Cookbook testing with KitcenCI and Serverrspec
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Testing Your Automation Code (Docker Version)
Automated Deployments with Ansible
How to Write Chef Cookbook
2019 Chef InSpec Jumpstart Part 2 of 2
Chef for beginners module 5
Puppet Camp Düsseldorf 2014: Continuously Deliver Your Puppet Code with Jenki...
Ad

Similar to Test driven infrastructure (20)

PDF
Treat your servers like your Ruby App: Infrastructure as Code
PDF
Test Driven Development
PDF
Using Test Kitchen for testing Chef cookbooks
PDF
Test Kitchen and Infrastructure as Code
PDF
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
PPTX
Altitude San Francisco 2018: Testing with Fastly Workshop
PDF
Continous Delivering a PHP application
PDF
Testing in Laravel Framework
PPT
Zend Framework 2 - PHPUnit
PPTX
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
PDF
Stop Being Lazy and Test Your Software
PPTX
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
PDF
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
PDF
Keep your side-effects 
in the right place with 
redux observable
PDF
"To cover uncoverable", Andrii Shumada
PDF
One commit, one release. Continuously delivering a Symfony project.
KEY
Enterprise Build And Test In The Cloud
PPTX
АНДРІЙ ШУМАДА «To Cover Uncoverable» Online WDDay 2022 js
PPTX
Continuous Integration/ Continuous Delivery of web applications
PDF
Continuous integration / continuous delivery
Treat your servers like your Ruby App: Infrastructure as Code
Test Driven Development
Using Test Kitchen for testing Chef cookbooks
Test Kitchen and Infrastructure as Code
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Altitude San Francisco 2018: Testing with Fastly Workshop
Continous Delivering a PHP application
Testing in Laravel Framework
Zend Framework 2 - PHPUnit
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Stop Being Lazy and Test Your Software
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Keep your side-effects 
in the right place with 
redux observable
"To cover uncoverable", Andrii Shumada
One commit, one release. Continuously delivering a Symfony project.
Enterprise Build And Test In The Cloud
АНДРІЙ ШУМАДА «To Cover Uncoverable» Online WDDay 2022 js
Continuous Integration/ Continuous Delivery of web applications
Continuous integration / continuous delivery
Ad

More from XPeppers (20)

PDF
Yagni, You aren't gonna need it
PDF
Jenkins Shared Libraries
PDF
The Continuous Delivery process
PDF
A quick and fast intro to Kotlin
PDF
How Agile Dev Teams work
PDF
The Phoenix Project: un romanzo sull'IT
PDF
Metriche per finanziare il cambiamento
PDF
How do you handle renaming of a resource in RESTful way
PDF
La tecnica del pomodoro - Come viene adottata in XPeppers
PDF
Collective code ownership in Extreme Programming
PDF
What is Agile?
PDF
Improve your TDD skills
PDF
Banche agili un ossimoro?
PDF
Hiring Great People: how we improved our recruiting process to build and grow...
PDF
Continuous Delivery in Java
PDF
Life in XPeppers
PDF
Cloud e innovazione
PDF
Company culture slides
PDF
Agileday2013 Bravi si diventa
PDF
Agileday2013 pratiche agili applicate all'infrastruttura
Yagni, You aren't gonna need it
Jenkins Shared Libraries
The Continuous Delivery process
A quick and fast intro to Kotlin
How Agile Dev Teams work
The Phoenix Project: un romanzo sull'IT
Metriche per finanziare il cambiamento
How do you handle renaming of a resource in RESTful way
La tecnica del pomodoro - Come viene adottata in XPeppers
Collective code ownership in Extreme Programming
What is Agile?
Improve your TDD skills
Banche agili un ossimoro?
Hiring Great People: how we improved our recruiting process to build and grow...
Continuous Delivery in Java
Life in XPeppers
Cloud e innovazione
Company culture slides
Agileday2013 Bravi si diventa
Agileday2013 pratiche agili applicate all'infrastruttura

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
Modernizing your data center with Dell and AMD
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I

Test driven infrastructure