DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Testing Puppet Modules

Testing Puppet Modules

Carlos Sanchez user avatar by
Carlos Sanchez
·
Jan. 30, 13 · Interview
Like (0)
Save
Tweet
Share
3.77K Views

Join the DZone community and get the full member experience.

Join For Free
there are several steps depending on how much involved the tests are, what parts are tested and, of course, how long it takes to run the tests.

for unit testing we use rspec puppet , and we can check that our manifests and modules compile and contain the expected values. it can be used to test that specific types, classes or definitions are in the compiled catalog and that the parameters math the expectations.

later on we can do some integration testing starting a new vm with vagrant and checking that there are no errors in the provisioning, as well as checking that some conditions are met.

for rspec-puppet, puppetlabs has created a project called puppetlabs_spec_helper that let’s us avoid writing a bunch of boilerplate. a missing point though is that it only allows to use modules for testing from git. if you’re already using librarian-puppet (and you should!) you can easily use the same puppetfile for deploying modules and to test them. doing otherwise sounds like a bit of useless testing, you could end with different versions in different development machines, ci server, puppet master,… so just add a call to librarian puppet in your rakefile to populate the rspec-puppet fixtures before running the specs.

unfortunately rspec-puppet doesn’t work with puppet 3.0.x and  at least puppet 3.1.0-rc1 is required. it was a bit of a setback when we moved to puppet 3 and started using hiera , which is proving to be very useful to have simpler manifests and external data injected for our maestro installations with puppet from scratch.

you can also use the same puppetfile to start vagrant boxes with the exact same version of the modules. we are using cucumber and aruba to execute vagrant, provision the vm with puppet and check several things, like open ports, services up,… but that’s a different story :-)

example

in this puppet-for-java-devs project you will find the bits that showcase all these tools integrated. it includes definition of a 3-tier system with puppet definitions for a postgresql database, tomcat nodes with a war installed and apache nodes fronting them.

install all required gems

bundle install

install all puppet modules with puppet librarian

librarian-puppet install

run the specs with puppet-rspec

bundle exec rake

start all the vms with vagrant

vagrant up

rakefile

require 'bundler'
bundler.require(:rake)
require 'rake/clean'




require 'puppetlabs_spec_helper/rake_tasks'




clean.include('modules', 'spec/fixtures/', 'doc')
clobber.include('.tmp', '.librarian')




task :librarian_spec_prep do
 sh "librarian-puppet install"
end
task :spec_prep => :librarian_spec_prep




task :default => [:spec]

puppetfile for librarian-puppet

forge 'http://forge.puppetlabs.com'




mod 'puppetlabs/java', '0.1.6'
mod 'puppetlabs/apache', '0.4.0'
mod 'inkling/postgresql', '0.2.0'
mod 'puppetlabs/firewall', '0.0.4'
mod 'tomcat', :git => 'https://github.com/carlossg/puppet-tomcat.git', :ref => 'centos'
mod 'maestrodev/maven', '1.x'
mod 'stahnma/epel', '0.0.2'
mod 'maestrodev/avahi', '1.x'
mod 'other', :path => 'mymodules/other'

tomcat_spec.rb with rspec-puppet

require 'spec_helper'




describe 'tomcat1.acme.com' do
  let(:facts) { {:osfamily => 'redhat', :operatingsystem => 'centos', :operatingsystemrelease => 6.3} }




  it { should contain_class('java').with_distribution /openjdk/ }




  it "configure webapp" do
    should contain_maven('/srv/tomcat/appfuse/webapps/root.war')
    should contain_maven('/srv/tomcat/appfuse/webapps/root/web-inf/lib/postgresql-9.1-901.jdbc4.jar')
  end
end

vagrantfile

vagrant::config.run do |config|
  config.vm.box = "centos-6.3-x86_64-minimal"
  config.vm.box_url = "https://dl.dropbox.com/u/7225008/vagrant/centos-6.3-x86_64-minimal.box"




  config.vm.customize ["modifyvm", :id, "--rtcuseutc", "on"] # use utc clock https://github.com/mitchellh/vagrant/issues/912




  # db server
  config.vm.define :db do |config|
    config.vm.host_name = "db.acme.local"
    config.vm.customize ["modifyvm", :id, "--name", "db"] # name for virtualbox gui
    config.vm.forward_port 5432, 5432
    config.vm.network :hostonly, "192.168.33.10"
    config.vm.provision :puppet do |puppet|
      puppet.module_path = "modules"
      puppet.manifest_file = "site.pp"
    end
  end




  # tomcat server
  config.vm.define :tomcat1 do |config|
    config.vm.host_name = "tomcat1.acme.local"
    config.vm.customize ["modifyvm", :id, "--name", "tomcat1"] # name for virtualbox gui
    config.vm.forward_port 8080, 8081
    config.vm.network :hostonly, "192.168.33.11"
    config.vm.provision :puppet do |puppet|
      puppet.module_path = "modules"
      puppet.manifest_file = "site.pp"
    end
  end




  # web server
  config.vm.define :www do |config|
    config.vm.host_name = "www.acme.local"
    config.vm.customize ["modifyvm", :id, "--name", "www"] # name for virtualbox gui
    config.vm.forward_port 80, 8080
    config.vm.network :hostonly, "192.168.33.12"
    config.vm.provision :puppet do |puppet|
      puppet.module_path = "modules"
      puppet.manifest_file = "site.pp"
    end
  end




end

unit test

Published at DZone with permission of Carlos Sanchez, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • PostgreSQL: Bulk Loading Data With Node.js and Sequelize
  • How Do the Docker Client and Docker Servers Work?
  • A Real-Time Supply Chain Control Tower Powered by Kafka
  • Choosing the Best Cloud Provider for Hosting DevOps Tools

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: