SlideShare a Scribd company logo
1 #Dynatrace
with Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure
Puppet
Meetup
2 #Dynatrace
Insert
image here Martin Etmajer
Senior Technology Strategist at Dynatrace
martin.etmajer@dynatrace.com
@metmajer
3 #Dynatrace
Why Continuous Delivery?
4 #Dynatrace
Why Continuous Delivery?
5 #Dynatrace
Utmost Goal: Minimize Cycle Time
feature cycle time time
Customer Users
6 #Dynatrace
Utmost Goal: Minimize Cycle Time
feature cycle time time
Customer minimize Users
7 #Dynatrace
Utmost Goal: Minimize Cycle Time
feature cycle time time
Customer
This is when you
create value!
minimize
8 #Dynatrace
Utmost Goal: Minimize Cycle Time
feature cycle time time
Customer
You
This is when you
create value!
minimize
9 #Dynatrace
Utmost Goal: Minimize Cycle Time
feature cycle time time
Customer
You
minimize
It’s about getting your features into your user’s hands
as quickly and confidently as possible!
10 #Dynatrace
Align Development and IT Operations
IT OPERATIONS
DEVELOPMENT
time
11 #Dynatrace
Align Development and IT Operations
IT OPERATIONS
DEVELOPMENT
current iteration
(e.g. 2 weeks)
time
12 #Dynatrace
Align Development and IT Operations
IT OPERATIONS
DEVELOPMENT
current iteration
(e.g. 2 weeks)
time
Planning
13 #Dynatrace
Align Development and IT Operations
IT OPERATIONS
DEVELOPMENT
current iteration
(e.g. 2 weeks)
time
Planning
Implementing
and testing
14 #Dynatrace
Align Development and IT Operations
IT OPERATIONS
DEVELOPMENT
current iteration
(e.g. 2 weeks)
time
Planning
Implementing
and testing
Working and
deployable code
15 #Dynatrace
Why Test-Driven
Infrastructure?
16 #Dynatrace
You write code!
17 #Dynatrace
“Make it work. Make it right. Make it fast.”
Kent Beck, Creator of Extreme Programming and Test-Driven Development
Get the code to
operate correctly
Make the code clear,
enforce good design Optimize
18 #Dynatrace
The Red, Green, Refactor Cycle of TDD
Write a Failing Test
Make the Test PassClean Up your Code
Small increments
Able to return to known working code
Designed and
tested code
Protects against regressions
19 #Dynatrace
Test Kitchen
Key Concepts
Pluggable Architecture
20 #Dynatrace
» Drivers
» Platforms
» Provisioners
» Test Suites
Key Concepts
21 #Dynatrace
» Drivers
» Platforms
» Provisioners
» Test Suites
Key Concepts
22 #Dynatrace
Drivers let you run your code on various...
Cloud Providers
» Azure, Cloud Stack, EC2, Digital Ocean, GCE, Rackspace,...
Virtualization Technologies
» Vagrant, Docker, LXC
Test Kitchen: Drivers
23 #Dynatrace
» Drivers
» Platforms
» Provisioners
» Test Suites
Key Concepts
24 #Dynatrace
Platforms are the Operating Systems you want to run on.
Platforms
» Linux- or Windows-based (since Test Kitchen 1.4.0)
How to manage dependencies?
» Automatically resolved when using Docker or Vagrant
» Build your own and link them in the configuration file
Test Kitchen: Platforms
25 #Dynatrace
» Drivers
» Platforms
» Provisioners
» Test Suites
Key Concepts
26 #Dynatrace
Provisioners are the tools used to converge the environment.
Provisioners
» Ansible, Chef, CFEngine, Puppet, SaltStack
Why cool?
» Useful if you need to support multiple of these tools
Test Kitchen: Provisioners
27 #Dynatrace
» Drivers
» Platforms
» Provisioners
» Test Suites
Key Concepts
28 #Dynatrace
Test Suites define the tests to run against each platform.
Test Frameworks
» Bash, Bats, Cucumber, RSpec, Serverspec
Test Kitchen: Test Suites
29 #Dynatrace
Test Kitchen
Installation
30 #Dynatrace
Installation
Ready?
$ gem install test-kitchen kitchen-docker kitchen-puppet
Test Kitchen: Installation
$ kitchen version
Test Kitchen version 1.4.2
31 #Dynatrace
Test Kitchen
Configuration
32 #Dynatrace
Create a Puppet Module
Initialize Test Kitchen
$ mkdir –p my-puppet-module
$ cd my-puppet-module
Test Kitchen: Testing a Puppet Module
$ kitchen init --driver=docker --provisioner=puppet_apply
create .kitchen.yml
create test/integration/default
Configuration goes here!
Tests go here!
33 #Dynatrace
.kitchen.yml (as provided via `kitchen init`)
---
driver:
name: docker
provisioner:
name: puppet_apply
platforms:
- name: ubuntu-14.04
- name: centos-7.1
suites:
- name: default
run_list:
attributes:
Test Kitchen: Testing a Puppet Module
Names resolve to
Docker Images on
the Docker Hub
34 #Dynatrace
.kitchen.yml (slightly adjusted)
---
driver:
name: docker
provisioner:
name: puppet_apply
puppet_version: latest
files_path: files
manifests_path: test/integration
manifest: default/init.pp
puppet_verbose: true
puppet_debug: false
Test Kitchen: Testing a Puppet Module
platforms:
- name: ubuntu-14.04
- name: centos-7.1
suites:
- name: default
35 #Dynatrace
$ kitchen list
Instance Driver Provisioner Transport Last Action
default-ubuntu-1404 Docker PuppetApply Ssh <Not Created>
default-centos-71 Docker PuppetApply Ssh <Not Created>
`kitchen list`: List Test Kitchen Instances
Test Kitchen: Installation
This will change...Test Suite Platform
36 #Dynatrace
Test Kitchen
Write an Integration Test
37 #Dynatrace
Create a Puppet Manifest for Test Suite ‘default’
Test Kitchen: Testing a Puppet Module
$ kitchen init --driver=docker --provisioner=puppet_apply
create .kitchen.yml
create test/integration/default
Configuration goes here!
Tests go here!
38 #Dynatrace
test/integration/default/init.pp
class { ‘foo’: }
class { ‘bar‘:
bar_param => ...,
require => Class[‘foo’]
}
class { ‘baz’:
baz_param => ..,
require => Class[‘bar’]
}
...
Test Kitchen: Testing a Puppet Module
Create your
environment
Puppet Manifest
Test Suite
39 #Dynatrace
Serverspec and RSpec
A Short Primer
40 #Dynatrace
RSpec is a TDD tool for Ruby programmers.
RSpec
require ‘foo’
describe Foo do
before do
@foo = Foo.new
end
it ‘method #bar does something useful’ do
@foo.bar.should eq ‘something useful’
end
end
41 #Dynatrace
Serverspec is RSpec for your infrastructure.
Serverspec
require ‘serverspec’
describe user(‘foo’) do
it { should exist }
it { should belong_to_group ‘foo’ }
end
describe file(‘/opt/bar’) do
it { should be_directory }
it { should be_mode 777 }
it { should be_owned_by ‘foo’ }
it { should be_grouped_into ‘foo’ }
end
describe service(‘bar’) do
it { should be_enabled }
it { should be_running }
end
describe port(8080) do
it { should be_listening }
end
describe command(‘apachectl –M’) do
its(:stdout) { should contain(‘proxy_module’) }
end
Resource
Matcher
42 #Dynatrace
test/integration/default/serverspec/default_spec.rb
require ‘serverspec’
describe user(‘foo’) do
it { should exist }
it { should belong_to_group ‘foo’ }
end
Test Kitchen: Testing a Puppet Module
Test
Test Suite Do Serverspec!
43 #Dynatrace
`kitchen test`: Run Test Kitchen Test
Test Kitchen: Testing a Puppet Module
$ kitchen test default-ubuntu-1404
$ kitchen test ubuntu
$ kitchen test
regex!
$ kitchen list
Instance Driver Provisioner Transport Last Action
default-ubuntu-1404 Docker PuppetApply Ssh <Not Created>
default-centos-71 Docker PuppetApply Ssh <Not Created>
44 #Dynatrace
Test Kitchen: Actions
Test = Converge Setup Verify
Instance created
and provisioned
Instance ready for verification
(dependencies installed)
45 #Dynatrace
`kitchen test`: Run Test Kitchen Test
$ kitchen test ubuntu
...
User "foo"
should exist
should belong to group "foo"
Finished in 0.14825 seconds (files took 0.6271 seconds to load)
2 examples, 0 failures
Finished verifying <default-ubuntu-1404> (0m37.21s).
Test Kitchen: Testing a Puppet Module
46 #Dynatrace
`kitchen list`: List Test Kitchen Instances
Test Kitchen: Testing a Puppet Module
$ kitchen list
Instance Driver Provisioner Transport Last Action
default-ubuntu-1404 Docker PuppetApply Ssh Verified
default-centos-71 Docker PuppetApply Ssh <Not Created>
47 #Dynatrace
Test Kitchen with Puppet
Advanced Tips
48 #Dynatrace
Testing Puppet Modules
in Amazon EC2
49 #Dynatrace
.kitchen.yml
---
driver:
name: ec2
aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID']%>"
aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY']%>"
aws_ssh_key_id: "<%= ENV['AWS_SSH_KEY_ID']%>"
region: eu-west-1
availability_zone: eu-west-1b
transport:
ssh_key: "<%= ENV['AWS_SSH_KEY_PATH']%>"
username: admin
...
Test Kitchen: Testing Puppet Modules in EC2
Environment Variables
50 #Dynatrace
Testing REST APIs
with RSpec
Not supported by Serverspec
51 #Dynatrace
Testing REST APIs
with RSpec
Infraspec not yet integrated
52 #Dynatrace
test/integration/default/rspec/default_spec.rb
require ‘json’
require ‘net/http’
...
describe ‘Server REST API’ do
it ‘/rest/foo responds correctly’ do
uri = URI(‘http://localhost:8080/rest/foo’)
request = Net::HTTP::Get.new(uri, { ‘Accept’ => ‘application/json’ })
request.basic_auth(‘foo’, ‘foo’)
response = Net::HTTP.new(uri.host, uri.port).request(request)
expect(response.code).to eq 200
expect(JSON.parse(response.body)).to eq { ‘bar’ => ‘baz’ }
end
end
Test Kitchen: Testing REST APIs
Do RSpec!
53 #Dynatrace
test/integration/default/rspec/default_spec.rb
require ‘json’
require ‘net/http’
...
describe ‘Server REST API’ do
it ‘/rest/foo responds correctly’ do
uri = URI(‘http://localhost:8080/rest/foo’)
request = Net::HTTP::Get.new(uri, { ‘Accept’ => ‘application/json’ })
request.basic_auth(‘foo’, ‘foo’)
response = Net::HTTP.new(uri.host, uri.port).request(request)
expect(response.code).to eq 200
expect(JSON.parse(response.body)).to eq { ‘bar’ => ‘baz’ }
end
end
Test Kitchen: Testing REST APIs
Could use serverspec!
54 #Dynatrace
Dynatrace-Puppet Module
Further Examples: https://github.com/dynaTrace/Dynatrace-Puppet
55 #Dynatrace
56 #Dynatrace
Questions?
57 #Dynatrace

More Related Content

What's hot (20)

PDF
Continuous infrastructure testing
Daniel Paulus
 
PDF
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Puppet
 
PPTX
Docker ansible-make-chef-puppet-unnecessary-minnihan
jbminn
 
PDF
Introduction to Ansible (Pycon7 2016)
Ivan Rossi
 
PPTX
Automated Deployments with Ansible
Martin Etmajer
 
PDF
Investigation of testing with ansible
Dennis Rowe
 
PDF
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
PDF
The Puppet Master on the JVM - PuppetConf 2014
Puppet
 
PPTX
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn
 
PDF
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Puppet
 
PPTX
Go Faster with Ansible (PHP meetup)
Richard Donkin
 
PDF
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
PDF
10 Million hits a day with WordPress using a $15 VPS
Paolo Tonin
 
PDF
Containing Chaos with Kubernetes - Terrence Ryan, Google - DevOpsDays Tel Avi...
DevOpsDays Tel Aviv
 
PDF
Making Spinnaker Go @ Stitch Fix
Diana Tkachenko
 
PDF
Ansible Crash Course
Peter Sankauskas
 
PDF
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Puppet
 
PPTX
Monitoring and tuning your chef server - chef conf talk
Andrew DuFour
 
PDF
Cookbook testing with KitcenCI and Serverrspec
Daniel Paulus
 
PDF
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
rmcleay
 
Continuous infrastructure testing
Daniel Paulus
 
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Puppet
 
Docker ansible-make-chef-puppet-unnecessary-minnihan
jbminn
 
Introduction to Ansible (Pycon7 2016)
Ivan Rossi
 
Automated Deployments with Ansible
Martin Etmajer
 
Investigation of testing with ansible
Dennis Rowe
 
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
The Puppet Master on the JVM - PuppetConf 2014
Puppet
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Puppet
 
Go Faster with Ansible (PHP meetup)
Richard Donkin
 
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
10 Million hits a day with WordPress using a $15 VPS
Paolo Tonin
 
Containing Chaos with Kubernetes - Terrence Ryan, Google - DevOpsDays Tel Avi...
DevOpsDays Tel Aviv
 
Making Spinnaker Go @ Stitch Fix
Diana Tkachenko
 
Ansible Crash Course
Peter Sankauskas
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Puppet
 
Monitoring and tuning your chef server - chef conf talk
Andrew DuFour
 
Cookbook testing with KitcenCI and Serverrspec
Daniel Paulus
 
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
rmcleay
 

Viewers also liked (20)

PDF
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
PDF
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Puppet
 
PPTX
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Martin Etmajer
 
PDF
2014-11-11 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Seattle
garrett honeycutt
 
PDF
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Puppet
 
PPTX
Automated Deployments
Martin Etmajer
 
PPTX
Ansible presentation
Suresh Kumar
 
PPTX
Ansible presentation
Kumar Y
 
PDF
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
Zabbix User Group
 
PPTX
Introduction to Automated Deployments with Ansible
Martin Etmajer
 
PPTX
Deploying On-Prem as SaaS: Why we go with Ansible
Martin Etmajer
 
PPTX
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
Martin Etmajer
 
PPTX
Serverspec and Sensu - Testing and Monitoring collide
m_richardson
 
PDF
Ansible Overview - System Administration and Maintenance
Jishnu P
 
PDF
Ansible - Introduction
Stephane Manciot
 
PDF
Monitoring all Elements of Your Database Operations With Zabbix
Zabbix
 
PDF
Alexei Vladishev - Zabbix - Monitoring Solution for Everyone
Zabbix
 
PPTX
Monitoring Microservices at Scale on OpenShift (OpenShift Commons Briefing #52)
Martin Etmajer
 
PDF
Zabbix 3.0 and beyond - FISL 2015
Zabbix
 
PPTX
Introduction to Zabbix - Company, Product, Services and Use Cases
Zabbix
 
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Puppet
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Martin Etmajer
 
2014-11-11 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Seattle
garrett honeycutt
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Puppet
 
Automated Deployments
Martin Etmajer
 
Ansible presentation
Suresh Kumar
 
Ansible presentation
Kumar Y
 
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
Zabbix User Group
 
Introduction to Automated Deployments with Ansible
Martin Etmajer
 
Deploying On-Prem as SaaS: Why we go with Ansible
Martin Etmajer
 
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
Martin Etmajer
 
Serverspec and Sensu - Testing and Monitoring collide
m_richardson
 
Ansible Overview - System Administration and Maintenance
Jishnu P
 
Ansible - Introduction
Stephane Manciot
 
Monitoring all Elements of Your Database Operations With Zabbix
Zabbix
 
Alexei Vladishev - Zabbix - Monitoring Solution for Everyone
Zabbix
 
Monitoring Microservices at Scale on OpenShift (OpenShift Commons Briefing #52)
Martin Etmajer
 
Zabbix 3.0 and beyond - FISL 2015
Zabbix
 
Introduction to Zabbix - Company, Product, Services and Use Cases
Zabbix
 
Ad

Similar to Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec (20)

PDF
Continuous Integration Testing in Django
Kevin Harvey
 
PPTX
Lookout-Cucumber-Chef
Zachary Patten
 
PDF
Stop Being Lazy and Test Your Software
Laura Frank Tacho
 
PDF
Chef for beginners module 5
Chef
 
PDF
Building Autonomous Operations for Kubernetes with keptn
Johannes Bräuer
 
PPTX
What's new in Docker - InfraKit - Docker Meetup Berlin 2016
Patrick Chanezon
 
PDF
Automate Thyself
Ortus Solutions, Corp
 
PDF
Troubleshooting tips from docker support engineers
Docker, Inc.
 
PDF
PaaSTA: Running applications at Yelp
Nathan Handler
 
PDF
Ephemeral DevOps: Adventures in Managing Short-Lived Systems
Priyanka Aash
 
PPTX
Pynvme introduction
Crane Chu
 
PDF
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
PDF
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Jimmy Lai
 
PDF
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
PROIDEA
 
PPTX
DevOps Practices @Pipedrive
Renno Reinurm
 
PPTX
Containerize your Blackbox tests
Kevin Beeman
 
PPTX
DockerCon EU 2015: Stop Being Lazy and Test Your Software!
Docker, Inc.
 
PPTX
Effective Testing with Ansible and InSpec
Nathen Harvey
 
PPTX
PuppetConf 2017: Test First Approach for Puppet on Windows- Miro Sommer, Hiscox
Puppet
 
PPTX
Introduction to Test Kitchen and InSpec
Nathen Harvey
 
Continuous Integration Testing in Django
Kevin Harvey
 
Lookout-Cucumber-Chef
Zachary Patten
 
Stop Being Lazy and Test Your Software
Laura Frank Tacho
 
Chef for beginners module 5
Chef
 
Building Autonomous Operations for Kubernetes with keptn
Johannes Bräuer
 
What's new in Docker - InfraKit - Docker Meetup Berlin 2016
Patrick Chanezon
 
Automate Thyself
Ortus Solutions, Corp
 
Troubleshooting tips from docker support engineers
Docker, Inc.
 
PaaSTA: Running applications at Yelp
Nathan Handler
 
Ephemeral DevOps: Adventures in Managing Short-Lived Systems
Priyanka Aash
 
Pynvme introduction
Crane Chu
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Jimmy Lai
 
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
PROIDEA
 
DevOps Practices @Pipedrive
Renno Reinurm
 
Containerize your Blackbox tests
Kevin Beeman
 
DockerCon EU 2015: Stop Being Lazy and Test Your Software!
Docker, Inc.
 
Effective Testing with Ansible and InSpec
Nathen Harvey
 
PuppetConf 2017: Test First Approach for Puppet on Windows- Miro Sommer, Hiscox
Puppet
 
Introduction to Test Kitchen and InSpec
Nathen Harvey
 
Ad

Recently uploaded (20)

PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
July Patch Tuesday
Ivanti
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Designing Production-Ready AI Agents
Kunal Rai
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 

Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec

  • 1. 1 #Dynatrace with Test Kitchen, Serverspec and RSpec Test-Driven Infrastructure Puppet Meetup
  • 2. 2 #Dynatrace Insert image here Martin Etmajer Senior Technology Strategist at Dynatrace [email protected] @metmajer
  • 5. 5 #Dynatrace Utmost Goal: Minimize Cycle Time feature cycle time time Customer Users
  • 6. 6 #Dynatrace Utmost Goal: Minimize Cycle Time feature cycle time time Customer minimize Users
  • 7. 7 #Dynatrace Utmost Goal: Minimize Cycle Time feature cycle time time Customer This is when you create value! minimize
  • 8. 8 #Dynatrace Utmost Goal: Minimize Cycle Time feature cycle time time Customer You This is when you create value! minimize
  • 9. 9 #Dynatrace Utmost Goal: Minimize Cycle Time feature cycle time time Customer You minimize It’s about getting your features into your user’s hands as quickly and confidently as possible!
  • 10. 10 #Dynatrace Align Development and IT Operations IT OPERATIONS DEVELOPMENT time
  • 11. 11 #Dynatrace Align Development and IT Operations IT OPERATIONS DEVELOPMENT current iteration (e.g. 2 weeks) time
  • 12. 12 #Dynatrace Align Development and IT Operations IT OPERATIONS DEVELOPMENT current iteration (e.g. 2 weeks) time Planning
  • 13. 13 #Dynatrace Align Development and IT Operations IT OPERATIONS DEVELOPMENT current iteration (e.g. 2 weeks) time Planning Implementing and testing
  • 14. 14 #Dynatrace Align Development and IT Operations IT OPERATIONS DEVELOPMENT current iteration (e.g. 2 weeks) time Planning Implementing and testing Working and deployable code
  • 17. 17 #Dynatrace “Make it work. Make it right. Make it fast.” Kent Beck, Creator of Extreme Programming and Test-Driven Development Get the code to operate correctly Make the code clear, enforce good design Optimize
  • 18. 18 #Dynatrace The Red, Green, Refactor Cycle of TDD Write a Failing Test Make the Test PassClean Up your Code Small increments Able to return to known working code Designed and tested code Protects against regressions
  • 19. 19 #Dynatrace Test Kitchen Key Concepts Pluggable Architecture
  • 20. 20 #Dynatrace » Drivers » Platforms » Provisioners » Test Suites Key Concepts
  • 21. 21 #Dynatrace » Drivers » Platforms » Provisioners » Test Suites Key Concepts
  • 22. 22 #Dynatrace Drivers let you run your code on various... Cloud Providers » Azure, Cloud Stack, EC2, Digital Ocean, GCE, Rackspace,... Virtualization Technologies » Vagrant, Docker, LXC Test Kitchen: Drivers
  • 23. 23 #Dynatrace » Drivers » Platforms » Provisioners » Test Suites Key Concepts
  • 24. 24 #Dynatrace Platforms are the Operating Systems you want to run on. Platforms » Linux- or Windows-based (since Test Kitchen 1.4.0) How to manage dependencies? » Automatically resolved when using Docker or Vagrant » Build your own and link them in the configuration file Test Kitchen: Platforms
  • 25. 25 #Dynatrace » Drivers » Platforms » Provisioners » Test Suites Key Concepts
  • 26. 26 #Dynatrace Provisioners are the tools used to converge the environment. Provisioners » Ansible, Chef, CFEngine, Puppet, SaltStack Why cool? » Useful if you need to support multiple of these tools Test Kitchen: Provisioners
  • 27. 27 #Dynatrace » Drivers » Platforms » Provisioners » Test Suites Key Concepts
  • 28. 28 #Dynatrace Test Suites define the tests to run against each platform. Test Frameworks » Bash, Bats, Cucumber, RSpec, Serverspec Test Kitchen: Test Suites
  • 30. 30 #Dynatrace Installation Ready? $ gem install test-kitchen kitchen-docker kitchen-puppet Test Kitchen: Installation $ kitchen version Test Kitchen version 1.4.2
  • 32. 32 #Dynatrace Create a Puppet Module Initialize Test Kitchen $ mkdir –p my-puppet-module $ cd my-puppet-module Test Kitchen: Testing a Puppet Module $ kitchen init --driver=docker --provisioner=puppet_apply create .kitchen.yml create test/integration/default Configuration goes here! Tests go here!
  • 33. 33 #Dynatrace .kitchen.yml (as provided via `kitchen init`) --- driver: name: docker provisioner: name: puppet_apply platforms: - name: ubuntu-14.04 - name: centos-7.1 suites: - name: default run_list: attributes: Test Kitchen: Testing a Puppet Module Names resolve to Docker Images on the Docker Hub
  • 34. 34 #Dynatrace .kitchen.yml (slightly adjusted) --- driver: name: docker provisioner: name: puppet_apply puppet_version: latest files_path: files manifests_path: test/integration manifest: default/init.pp puppet_verbose: true puppet_debug: false Test Kitchen: Testing a Puppet Module platforms: - name: ubuntu-14.04 - name: centos-7.1 suites: - name: default
  • 35. 35 #Dynatrace $ kitchen list Instance Driver Provisioner Transport Last Action default-ubuntu-1404 Docker PuppetApply Ssh <Not Created> default-centos-71 Docker PuppetApply Ssh <Not Created> `kitchen list`: List Test Kitchen Instances Test Kitchen: Installation This will change...Test Suite Platform
  • 36. 36 #Dynatrace Test Kitchen Write an Integration Test
  • 37. 37 #Dynatrace Create a Puppet Manifest for Test Suite ‘default’ Test Kitchen: Testing a Puppet Module $ kitchen init --driver=docker --provisioner=puppet_apply create .kitchen.yml create test/integration/default Configuration goes here! Tests go here!
  • 38. 38 #Dynatrace test/integration/default/init.pp class { ‘foo’: } class { ‘bar‘: bar_param => ..., require => Class[‘foo’] } class { ‘baz’: baz_param => .., require => Class[‘bar’] } ... Test Kitchen: Testing a Puppet Module Create your environment Puppet Manifest Test Suite
  • 39. 39 #Dynatrace Serverspec and RSpec A Short Primer
  • 40. 40 #Dynatrace RSpec is a TDD tool for Ruby programmers. RSpec require ‘foo’ describe Foo do before do @foo = Foo.new end it ‘method #bar does something useful’ do @foo.bar.should eq ‘something useful’ end end
  • 41. 41 #Dynatrace Serverspec is RSpec for your infrastructure. Serverspec require ‘serverspec’ describe user(‘foo’) do it { should exist } it { should belong_to_group ‘foo’ } end describe file(‘/opt/bar’) do it { should be_directory } it { should be_mode 777 } it { should be_owned_by ‘foo’ } it { should be_grouped_into ‘foo’ } end describe service(‘bar’) do it { should be_enabled } it { should be_running } end describe port(8080) do it { should be_listening } end describe command(‘apachectl –M’) do its(:stdout) { should contain(‘proxy_module’) } end Resource Matcher
  • 42. 42 #Dynatrace test/integration/default/serverspec/default_spec.rb require ‘serverspec’ describe user(‘foo’) do it { should exist } it { should belong_to_group ‘foo’ } end Test Kitchen: Testing a Puppet Module Test Test Suite Do Serverspec!
  • 43. 43 #Dynatrace `kitchen test`: Run Test Kitchen Test Test Kitchen: Testing a Puppet Module $ kitchen test default-ubuntu-1404 $ kitchen test ubuntu $ kitchen test regex! $ kitchen list Instance Driver Provisioner Transport Last Action default-ubuntu-1404 Docker PuppetApply Ssh <Not Created> default-centos-71 Docker PuppetApply Ssh <Not Created>
  • 44. 44 #Dynatrace Test Kitchen: Actions Test = Converge Setup Verify Instance created and provisioned Instance ready for verification (dependencies installed)
  • 45. 45 #Dynatrace `kitchen test`: Run Test Kitchen Test $ kitchen test ubuntu ... User "foo" should exist should belong to group "foo" Finished in 0.14825 seconds (files took 0.6271 seconds to load) 2 examples, 0 failures Finished verifying <default-ubuntu-1404> (0m37.21s). Test Kitchen: Testing a Puppet Module
  • 46. 46 #Dynatrace `kitchen list`: List Test Kitchen Instances Test Kitchen: Testing a Puppet Module $ kitchen list Instance Driver Provisioner Transport Last Action default-ubuntu-1404 Docker PuppetApply Ssh Verified default-centos-71 Docker PuppetApply Ssh <Not Created>
  • 47. 47 #Dynatrace Test Kitchen with Puppet Advanced Tips
  • 48. 48 #Dynatrace Testing Puppet Modules in Amazon EC2
  • 49. 49 #Dynatrace .kitchen.yml --- driver: name: ec2 aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID']%>" aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY']%>" aws_ssh_key_id: "<%= ENV['AWS_SSH_KEY_ID']%>" region: eu-west-1 availability_zone: eu-west-1b transport: ssh_key: "<%= ENV['AWS_SSH_KEY_PATH']%>" username: admin ... Test Kitchen: Testing Puppet Modules in EC2 Environment Variables
  • 50. 50 #Dynatrace Testing REST APIs with RSpec Not supported by Serverspec
  • 51. 51 #Dynatrace Testing REST APIs with RSpec Infraspec not yet integrated
  • 52. 52 #Dynatrace test/integration/default/rspec/default_spec.rb require ‘json’ require ‘net/http’ ... describe ‘Server REST API’ do it ‘/rest/foo responds correctly’ do uri = URI(‘http://localhost:8080/rest/foo’) request = Net::HTTP::Get.new(uri, { ‘Accept’ => ‘application/json’ }) request.basic_auth(‘foo’, ‘foo’) response = Net::HTTP.new(uri.host, uri.port).request(request) expect(response.code).to eq 200 expect(JSON.parse(response.body)).to eq { ‘bar’ => ‘baz’ } end end Test Kitchen: Testing REST APIs Do RSpec!
  • 53. 53 #Dynatrace test/integration/default/rspec/default_spec.rb require ‘json’ require ‘net/http’ ... describe ‘Server REST API’ do it ‘/rest/foo responds correctly’ do uri = URI(‘http://localhost:8080/rest/foo’) request = Net::HTTP::Get.new(uri, { ‘Accept’ => ‘application/json’ }) request.basic_auth(‘foo’, ‘foo’) response = Net::HTTP.new(uri.host, uri.port).request(request) expect(response.code).to eq 200 expect(JSON.parse(response.body)).to eq { ‘bar’ => ‘baz’ } end end Test Kitchen: Testing REST APIs Could use serverspec!
  • 54. 54 #Dynatrace Dynatrace-Puppet Module Further Examples: https://github.com/dynaTrace/Dynatrace-Puppet

Editor's Notes

  • #17: And as we are dealing with code - “infrastructure as code” namely – why shouldn’t we apply the same principles that help us create better software to create better infrastructure? After all, a bug in the environment may have more severe consequences than a bug in a software.
  • #18: See: - http://c2.com/cgi/wiki?MakeItWorkMakeItRightMakeItFast
  • #19: See: http://www.jamesshore.com/Agile-Book/test_driven_development.html http://blog.goyello.com/2011/09/13/red-green-refactor-cycle/