SlideShare a Scribd company logo
Test Driven
Infrastructure with
Docker, Test Kitchen
and Serverspec
Yury Tsarev
Agenda
▸ Goal
▸ Test kitchen
▸ Docker driver
▸ kitchen-puppet provisioner
▸ Serverspec verifier
▸ Shellmocking
▸ Defining puppet type in kitchen
▸ Create test-driven infrastructure change
▸ Wrap-up
Goal
▸ Infrastructure code should be treated as any other code
▸ Apply TDD for puppet
▸ Grow regression test suite
Test kitchen
▸ http://kitchen.ci/
▸ Test orchestrator
▸ Originated in Chef community
▸ Very pluggable on all levels
▸ "Your infrastructure deserves tests too."
▸ Book - Test-Driven Infrastructure with Chef
Test kitchen - high level process
1. Create VM/Container (docker driver)
2. Run configuration management code there (puppet
provisioner)
3. Test with verifier (serverspec)
Main configuration file - .kitchen.yml
▸ Driver: what type of VM/containerization/cloud to use
▸ Provisioner: which configuration management tool to apply
▸ Verifier: test automation type to verify with
▸ Transport: mechanism to upload files into instance under
test
Docker driver
▸ https://github.com/portertech/kitchen-docker
▸ kitchen driver to work with docker containers as machines
under test
driver:
name: docker
image: docker-registry.na.intgdc.com:80/gdc:R23
platform: rhel
use_sudo: false
provision_command:
yum clean all && yum makecache
kitchen-puppet provisioner
▸ https://github.com/neillturner/kitchen-puppet
▸ Uploads puppet code into instance
▸ Runs puppet there (converge)
▸ Provides facts customization facility
custom_facts:
docker: 1
hostname: kitchen_test
ec2data_branch: develop # pulp repo branch, critical for gitflow repo
ec2data_gitbranch: develop # git branch
ec2data_freeipa_otp: test
ec2_public_ipv4: 127.0.0.1
ec2_local_ipv4: 127.0.0.1
has_mnt: 0
Serverspec test suite
▸ http://serverspec.org/ - RSpec based framework
▸ http://serverspec.org/resource_types.html
▸ Independent of kitchen - can be used standalone
▸ We keep test suite together with puppet code under
spec directory to have ability to create consistent PRs
describe file('/var/log/httpd') do
it { should be_directory }
end
describe docker_image('busybox:latest') do
its(['Architecture']) { should eq 'amd64' }
end
Serverspec verifier: busser or shell
▸ Simple
https://github.com/test-kitchen/busser-serverspec
▸ Advanced
https://github.com/vincentbernat/serverspec-example
Serverspec verifier in GD
▸ Based on shell verifier and serverspec test suite
▸ Runs a serverspec test suite against the configured
(converged) instance
▸ Reports in shell and junit - jenkins ready
verifier:
name: shell
remote_exec: true
command: |
sudo -s <<SERVERSPEC
export SERVERSPEC_ENV=$EC2DATA_ENVIRONMENT
export SERVERSPEC_BACKEND=exec
serverspec junit=true tag=~skip_in_kitchen check:role:$EC2DATA_TYPE
SERVERSPEC
Transport
▸ https://github.com/coderanger/kitchen-sync
▸ Replaced default scp with sftp transport
▸ Reduced 1.5m to 5 sec for puppet and test suite upload!
Shellmocking
▸ To bypass external dependencies
▸ To bypass docker specific limitations
▸ Implementation located in puppet repo under
spec/shellmock
▸ Simple ruby script
▸ Wraps yum invocation
▸ Mock is defined in simple yaml format:
package:
/path/to/executable: contents
Defining puppet type in kitchen
▸ Declare in platforms section of .kitchen.yml
platforms:
- name: zuul
provisioner:
custom_facts:
ec2data_type: zuul
▸ kitchen converge
▸ pray
▸ shellmock
▸ repeat
Create test-driven infrastructure change
▸ Write serverspec expectation for new code
▸ kitchen verify <type>
▸ Observe related test is red
▸ Write puppet code
▸ kitchen converge <type>
▸ kitchen verify <type>
▸ Observe related test is green
▸ Commit the changes and create PR to puppet repo
▸ DEMO
Wrap-up: Benefits
▸ Scratch environment
▸ Test in isolation
▸ Easy to test permutations
▸ Resource efficiency
▸ Test-first/test-driven approach for infrastructure code
▸ Fast feedback - even before a commit
▸ Naturally growing regression test suite
Wrap-up: OSS side of things
▸ Multiple open source projects combined
▸ We contributed a lot into related kitchen projects and
serverspec
▸ Nominated as kitchen-puppet core contributor
Wrap-up: What is next ?
▸ Define all types in kitchen
▸ with every next adopted type it will be easier
▸ Create smart way to test only related types for code change,
a.k.a puppet dependency tracking
Wrap-up: A note on agnostic approach
▸ As the kitchen driver is agnostic to virtualization
solution/cloud
▸ As the kitchen provisioner is agnostic to configuration
management solution
▸ As the serverspec is agnostic to way to configure servers at
all
▸ We are capable to make brave movements in future!
Wrap-up: Try it!
▸ http://kitchen.ci/
▸ https://github.com/portertech/kitchen-docker
▸ https://github.com/neillturner/kitchen-puppet
▸ http://serverspec.org/

More Related Content

What's hot (20)

PPTX
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Antons Kranga
 
PDF
Cookbook testing with KitcenCI and Serverrspec
Daniel Paulus
 
PDF
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Puppet
 
PDF
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
PPTX
Baking docker using chef
Mukta Aphale
 
PDF
Ansible new paradigms for orchestration
Paolo Tonin
 
PDF
Testing Your Automation Code (Docker Version)
Mischa Taylor
 
PDF
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
PDF
Drone your Ansible
Dennis Rowe
 
PDF
Chef for beginners module 5
Chef
 
PDF
Cooking Perl with Chef
David Golden
 
PDF
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Puppet
 
PDF
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
PPTX
Vagrant to-aws-flow
Kimberly Macias
 
PDF
Tp install anything
Alessandro Franceschi
 
PDF
Chef for beginners module 2
Chef
 
PDF
Deploying an application with Chef and Docker
Daniel Ku
 
PDF
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Marcel Birkner
 
PDF
Testing with Ansible
Bas Meijer
 
PDF
Building kubectl plugins with Quarkus | DevNation Tech Talk
Red Hat Developers
 
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Antons Kranga
 
Cookbook testing with KitcenCI and Serverrspec
Daniel Paulus
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Puppet
 
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
Baking docker using chef
Mukta Aphale
 
Ansible new paradigms for orchestration
Paolo Tonin
 
Testing Your Automation Code (Docker Version)
Mischa Taylor
 
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
Drone your Ansible
Dennis Rowe
 
Chef for beginners module 5
Chef
 
Cooking Perl with Chef
David Golden
 
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Puppet
 
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
Vagrant to-aws-flow
Kimberly Macias
 
Tp install anything
Alessandro Franceschi
 
Chef for beginners module 2
Chef
 
Deploying an application with Chef and Docker
Daniel Ku
 
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Marcel Birkner
 
Testing with Ansible
Bas Meijer
 
Building kubectl plugins with Quarkus | DevNation Tech Talk
Red Hat Developers
 

Similar to Test Driven Infrastructure with Docker, Test Kitchen and Serverspec (20)

PDF
Chef basics - write infrastructure as code
stevaaa
 
PDF
Kubernetes Workshop
Walter Liu
 
PDF
Using Test Kitchen for testing Chef cookbooks
Timur Batyrshin
 
PPTX
What is Test Kitchen
Benoit Caron
 
PDF
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
PROIDEA
 
PDF
Automated-Testing-inside-containers
Manoj Kumar Kumar
 
PPTX
Cooking chef
ranjithar92
 
PDF
Kubernetes: training micro-dragons for a serious battle
Amir Moghimi
 
PDF
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeAcademy
 
PDF
Test-Driven Infrastructure with Chef
Michael Lihs
 
PDF
Testing Your Automation Code (Vagrant Version)
Mischa Taylor
 
PDF
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Erica Windisch
 
PDF
Testing your-automation-code (vagrant version) v0.2
Sylvain Tissot
 
PPTX
One click deployment
Alex Su
 
PDF
Testable Infrastructure with Chef, Test Kitchen, and Docker
Mandi Walls
 
PPTX
Get started with docker &amp; dev ops
Asya Dudnik
 
PDF
Docker dev, test & production (afas)
Wouter Lagerweij
 
PDF
PDXPortland - Dockerize Django
Hannes Hapke
 
PDF
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
PPTX
Get started with docker &amp; dev ops
Asya Dudnik
 
Chef basics - write infrastructure as code
stevaaa
 
Kubernetes Workshop
Walter Liu
 
Using Test Kitchen for testing Chef cookbooks
Timur Batyrshin
 
What is Test Kitchen
Benoit Caron
 
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
PROIDEA
 
Automated-Testing-inside-containers
Manoj Kumar Kumar
 
Cooking chef
ranjithar92
 
Kubernetes: training micro-dragons for a serious battle
Amir Moghimi
 
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeAcademy
 
Test-Driven Infrastructure with Chef
Michael Lihs
 
Testing Your Automation Code (Vagrant Version)
Mischa Taylor
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Erica Windisch
 
Testing your-automation-code (vagrant version) v0.2
Sylvain Tissot
 
One click deployment
Alex Su
 
Testable Infrastructure with Chef, Test Kitchen, and Docker
Mandi Walls
 
Get started with docker &amp; dev ops
Asya Dudnik
 
Docker dev, test & production (afas)
Wouter Lagerweij
 
PDXPortland - Dockerize Django
Hannes Hapke
 
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
Get started with docker &amp; dev ops
Asya Dudnik
 
Ad

Recently uploaded (20)

PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Ad

Test Driven Infrastructure with Docker, Test Kitchen and Serverspec

  • 1. Test Driven Infrastructure with Docker, Test Kitchen and Serverspec Yury Tsarev
  • 2. Agenda ▸ Goal ▸ Test kitchen ▸ Docker driver ▸ kitchen-puppet provisioner ▸ Serverspec verifier ▸ Shellmocking ▸ Defining puppet type in kitchen ▸ Create test-driven infrastructure change ▸ Wrap-up
  • 3. Goal ▸ Infrastructure code should be treated as any other code ▸ Apply TDD for puppet ▸ Grow regression test suite
  • 4. Test kitchen ▸ http://kitchen.ci/ ▸ Test orchestrator ▸ Originated in Chef community ▸ Very pluggable on all levels ▸ "Your infrastructure deserves tests too." ▸ Book - Test-Driven Infrastructure with Chef
  • 5. Test kitchen - high level process 1. Create VM/Container (docker driver) 2. Run configuration management code there (puppet provisioner) 3. Test with verifier (serverspec)
  • 6. Main configuration file - .kitchen.yml ▸ Driver: what type of VM/containerization/cloud to use ▸ Provisioner: which configuration management tool to apply ▸ Verifier: test automation type to verify with ▸ Transport: mechanism to upload files into instance under test
  • 7. Docker driver ▸ https://github.com/portertech/kitchen-docker ▸ kitchen driver to work with docker containers as machines under test driver: name: docker image: docker-registry.na.intgdc.com:80/gdc:R23 platform: rhel use_sudo: false provision_command: yum clean all && yum makecache
  • 8. kitchen-puppet provisioner ▸ https://github.com/neillturner/kitchen-puppet ▸ Uploads puppet code into instance ▸ Runs puppet there (converge) ▸ Provides facts customization facility custom_facts: docker: 1 hostname: kitchen_test ec2data_branch: develop # pulp repo branch, critical for gitflow repo ec2data_gitbranch: develop # git branch ec2data_freeipa_otp: test ec2_public_ipv4: 127.0.0.1 ec2_local_ipv4: 127.0.0.1 has_mnt: 0
  • 9. Serverspec test suite ▸ http://serverspec.org/ - RSpec based framework ▸ http://serverspec.org/resource_types.html ▸ Independent of kitchen - can be used standalone ▸ We keep test suite together with puppet code under spec directory to have ability to create consistent PRs describe file('/var/log/httpd') do it { should be_directory } end describe docker_image('busybox:latest') do its(['Architecture']) { should eq 'amd64' } end
  • 10. Serverspec verifier: busser or shell ▸ Simple https://github.com/test-kitchen/busser-serverspec ▸ Advanced https://github.com/vincentbernat/serverspec-example
  • 11. Serverspec verifier in GD ▸ Based on shell verifier and serverspec test suite ▸ Runs a serverspec test suite against the configured (converged) instance ▸ Reports in shell and junit - jenkins ready verifier: name: shell remote_exec: true command: | sudo -s <<SERVERSPEC export SERVERSPEC_ENV=$EC2DATA_ENVIRONMENT export SERVERSPEC_BACKEND=exec serverspec junit=true tag=~skip_in_kitchen check:role:$EC2DATA_TYPE SERVERSPEC
  • 12. Transport ▸ https://github.com/coderanger/kitchen-sync ▸ Replaced default scp with sftp transport ▸ Reduced 1.5m to 5 sec for puppet and test suite upload!
  • 13. Shellmocking ▸ To bypass external dependencies ▸ To bypass docker specific limitations ▸ Implementation located in puppet repo under spec/shellmock ▸ Simple ruby script ▸ Wraps yum invocation ▸ Mock is defined in simple yaml format: package: /path/to/executable: contents
  • 14. Defining puppet type in kitchen ▸ Declare in platforms section of .kitchen.yml platforms: - name: zuul provisioner: custom_facts: ec2data_type: zuul ▸ kitchen converge ▸ pray ▸ shellmock ▸ repeat
  • 15. Create test-driven infrastructure change ▸ Write serverspec expectation for new code ▸ kitchen verify <type> ▸ Observe related test is red ▸ Write puppet code ▸ kitchen converge <type> ▸ kitchen verify <type> ▸ Observe related test is green ▸ Commit the changes and create PR to puppet repo ▸ DEMO
  • 16. Wrap-up: Benefits ▸ Scratch environment ▸ Test in isolation ▸ Easy to test permutations ▸ Resource efficiency ▸ Test-first/test-driven approach for infrastructure code ▸ Fast feedback - even before a commit ▸ Naturally growing regression test suite
  • 17. Wrap-up: OSS side of things ▸ Multiple open source projects combined ▸ We contributed a lot into related kitchen projects and serverspec ▸ Nominated as kitchen-puppet core contributor
  • 18. Wrap-up: What is next ? ▸ Define all types in kitchen ▸ with every next adopted type it will be easier ▸ Create smart way to test only related types for code change, a.k.a puppet dependency tracking
  • 19. Wrap-up: A note on agnostic approach ▸ As the kitchen driver is agnostic to virtualization solution/cloud ▸ As the kitchen provisioner is agnostic to configuration management solution ▸ As the serverspec is agnostic to way to configure servers at all ▸ We are capable to make brave movements in future!
  • 20. Wrap-up: Try it! ▸ http://kitchen.ci/ ▸ https://github.com/portertech/kitchen-docker ▸ https://github.com/neillturner/kitchen-puppet ▸ http://serverspec.org/