Home >Technology >Ottawa Puppet User Group - Puppet Module Testing

Ottawa Puppet User Group - Puppet Module Testing

Date post:27-Jun-2015
Category:
View:84 times
Download:1 times
Share this document with a friend
Description:
A presentation delivered at the September 2014 meeting of the Ottawa Puppet User Group, discussing why you want to test your modules, types of testing, and tools available to help you do so.
Transcript:
  • 1. Puppet Module TestingBest practices to make your module awesome!Prepared By: Bill FraserSeptember 9th, 2014

2. 2014 PythianAbout Me Principal Consultant, EnterpriseInfrastructure Services Open source enthusiast DevOps, WebOps, SRE IT automation and configurationmanagement System, network and applicationmonitoring and performancetrending Cloud and virtualizationtechnologies 3. Why Test? Does the software do what it was designed to do? Are you confident code changes wont break existingfunctionality? Or introduce new bugs? Are your troubleshooting, repair, rework and / or redesigncosts minimal? Is your software used externally? Do you have name orbrand perception / reputation to uphold? Can other team members and contributors understand andsupport / maintain the code? 2014 Pythian 4. How (Not) To Test Where do you test? On a passive, standby server? On a test server? Locally, in a testing environment? 2014 Pythian What do you test? Deploy the software and look for errors? Follow a build / deployment checklist? Have a focus group use the software and file bugs? 5. 2014 PythianHow To TestSyntax / Style Tests to ensure the code is syntactically correct and / orconforms to style best practices for readability andmaintainabilityUnit Testing Tests that verify the functionality of a specific section of code(usually at the class level, can have multiple tests per class)Integration Testing Tests that verify the interfaces between components.Progressively larger groups of components are integratedand tested until the software works as a systemSystem Testing End-to-end testing, tests a completely integrated system toverify it meets its requirementsAcceptance Testing The system is delivered to the users for acceptance testing 6. 2014 PythianPuppet TestsSyntax / Style puppet parser, puppet-syntax, puppet-lintUnit Tests rspec-puppetIntegration Tests rspec-puppetSystem Tests beaker, beaker-rspecAcceptance Tests beaker, beaker-rspec 7. Puppet Parser You can interact directly with the Puppet parser from thecommand linepuppet parser validate [ manifest] [manifest ...] Validates Puppet DSL syntax without compiling a catalogor syncing any resources Returns: nothing, or the first syntax error encountered 2014 Pythian 8. Puppet Syntax Ruby gem puppet-syntax Syntax check of manifests, templates, and Hiera YAML Works with any version of Puppet >= 2.7 that provides the validate face Ruby >= 1.8 with erb from stdlib Add the following to your Rakefilerequire 'puppet-syntax/tasks/puppet-syntax' Provides syntax, syntax:hiera, syntax:manifests, andsyntax:templates Rake tasks 2014 Pythian 9. Puppet Lint Ruby gem puppet-lint Checks conformance of your manifest(s) with the PuppetStyle Guide Requires Ruby 1.8.7 or higher Can be run from command line or as a Rake task Add the following to your Rakefilerequire 'puppet-lint/tasks/puppet-lint' Also provided as a Rake task if usingpuppetlabs_spec_helper Individual checks can be disabled / ignored if desired 2014 Pythian 10. rspec-puppet Ruby gem rspec-puppet Allows you to write RSpec tests for your Puppet manifests Supports a number of matchers, including: compile contain_* with_*, without_* with, without that_requires, that_comes_before that_notifies, that_subscribes_to Rake tasks provided by puppetlabs_spec_helper 2014 Pythian 11. Beaker Ruby gems beaker and beaker-rspec System / acceptance testing harness with its own DSL Can provision, validate, test, clean up, and report Supports multiple hypervisors for provisioning, including: VMware (Fusion, vSphere, vCloud) Amazon EC2 Google Compute Engine Docker Vagrant Run via command line or as RSpec tests 2014 Pythian 12. Beaker (cont) RSpec tests rely on spec_helper_acceptance.rb Systems Under Test (SUT) referred to as nodesets SUT configuration in YAML in spec/acceptance/nodesets/ Can perform the following actions on SUTs: Install, upgrade Puppet Check for, install or upgrade packages Copy files in and out, create files, run scripts Use Puppet, Facter and Hiera Apply manifests 2014 Pythian 13. puppetlabs_spec_helper A project (Ruby gem) that intends to provide: A bridge between external projects and multipleversions of Puppet, to simplify testing A common set of Rake tasks and convenience classes /methods such as common RSpec matchers For module testing, add the following to spec_helper.rbrequire 'puppetlabs_spec_helper/module_spec_helper' And add the following to your Rakefilerequire 'puppetlabs_spec_helper/rake_tasks' 2014 Pythian 14. Setting Up The Environment You can do the following: Add puppet-lint, puppet-syntax, rspec-puppet andpuppetlabs_spec_helper to your Gemfile Run bundle install Add the following to your Rakefilerequire 'puppetlabs_spec_helper/rake_tasks'require 'puppet-lint/tasks/puppet-lint'require 'puppet-syntax/tasks/puppet-syntax' Create spec/spec_helper.rb Et cetera, or you can make life easy on yourself ... 2014 Pythian 15. puppet-module-skeleton Use Gareth Rushgroves puppet-module-skeleton All you need to do:git clone https://github.com/garethr/puppet-module-skeletoncd puppet-module-skeletonbash install.sh Integrates with Puppet Module Tool, so you can do thefollowing:puppet module generate user-modulecd user-modulebundle installbundle exec rake -T Provides all of the Rake tasks mentioned in previous slides 2014 Pythian 16. References1. https://docs.puppetlabs.com/references/latest/man/parser.html2. https://github.com/gds-operations/puppet-syntax3. http://puppet-lint.com/4. http://rspec-puppet.com/5. https://github.com/puppetlabs/beaker6. https://github.com/puppetlabs/beaker-rspec7. https://docs.puppetlabs.com/guides/style_guide.html8. https://github.com/puppetlabs/puppetlabs_spec_helper9. https://github.com/garethr/puppet-module-skeleton 2014 Pythian 17. Thank You - Q&ATo contact [email protected], [email protected]+1 (877) PYTHIAN 2014 PythianTo follow ushttp://www.pythian.com/[email protected], @wmjfraserhttp://www.linkedin.com/company/pythian,http://www.linkedin.com/in/wmjfraser

Popular Tags:

Click here to load reader

Embed Size (px)
Recommended