SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
;
Testing your puppet codeTesting your puppet code
Julien PivottoJulien Pivotto
Libre Software Meeting 2013Libre Software Meeting 2013
July 15, 2013July 15, 2013
;
Introduction
Testing tools
Jenkins
Conclusion
1 Introduction
Automation
Vagrant
Puppet in a large scale
Puppet code
2 Testing tools
Style and linting
Catalogs
rspec-puppet
3 Jenkins
4 Conclusion
Homework
Conclusion
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Julien PivottoJulien Pivotto
• sysadmin @ inuitssysadmin @ inuits
• open-source defender for 7+ yearsopen-source defender for 7+ years
• devops believerdevops believer
• @roidelapluie on twitter/github@roidelapluie on twitter/github
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Infrastructure as Code
• Keep your environments under SCMKeep your environments under SCM
• Overview of complete environmentsOverview of complete environments
• Reduce the deployment timeReduce the deployment time
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Keep all environments the same
http://www.flickr.com/photos/bobvietnam/4828291896/
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Packaging with FPM
• Ruby gemRuby gem
• package a directory (and much more)package a directory (and much more)
• Support .deb, .rpmSupport .deb, .rpm
• Package the code with several prefixesPackage the code with several prefixes
• /etc/puppet/environments/infradev/etc/puppet/environments/infradev
• /etc/puppet/environments/uat/etc/puppet/environments/uat
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Vagrant
• Create virtual machinesCreate virtual machines
• Provision themProvision them
• Destroy & recreateDestroy & recreate
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Vagrant
• Chef, scripts, puppet, . . .Chef, scripts, puppet, . . .
• Backend: Virtualbox, KVM, . . .Backend: Virtualbox, KVM, . . .
• A lot of baseboxes availableA lot of baseboxes available
• http://vagrantup.comhttp://vagrantup.com
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Vagrant
• Local testingLocal testing
• The same environment as the targetThe same environment as the target
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Puppet environments
• Multiple environmentsMultiple environments
• The same tree for all the environmentsThe same tree for all the environments
• Pushing changes to UAT/prod on-demandPushing changes to UAT/prod on-demand
• Small changes vs big releasesSmall changes vs big releases
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Hiera
• Storing the data in Hiera(-gpg)Storing the data in Hiera(-gpg)
• Usernames, password, IP addressesUsernames, password, IP addresses
• Hiera is made to be structuredHiera is made to be structured
• Using one hiera repo for all the environmentsUsing one hiera repo for all the environments
• Using Hiera in your manifests, not in your modulesUsing Hiera in your manifests, not in your modules
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Hiera tree
• %{environment}/%{hostname}%{environment}/%{hostname}
• %{environment}/common%{environment}/common
• infradev/www45.yamlinfradev/www45.yaml
• infradev/common.yamlinfradev/common.yaml
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Keeping clean puppet modules
http://www.flickr.com/photos/aurelie_solenne/8340968061/
• Make them readableMake them readable
• Make them reusable and sharableMake them reusable and sharable
• Don’t puppetize everythingDon’t puppetize everything
• User generated content is not puppetizedUser generated content is not puppetized
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Use the right structure for your modules
• Package, config, servicePackage, config, service
• module::package, module::config, module::servicemodule::package, module::config, module::service
• Parameterized classesParameterized classes
http://www.slideshare.net/PuppetLabs/modern-module-development-ken-barber-2012-edinburgh-
puppet-camp
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Distribution-agnostic puppet modules
• You don’t have to support all the distrosYou don’t have to support all the distros
• Adding support for another distro should be easyAdding support for another distro should be easy
$config_dir = $configroot ? {
undef => $::operatingsystem ? {
/Debian|Ubuntu/ => ’/etc/apache2’,
/CentOS|RedHat/ => ’/etc/httpd’,
default => ’/etc/httpd’,
},
default => $configroot,
}
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Automation
Vagrant
Puppet in a large scale
Puppet code
Puppet function
• The fail function prevents catalog to be appliedThe fail function prevents catalog to be applied
• The notify function prints a warningThe notify function prints a warning
if (!$leftsubnet) and (!$leftsubnets) {
fail(’$leftsubnets and $leftsubnet both empty’)
}
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
Puppet parser
• Included in puppetIncluded in puppet
• Validating the syntaxValidating the syntax
• puppet parser validate init.pppuppet parser validate init.pp
• find . -name ’*.pp’ -exec puppet parser validate
+ ;
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
Puppet lint
http://www.flickr.com/photos/voyages-provence/8127668094/
• Follow the puppet style guideFollow the puppet style guide
• Two-space soft tabTwo-space soft tab
• align fat comma arrows (=>) within blocks of attributesalign fat comma arrows (=>) within blocks of attributes
• http://docs.puppetlabs.com/guides/style_guide.htmlhttp://docs.puppetlabs.com/guides/style_guide.html
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
Cucumber puppet
• Write scenariosWrite scenarios
• Easy to read (full sentences)Easy to read (full sentences)
• Use your manifestsUse your manifests
• Need some tricks to work with Puppet 3Need some tricks to work with Puppet 3
• DiscontinuedDiscontinued
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
Cucumber example
Cucumber
Feature: General catalog policy
In order to ensure applicability of a host’s catalog
As a manifest developer
I want all catalogs to obey some general rules
Scenario Outline: Compile and verify catalog
Given a node specified by "features/yaml/<hostname>."
When I compile its catalog
Then compilation should succeed
And all resource dependencies should resolve
Examples:
| hostname |
| localhost |
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
rspec-puppet
• Check what is the behaviour of puppetCheck what is the behaviour of puppet
• Separate tests per modulesSeparate tests per modules
• Add context, facts, . . .Add context, facts, . . .
• Test custom functions, hosts, manifests, . . .Test custom functions, hosts, manifests, . . .
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
rspec-puppet
Start with rspec puppet
gem install rspec-puppet
gem install puppet
cd my-module
rspec-puppet-init
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
rspec-puppet
spec/defines/connection_spec.rb
require ’spec_helper’
describe ’openswan::connection’ do
describe ’should require rightsubnet or rightsubnets’ do
let(:title) { ’foobar’ }
let (:params) { {
:ike => ’aes256-sha1;modp1024’,
:esp => ’aes256-sha1;modp1024’,
:leftsubnet => ’8.8.5.5’,
:right => ’84.54.105.5’,
:left => ’68.65.98.6’,
:foreignip => ’45.25.5.5’,
:localtestip => ’82.8.8.8’, } }
it do
expect {
should contain_file("/etc/ipsec.d/foobar.conf")
}.to raise_error(Puppet::Error, /$rightsubnets and $rightsubnet cannot be both empty/)
end
end
end
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
rspec-puppet
Second example
require ’spec_helper’
describe ’apache’, :type => :class do
let (:facts) { {
:operatingsystem => ’CentOS’,
:osfamily => ’RedHat’,
} }
describe ’without parameters’ do
it { should create_class(’apache’) }
it { should include_class(’apache::service’) }
it { should contain_apache__listen(’80’) }
it { should contain_apache__namevhost(’80’) }
end
end
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Style and linting
Catalogs
rspec-puppet
rspec-puppet
• should, should_notshould, should_not
• should contain_packageshould contain_package
• contain_foo__bar(’baz’) (for foo::bar)contain_foo__bar(’baz’) (for foo::bar)
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Integration with jenkins
• Pulling, testing and deploymentsPulling, testing and deployments
• Push-Test-Package-DeployPush-Test-Package-Deploy
• Continuous integrationContinuous integration
• Continuous deliveryContinuous delivery
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Jenkins pipelines
• Build pipelinesBuild pipelines
• Overview of what happensOverview of what happens
• Getting notified about what failedGetting notified about what failed
• Promoted build pluginPromoted build plugin
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Jenkins pipelines
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Advantages of CI
• You trust your codeYou trust your code
• ReproducabilityReproducability
• You get metrics: number of warning, . . .You get metrics: number of warning, . . .
• You have a backlogYou have a backlog
• It is easy!It is easy!
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Promotions
• Provides buttons you can clickProvides buttons you can click
• Trigger actionsTrigger actions
• deploy to other environmentsdeploy to other environments
• Get a mail with the changesGet a mail with the changes
• Have a log of who deployedHave a log of who deployed
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Promotions
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Homework
Conclusion
Homework
• Integrating tests with git hooksIntegrating tests with git hooks
• Integrating tests with VIIntegrating tests with VI
• github.com/philandstuff/fizzgiggithub.com/philandstuff/fizzgig
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Homework
Conclusion
Conclusion
• Use nice & simple Puppet modulesUse nice & simple Puppet modules
• Continuous integrationContinuous integration
• Multiple environmentsMultiple environments
• Readability & reusabilityReadability & reusability
• Tools exist and work togetherTools exist and work together
Julien Pivotto Testing your puppet code
;
Introduction
Testing tools
Jenkins
Conclusion
Homework
Conclusion
Contact
Julien PivottoJulien Pivotto
julien@inuits.eujulien@inuits.eu
@roidelapluie@roidelapluie
INUITS bvbaINUITS bvba
Duboisstraat 50Duboisstraat 50
2060 Antwerp2060 Antwerp
BelgiumBelgium
+32 473 441 636+32 473 441 636
https://inuits.euhttps://inuits.eu
Julien Pivotto Testing your puppet code

Contenu connexe

Tendances

Package Management and Chef - ChefConf 2015
Package Management and Chef - ChefConf 2015Package Management and Chef - ChefConf 2015
Package Management and Chef - ChefConf 2015
Chef
 
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
Aaron Meurer
 

Tendances (20)

Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
 
Getting the maximum out of systemd
Getting the maximum out of systemdGetting the maximum out of systemd
Getting the maximum out of systemd
 
Test Driven Development with Puppet
Test Driven Development with Puppet Test Driven Development with Puppet
Test Driven Development with Puppet
 
Package Management and Chef - ChefConf 2015
Package Management and Chef - ChefConf 2015Package Management and Chef - ChefConf 2015
Package Management and Chef - ChefConf 2015
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
 
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
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
 
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, PuppetPuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
 
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
 
Jenkins Shared Libraries
Jenkins Shared LibrariesJenkins Shared Libraries
Jenkins Shared Libraries
 
Cooking the Cake for Nuget packages
Cooking the Cake for Nuget packagesCooking the Cake for Nuget packages
Cooking the Cake for Nuget packages
 
2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with Django
 
State of the Jenkins Automation
State of the Jenkins AutomationState of the Jenkins Automation
State of the Jenkins Automation
 
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
Conda: A Cross-Platform Package Manager for Any Binary Distribution (SciPy 2014)
 
Continuous Integration with Puppet
Continuous Integration with PuppetContinuous Integration with Puppet
Continuous Integration with Puppet
 

En vedette

Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Bamdad Dashtban
 

En vedette (7)

Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
 
PuppetConf 2016: Continuous Delivery and DevOps with Jenkins and Puppet Enter...
PuppetConf 2016: Continuous Delivery and DevOps with Jenkins and Puppet Enter...PuppetConf 2016: Continuous Delivery and DevOps with Jenkins and Puppet Enter...
PuppetConf 2016: Continuous Delivery and DevOps with Jenkins and Puppet Enter...
 
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
 
Continuous Development with Jenkins - Stephen Connolly at PuppetCamp Dublin '12
Continuous Development with Jenkins - Stephen Connolly at PuppetCamp Dublin '12Continuous Development with Jenkins - Stephen Connolly at PuppetCamp Dublin '12
Continuous Development with Jenkins - Stephen Connolly at PuppetCamp Dublin '12
 
Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms
 
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
 

Similaire à Testing your puppet code

20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting
Kazuhiro Oinuma
 

Similaire à Testing your puppet code (20)

Practical Pig and PigUnit (Michael Noll, Verisign)
Practical Pig and PigUnit (Michael Noll, Verisign)Practical Pig and PigUnit (Michael Noll, Verisign)
Practical Pig and PigUnit (Michael Noll, Verisign)
 
Repositories as Code
Repositories as CodeRepositories as Code
Repositories as Code
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at Scale
 
Complete python toolbox for modern developers
Complete python toolbox for modern developersComplete python toolbox for modern developers
Complete python toolbox for modern developers
 
20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
 
Automating MySQL operations with Puppet
Automating MySQL operations with PuppetAutomating MySQL operations with Puppet
Automating MySQL operations with Puppet
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development Workflow
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Fluo CICD OpenStack Summit
Fluo CICD OpenStack SummitFluo CICD OpenStack Summit
Fluo CICD OpenStack Summit
 
Organize your chickens: NuGet for the enterprise
Organize your chickens: NuGet for the enterpriseOrganize your chickens: NuGet for the enterprise
Organize your chickens: NuGet for the enterprise
 
Continuous Delivery of (y)our infrastructure.
Continuous Delivery of (y)our infrastructure.Continuous Delivery of (y)our infrastructure.
Continuous Delivery of (y)our infrastructure.
 
Smarter deployments with octopus deploy
Smarter deployments with octopus deploySmarter deployments with octopus deploy
Smarter deployments with octopus deploy
 
Testing your infallibleness
Testing your infalliblenessTesting your infallibleness
Testing your infallibleness
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Using Vagrant, Puppet, Testing & Hadoop
Using Vagrant, Puppet, Testing & HadoopUsing Vagrant, Puppet, Testing & Hadoop
Using Vagrant, Puppet, Testing & Hadoop
 
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
 
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
 

Plus de Julien Pivotto

Plus de Julien Pivotto (20)

The O11y Toolkit
The O11y ToolkitThe O11y Toolkit
The O11y Toolkit
 
What's New in Prometheus and Its Ecosystem
What's New in Prometheus and Its EcosystemWhat's New in Prometheus and Its Ecosystem
What's New in Prometheus and Its Ecosystem
 
Prometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is comingPrometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is coming
 
What's new in Prometheus?
What's new in Prometheus?What's new in Prometheus?
What's new in Prometheus?
 
Introduction to Grafana Loki
Introduction to Grafana LokiIntroduction to Grafana Loki
Introduction to Grafana Loki
 
Why you should revisit mgmt
Why you should revisit mgmtWhy you should revisit mgmt
Why you should revisit mgmt
 
Observing the HashiCorp Ecosystem From Prometheus
Observing the HashiCorp Ecosystem From PrometheusObserving the HashiCorp Ecosystem From Prometheus
Observing the HashiCorp Ecosystem From Prometheus
 
Monitoring in a fast-changing world with Prometheus
Monitoring in a fast-changing world with PrometheusMonitoring in a fast-changing world with Prometheus
Monitoring in a fast-changing world with Prometheus
 
5 tips for Prometheus Service Discovery
5 tips for Prometheus Service Discovery5 tips for Prometheus Service Discovery
5 tips for Prometheus Service Discovery
 
Prometheus and TLS - an Introduction
Prometheus and TLS - an IntroductionPrometheus and TLS - an Introduction
Prometheus and TLS - an Introduction
 
Powerful graphs in Grafana
Powerful graphs in GrafanaPowerful graphs in Grafana
Powerful graphs in Grafana
 
YAML Magic
YAML MagicYAML Magic
YAML Magic
 
HAProxy as Egress Controller
HAProxy as Egress ControllerHAProxy as Egress Controller
HAProxy as Egress Controller
 
Improved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and AlertmanagerImproved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and Alertmanager
 
SIngle Sign On with Keycloak
SIngle Sign On with KeycloakSIngle Sign On with Keycloak
SIngle Sign On with Keycloak
 
Monitoring as an entry point for collaboration
Monitoring as an entry point for collaborationMonitoring as an entry point for collaboration
Monitoring as an entry point for collaboration
 
Incident Resolution as Code
Incident Resolution as CodeIncident Resolution as Code
Incident Resolution as Code
 
Monitor your CentOS stack with Prometheus
Monitor your CentOS stack with PrometheusMonitor your CentOS stack with Prometheus
Monitor your CentOS stack with Prometheus
 
Monitor your CentOS stack with Prometheus
Monitor your CentOS stack with PrometheusMonitor your CentOS stack with Prometheus
Monitor your CentOS stack with Prometheus
 
An introduction to Ansible
An introduction to AnsibleAn introduction to Ansible
An introduction to Ansible
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Testing your puppet code

  • 1. ; Testing your puppet codeTesting your puppet code Julien PivottoJulien Pivotto Libre Software Meeting 2013Libre Software Meeting 2013 July 15, 2013July 15, 2013
  • 2. ; Introduction Testing tools Jenkins Conclusion 1 Introduction Automation Vagrant Puppet in a large scale Puppet code 2 Testing tools Style and linting Catalogs rspec-puppet 3 Jenkins 4 Conclusion Homework Conclusion Julien Pivotto Testing your puppet code
  • 3. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Julien PivottoJulien Pivotto • sysadmin @ inuitssysadmin @ inuits • open-source defender for 7+ yearsopen-source defender for 7+ years • devops believerdevops believer • @roidelapluie on twitter/github@roidelapluie on twitter/github Julien Pivotto Testing your puppet code
  • 4. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Infrastructure as Code • Keep your environments under SCMKeep your environments under SCM • Overview of complete environmentsOverview of complete environments • Reduce the deployment timeReduce the deployment time Julien Pivotto Testing your puppet code
  • 5. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Keep all environments the same http://www.flickr.com/photos/bobvietnam/4828291896/ Julien Pivotto Testing your puppet code
  • 6. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Packaging with FPM • Ruby gemRuby gem • package a directory (and much more)package a directory (and much more) • Support .deb, .rpmSupport .deb, .rpm • Package the code with several prefixesPackage the code with several prefixes • /etc/puppet/environments/infradev/etc/puppet/environments/infradev • /etc/puppet/environments/uat/etc/puppet/environments/uat Julien Pivotto Testing your puppet code
  • 7. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Vagrant • Create virtual machinesCreate virtual machines • Provision themProvision them • Destroy & recreateDestroy & recreate Julien Pivotto Testing your puppet code
  • 8. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Vagrant • Chef, scripts, puppet, . . .Chef, scripts, puppet, . . . • Backend: Virtualbox, KVM, . . .Backend: Virtualbox, KVM, . . . • A lot of baseboxes availableA lot of baseboxes available • http://vagrantup.comhttp://vagrantup.com Julien Pivotto Testing your puppet code
  • 9. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Vagrant • Local testingLocal testing • The same environment as the targetThe same environment as the target Julien Pivotto Testing your puppet code
  • 10. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Puppet environments • Multiple environmentsMultiple environments • The same tree for all the environmentsThe same tree for all the environments • Pushing changes to UAT/prod on-demandPushing changes to UAT/prod on-demand • Small changes vs big releasesSmall changes vs big releases Julien Pivotto Testing your puppet code
  • 11. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Hiera • Storing the data in Hiera(-gpg)Storing the data in Hiera(-gpg) • Usernames, password, IP addressesUsernames, password, IP addresses • Hiera is made to be structuredHiera is made to be structured • Using one hiera repo for all the environmentsUsing one hiera repo for all the environments • Using Hiera in your manifests, not in your modulesUsing Hiera in your manifests, not in your modules Julien Pivotto Testing your puppet code
  • 12. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Hiera tree • %{environment}/%{hostname}%{environment}/%{hostname} • %{environment}/common%{environment}/common • infradev/www45.yamlinfradev/www45.yaml • infradev/common.yamlinfradev/common.yaml Julien Pivotto Testing your puppet code
  • 13. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Keeping clean puppet modules http://www.flickr.com/photos/aurelie_solenne/8340968061/ • Make them readableMake them readable • Make them reusable and sharableMake them reusable and sharable • Don’t puppetize everythingDon’t puppetize everything • User generated content is not puppetizedUser generated content is not puppetized Julien Pivotto Testing your puppet code
  • 14. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Use the right structure for your modules • Package, config, servicePackage, config, service • module::package, module::config, module::servicemodule::package, module::config, module::service • Parameterized classesParameterized classes http://www.slideshare.net/PuppetLabs/modern-module-development-ken-barber-2012-edinburgh- puppet-camp Julien Pivotto Testing your puppet code
  • 15. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Distribution-agnostic puppet modules • You don’t have to support all the distrosYou don’t have to support all the distros • Adding support for another distro should be easyAdding support for another distro should be easy $config_dir = $configroot ? { undef => $::operatingsystem ? { /Debian|Ubuntu/ => ’/etc/apache2’, /CentOS|RedHat/ => ’/etc/httpd’, default => ’/etc/httpd’, }, default => $configroot, } Julien Pivotto Testing your puppet code
  • 16. ; Introduction Testing tools Jenkins Conclusion Automation Vagrant Puppet in a large scale Puppet code Puppet function • The fail function prevents catalog to be appliedThe fail function prevents catalog to be applied • The notify function prints a warningThe notify function prints a warning if (!$leftsubnet) and (!$leftsubnets) { fail(’$leftsubnets and $leftsubnet both empty’) } Julien Pivotto Testing your puppet code
  • 17. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet Puppet parser • Included in puppetIncluded in puppet • Validating the syntaxValidating the syntax • puppet parser validate init.pppuppet parser validate init.pp • find . -name ’*.pp’ -exec puppet parser validate + ; Julien Pivotto Testing your puppet code
  • 18. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet Puppet lint http://www.flickr.com/photos/voyages-provence/8127668094/ • Follow the puppet style guideFollow the puppet style guide • Two-space soft tabTwo-space soft tab • align fat comma arrows (=>) within blocks of attributesalign fat comma arrows (=>) within blocks of attributes • http://docs.puppetlabs.com/guides/style_guide.htmlhttp://docs.puppetlabs.com/guides/style_guide.html Julien Pivotto Testing your puppet code
  • 19. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet Cucumber puppet • Write scenariosWrite scenarios • Easy to read (full sentences)Easy to read (full sentences) • Use your manifestsUse your manifests • Need some tricks to work with Puppet 3Need some tricks to work with Puppet 3 • DiscontinuedDiscontinued Julien Pivotto Testing your puppet code
  • 20. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet Cucumber example Cucumber Feature: General catalog policy In order to ensure applicability of a host’s catalog As a manifest developer I want all catalogs to obey some general rules Scenario Outline: Compile and verify catalog Given a node specified by "features/yaml/<hostname>." When I compile its catalog Then compilation should succeed And all resource dependencies should resolve Examples: | hostname | | localhost | Julien Pivotto Testing your puppet code
  • 21. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet rspec-puppet • Check what is the behaviour of puppetCheck what is the behaviour of puppet • Separate tests per modulesSeparate tests per modules • Add context, facts, . . .Add context, facts, . . . • Test custom functions, hosts, manifests, . . .Test custom functions, hosts, manifests, . . . Julien Pivotto Testing your puppet code
  • 22. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet rspec-puppet Start with rspec puppet gem install rspec-puppet gem install puppet cd my-module rspec-puppet-init Julien Pivotto Testing your puppet code
  • 23. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet rspec-puppet spec/defines/connection_spec.rb require ’spec_helper’ describe ’openswan::connection’ do describe ’should require rightsubnet or rightsubnets’ do let(:title) { ’foobar’ } let (:params) { { :ike => ’aes256-sha1;modp1024’, :esp => ’aes256-sha1;modp1024’, :leftsubnet => ’8.8.5.5’, :right => ’84.54.105.5’, :left => ’68.65.98.6’, :foreignip => ’45.25.5.5’, :localtestip => ’82.8.8.8’, } } it do expect { should contain_file("/etc/ipsec.d/foobar.conf") }.to raise_error(Puppet::Error, /$rightsubnets and $rightsubnet cannot be both empty/) end end end Julien Pivotto Testing your puppet code
  • 24. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet rspec-puppet Second example require ’spec_helper’ describe ’apache’, :type => :class do let (:facts) { { :operatingsystem => ’CentOS’, :osfamily => ’RedHat’, } } describe ’without parameters’ do it { should create_class(’apache’) } it { should include_class(’apache::service’) } it { should contain_apache__listen(’80’) } it { should contain_apache__namevhost(’80’) } end end Julien Pivotto Testing your puppet code
  • 25. ; Introduction Testing tools Jenkins Conclusion Style and linting Catalogs rspec-puppet rspec-puppet • should, should_notshould, should_not • should contain_packageshould contain_package • contain_foo__bar(’baz’) (for foo::bar)contain_foo__bar(’baz’) (for foo::bar) Julien Pivotto Testing your puppet code
  • 26. ; Introduction Testing tools Jenkins Conclusion Integration with jenkins • Pulling, testing and deploymentsPulling, testing and deployments • Push-Test-Package-DeployPush-Test-Package-Deploy • Continuous integrationContinuous integration • Continuous deliveryContinuous delivery Julien Pivotto Testing your puppet code
  • 27. ; Introduction Testing tools Jenkins Conclusion Jenkins pipelines • Build pipelinesBuild pipelines • Overview of what happensOverview of what happens • Getting notified about what failedGetting notified about what failed • Promoted build pluginPromoted build plugin Julien Pivotto Testing your puppet code
  • 29. ; Introduction Testing tools Jenkins Conclusion Advantages of CI • You trust your codeYou trust your code • ReproducabilityReproducability • You get metrics: number of warning, . . .You get metrics: number of warning, . . . • You have a backlogYou have a backlog • It is easy!It is easy! Julien Pivotto Testing your puppet code
  • 30. ; Introduction Testing tools Jenkins Conclusion Promotions • Provides buttons you can clickProvides buttons you can click • Trigger actionsTrigger actions • deploy to other environmentsdeploy to other environments • Get a mail with the changesGet a mail with the changes • Have a log of who deployedHave a log of who deployed Julien Pivotto Testing your puppet code
  • 32. ; Introduction Testing tools Jenkins Conclusion Homework Conclusion Homework • Integrating tests with git hooksIntegrating tests with git hooks • Integrating tests with VIIntegrating tests with VI • github.com/philandstuff/fizzgiggithub.com/philandstuff/fizzgig Julien Pivotto Testing your puppet code
  • 33. ; Introduction Testing tools Jenkins Conclusion Homework Conclusion Conclusion • Use nice & simple Puppet modulesUse nice & simple Puppet modules • Continuous integrationContinuous integration • Multiple environmentsMultiple environments • Readability & reusabilityReadability & reusability • Tools exist and work togetherTools exist and work together Julien Pivotto Testing your puppet code
  • 34. ; Introduction Testing tools Jenkins Conclusion Homework Conclusion Contact Julien PivottoJulien Pivotto julien@inuits.eujulien@inuits.eu @roidelapluie@roidelapluie INUITS bvbaINUITS bvba Duboisstraat 50Duboisstraat 50 2060 Antwerp2060 Antwerp BelgiumBelgium +32 473 441 636+32 473 441 636 https://inuits.euhttps://inuits.eu Julien Pivotto Testing your puppet code