SlideShare a Scribd company logo
TESTING SERVERS
LIKE SOFTWARE
ME
DEVELOPER TURNED ops guy
WORKING AT KAINOS, CONTRACTING ON
GOVERNMENT PROJECTS
PREVIOUSLY ON THE IER
PROJECT
NOW LIVE! HTTPS://WWW.GOV.UK/
REGISTER-TO-VOTE
NOW ON THE DEFRA CAPD PROJECT
FOREWARNING
▸ Ruby and Puppet Biased
▸ They're the tools I use the most!
▸ But most tools mentioned are system and tool agnostic
SO YOU'VE MADE A
CONFIGURATION CODE
CHANGE...
THE UNIT TESTS
PASS...
IT'S BEEN CODE
REVIEWED
SO YOU PUSH TO
PRODUCTION!
IT DOESNT
WORK...
WHAT'S THE
MISSING STEP?
ACCEPTANCE
TESTING:
Serverspec
"Serverspec tests your servers'actual
state through SSH access"
CHECK YOUR SERVER
▸ Is $package installed?
▸ Does file contain $foo?
▸ Does the firewall have the correct rules?
▸ Is service running?
▸ etc...
RESOURCE TYPES
cgroup, command, cron, default_gateway, file,
group, host, iis_app_pool, iis_website,
interface, ipfilter, ipnat, iptables,
kernel_module, linux_kernel_parameter, lxc,
mail_alias, package, php_config, port, ppa,
process, routing_table, selinux, service, user,
windows_feature, windows_registry_key, yumrepo,
zfsfs
MOST ARE FAIRLY
SELF
EXPLANATORY
return_stdout
describe command('cat /etc/resolv.conf') do
it { should return_stdout /8.8.8.8/ }
end
content
describe file('/etc/httpd/conf/httpd.conf') do
its(:content) { should match /ServerName www.example.jp/ }
end
MY BREAD AND
BUTTER
BE_RESOLVABLE
describe host('serverspec.org') do
it { should be_resolvable }
end
describe host('serverspec.org') do
it { should be_resolvable.by('hosts') }
end
describe host('serverspec.org') do
it { should be_resolvable.by('dns') }
end
BE_REACHABLE
describe host('target.example.jp') do
# ping
it { should be_reachable }
# tcp port 22
it { should be_reachable.with( :port => 22 ) }
# set protocol explicitly
it { should be_reachable.with( :port => 22, :proto => 'tcp' ) }
# udp port 53
it { should be_reachable.with( :port => 53, :proto => 'udp' ) }
# timeout setting (default is 5 seconds)
it { should be_reachable.with( :port => 22, :proto => 'tcp', :timeout => 1 ) }
end
FULL SPECS FOR A WEB SERVER
require 'spec_helper'
describe package('apache2') do
it { should be_installed }
end
describe service('apache2') do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
EXAMPLE:HTTPS://GITHUB.COM/JVOORHIS/
VAGRANT-SERVERSPEC
LIVE DEMO TIME:
SERVERSPEC!
OUR WORKFLOW:CHANGE IN PUPPET MADE =>
TESTED IN VAGRANT INSTANCE
CODE REVIEWED, PASSES CI AND MERGED
PUSHED TO INTEGRATION ENVIRONMENT
SERVERSPEC TESTS RUN ON INTEGRATION ENVIRONMENT
ANY ISSUES: FIX OR IF BIG ENOUGH, REVERT
CONTINUES DOWN THE PIPELINE TO PRODUCTION
SERVERSPEC:
PRETTY NEAT
BUT THERE'S ALSO LANGUAGE
SPECIFIC TOOLS!
TEST KITCHEN
▸ Uses serverspec as it's core
▸ It's basically helper wrappers to install chef
▸ And run the cookbooks given
▸ Used for cookbook acceptance testing
EXAMPLE:HTTPS://GITHUB.COM/OPSCODE-
COOKBOOKS/APT/
LIVE DEMO TIME:
TEST-KITCHEN!
BEAKER
▸ Again: serverspec as it's core
▸ But specs customised with Puppet references
▸ Specific rspec grammer around running manifests etc.
EXAMPLE:HTTPS://GITHUB.COM/PETEMS/PUPPET-
SWAP_FILE
require 'spec_helper_acceptance'
describe 'swap_file class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'swap_file' do
context 'ensure => present' do
it 'should work with no errors' do
pp = <<-EOS
class { 'swap_file': }
EOS
# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end
context 'custom parameters' do
it 'should work with no errors' do
pp = <<-EOS
class { 'swap_file':
swapfile => '/tmp/swapfile',
swapfilesize => '5 MB',
}
EOS
it 'should contain the given swapfile' do
shell('/sbin/swapon -s | grep /tmp/swapfile', :acceptable_exit_codes => [0])
shell('/sbin/swapon -s | grep 5116', :acceptable_exit_codes => [0])
end
end
end
end
I KNOW WHAT YOU MIGHT BE
THINKING...
Wait, whats the difference between this
and monitoring?
MONITORING
KEEP THE LIGHTS ON
▸ "Fix me now!" issues
▸ Dynamic changes - Things crashing, hard drives are full
ACCEPTANCE
"MY CHANGES DIDN'T BREAK ANYTHING"
▸ Smoke tests
▸ Human readable
▸ One-off for edge-cases
▸ Auditing
HOWEVER
USING SERVERSPEC AS MONITORING IS
POSSIBLE!
AND HAS SOME PRETTY SWEET BENEFITS
HTTP://WWW.SLIDESHARE.NET/M_RICHARDSON/SERVERSPEC-AND-SENSU-TESTING-AND-MONITORING-
COLLIDE
Q&A
LINKShttp://serverspec.org/
http://vincent.bernat.im/en/blog/2014-serverspec-test-
infrastructure.html
https://github.com/serverspec/serverspec
http://www.debian-administration.org/article/703/
A_brief_introduction_to_server-testing_with_serverspec
"ChefConf 2014: Gosuke Miyashita, "Serverspec: The Simplest
Server Testing Tool Ever" - http://www.youtube.com/watch?
v=6GvlHImeloo*

More Related Content

PPTX
OSDC2014: Testing Server Infrastructure with #serverspec
PDF
Compliance as Code
PPTX
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
PPTX
Infrastructure Automation with Chef & Ansible
PPTX
Testing Ansible Infrastructure With Serverspec
PPTX
Understand Chef
PDF
Chef Automate Workflow Demo
PPTX
Serverspec and Sensu - Testing and Monitoring collide
OSDC2014: Testing Server Infrastructure with #serverspec
Compliance as Code
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
Infrastructure Automation with Chef & Ansible
Testing Ansible Infrastructure With Serverspec
Understand Chef
Chef Automate Workflow Demo
Serverspec and Sensu - Testing and Monitoring collide

What's hot (19)

PPTX
London Community Summit 2016 - Fresh New Chef Stuff
PPTX
Go Faster with Ansible (PHP meetup)
PPTX
SAP TechEd 2013 session Tec118 managing your-environment
PPTX
DevOps, A brief introduction to Vagrant & Ansible
PPTX
Chef Workflow Demo
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
PDF
Ansible Introduction
PDF
Test-Driven Infrastructure with Chef
PDF
Infrastructure Automation with Chef
PPTX
How to Write Chef Cookbook
PDF
Ansible
PPTX
Hands on ansible
PPTX
Zero Code Multi-Cloud Automation with Ansible and Terraform
PDF
Automating Compliance with InSpec - AWS North Sydney
PDF
Ansible Case Studies
PDF
Testable Infrastructure with Chef, Test Kitchen, and Docker
PDF
Nike pop up habitat
PDF
Server Installation and Configuration with Chef
PDF
Learning chef
London Community Summit 2016 - Fresh New Chef Stuff
Go Faster with Ansible (PHP meetup)
SAP TechEd 2013 session Tec118 managing your-environment
DevOps, A brief introduction to Vagrant & Ansible
Chef Workflow Demo
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Ansible Introduction
Test-Driven Infrastructure with Chef
Infrastructure Automation with Chef
How to Write Chef Cookbook
Ansible
Hands on ansible
Zero Code Multi-Cloud Automation with Ansible and Terraform
Automating Compliance with InSpec - AWS North Sydney
Ansible Case Studies
Testable Infrastructure with Chef, Test Kitchen, and Docker
Nike pop up habitat
Server Installation and Configuration with Chef
Learning chef
Ad

Viewers also liked (16)

PDF
Little Puppet Tools To Make Your Life Better
PDF
Puppet module anti patterns
PDF
Lock it down
PDF
Hardening Your Config Management - Security and Attack Vectors in Config Mana...
PDF
Knee deep in the undef - Tales from refactoring old Puppet codebases
PDF
Compliance and auditing with Puppet
PPTX
Ansible presentation
PPTX
Evolución de los contenidos móviles
PDF
家庭醫藥箱(上)
PPTX
How world class companies optimize the digital experience
PDF
PPM and Governance Workshop
PPTX
Social Media Strategies - social3i - August 2010
PDF
Kellton Tech Profile - Consumer and Enterprise Web Applications
PPTX
Testowanie EDW czyli projekt piekło - Bartłomiej Nikiel
PPT
Экологические «экстерналии» в районе водосбора, Коста-Рика
PPS
週末輕鬆一下
Little Puppet Tools To Make Your Life Better
Puppet module anti patterns
Lock it down
Hardening Your Config Management - Security and Attack Vectors in Config Mana...
Knee deep in the undef - Tales from refactoring old Puppet codebases
Compliance and auditing with Puppet
Ansible presentation
Evolución de los contenidos móviles
家庭醫藥箱(上)
How world class companies optimize the digital experience
PPM and Governance Workshop
Social Media Strategies - social3i - August 2010
Kellton Tech Profile - Consumer and Enterprise Web Applications
Testowanie EDW czyli projekt piekło - Bartłomiej Nikiel
Экологические «экстерналии» в районе водосбора, Коста-Рика
週末輕鬆一下
Ad

Similar to Testing servers like software (20)

PPTX
Effective Testing with Ansible and InSpec
PDF
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
PDF
Testing programmable infrastructure
PDF
Automating AWS Compliance with InSpec
PPTX
Introduction to DevOps
PDF
Chef basics - write infrastructure as code
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
KEY
From Dev to DevOps - ApacheCON NA 2011
PDF
Chef - industrialize and automate your infrastructure
PPTX
Effective Testing with Ansible and InSpec
PDF
Melbourne Chef Meetup: Automating Azure Compliance with InSpec
PDF
Treat your servers like your Ruby App: Infrastructure as Code
PDF
From Dev to DevOps
PDF
Introduction To Continuous Compliance & Remediation
PDF
Refactoring Infrastructure Code
PDF
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
PPTX
What is Test Kitchen
PDF
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
PDF
Testing Programmable Infrastructure with Ruby
PPTX
Continuous Testing and New Tools for Automation - Presentation from StarWest ...
Effective Testing with Ansible and InSpec
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
Testing programmable infrastructure
Automating AWS Compliance with InSpec
Introduction to DevOps
Chef basics - write infrastructure as code
Introduction to Infrastructure as Code & Automation / Introduction to Chef
From Dev to DevOps - ApacheCON NA 2011
Chef - industrialize and automate your infrastructure
Effective Testing with Ansible and InSpec
Melbourne Chef Meetup: Automating Azure Compliance with InSpec
Treat your servers like your Ruby App: Infrastructure as Code
From Dev to DevOps
Introduction To Continuous Compliance & Remediation
Refactoring Infrastructure Code
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
What is Test Kitchen
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Testing Programmable Infrastructure with Ruby
Continuous Testing and New Tools for Automation - Presentation from StarWest ...

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
A Presentation on Artificial Intelligence
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
Modernizing your data center with Dell and AMD
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A Presentation on Artificial Intelligence
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction

Testing servers like software