Unit Tests Are Not Enough
Unit tests check the catalog. They do not install a real package or start a real service. Acceptance tests run your code on a real (or container) operating system and check the actual result: is the port open? does the service answer? does a second run change nothing?
| Test level | Speed | Proves |
| Lint and validate | Seconds | Syntax and style |
| Unit (rspec-puppet) | Seconds to minutes | Catalog logic, parameters, relationships |
| Acceptance (Litmus) | Minutes | Real installation, idempotence, services, ports |
| Pre-production environment | Minutes to hours | Interaction with real data, network, load balancers |
Puppet Litmus
Litmus is the current acceptance test framework from the Puppet module tooling. It works in small, separate steps so you can keep a test machine and repeat tests quickly.
bash
cd mymodule
pdk bundle install
# 1. Create test machines (Docker containers here)
pdk bundle exec rake 'litmus:provision[docker, litmusimage/rockylinux:9]'
pdk bundle exec rake 'litmus:provision[docker, litmusimage/ubuntu:22.04]'
# Or a list of platforms from a file
pdk bundle exec rake 'litmus:provision_list[default]'
# 2. Install the Puppet agent on them
pdk bundle exec rake 'litmus:install_agent[puppet8]'
# 3. Install your module (builds it and copies it) and its dependencies
pdk bundle exec rake litmus:install_module
# 4. Run the acceptance tests
pdk bundle exec rake litmus:acceptance:parallel
# 5. Clean up
pdk bundle exec rake litmus:tear_dow
Provisioners: Litmus supports Docker, Vagrant, and cloud providers through plugins. Docker is best for CI because it is fast and cheap. Use a Vagrant or cloud VM for things containers cannot do well, such as systemd services, kernel settings or reboots.
An Acceptance Test
ruby
# spec/acceptance/ntp_spec.rb
require 'spec_helper_acceptance'
describe 'ntp class' do
let(:pp) do
<<-MANIFEST
class { 'ntp':
servers => ['0.pool.ntp.org'],
}
MANIFEST
end
it 'applies without errors and is idempotent' do
idempotent_apply(pp) # applies twice: first may change, second must NOT change anything
end
describe package('chrony') do
it { is_expected.to be_installed }
end
describe service('chronyd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
describe file('/etc/chrony.conf') do
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{pool 0\.pool\.ntp\.org} }
end
describe port(123) do
it { is_expected.to be_listening.with('udp') } # may not apply in containers
end
end
The idempotence check: idempotent_apply runs your manifest twice and fails if the second run reports any change. It is the best way to find an exec without creates or a file that changes every run.
Other Acceptance Tools
| Tool | Notes |
| Litmus | Recommended for modules, flexible and scriptable |
Test Kitchen (kitchen-puppet) | Older approach, still used. kitchen test creates, converges and verifies |
| Beaker | The older framework Litmus replaces. Seen in legacy modules |
| InSpec / Goss / serverspec | Verification tools that check the system state after a run |
Vagrant + puppet apply | Simple local labs, no framework |
yaml
# kitchen.yml (Test Kitchen example)
---
driver: { name: docker }
provisioner:
name: puppet_apply
manifests_path: examples
modules_path: spec/fixtures/modules
hiera_data_path: spec/fixtures/hieradata
platforms:
- name: rockylinux-9
- name: ubuntu-22.04
suites:
- name: default
manifest: init.pp
verifier:
name: inspec
CI Pipeline for a Module (GitHub Actions)
yaml
ame: CI
on: [pull_request, push]
jobs:
validate-and-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with: { ruby-version: '3.2', bundler-cache: true }
- run: bundle exec rake validate lint metadata_lint
- run: bundle exec rake parallel_spec
acceptance:
needs: validate-and-unit
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: [litmusimage/rockylinux:9, litmusimage/ubuntu:22.04]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with: { ruby-version: '3.2', bundler-cache: true }
- run: bundle exec rake "litmus:provision[docker,${{ matrix.image }}]"
- run: bundle exec rake "litmus:install_agent[puppet8]"
- run: bundle exec rake litmus:install_module
- run: bundle exec rake litmus:acceptance:parallel
- if: always()
run: bundle exec rake litmus:tear_dow
CI/CD Pipeline for a Control Repository
text
Pull request
├─ 1. Static checks : puppet parser validate, puppet-lint, yamllint, r10k puppetfile check, secret scan
├─ 2. Unit tests : rspec-puppet for site-modules (profiles and roles)
├─ 3. Catalog compile : compile catalogs for every role with sample facts (puppet catalog or onceover)
└─ 4. Review : at least one approver
Merge to `staging`
└─ 5. Deploy : r10k / Code Manager deploys the environment
└─ 6. Staging nodes : agents run, pipeline checks reports for failures
Merge to `production`
└─ 7. Canary deploy : subset of nodes run, wait 30 minutes, check report status
└─ 8. Full rollout : remaining nodes, with a health gate
└─ 9. Notify : Slack/Teams, update change log
Onceover: Onceover is a popular tool for testing control repositories. You describe your classes, nodes (as fact sets) and tests, and it compiles catalogs for each combination, so you know that every role compiles on every OS before merge.
yaml
# spec/onceover.yaml
classes:
- role::webserver
- role::database
nodes:
- Rocky-9
- Ubuntu-24.04
class_groups:
all_roles:
- role::webserver
- role::database
test_matrix:
- all_nodes:
classes: 'all_roles'
tests: 'all_tests'
yaml
# .gitlab-ci.yml: deploy to staging then production with approval
stages: [validate, test, deploy_staging, deploy_prod]
lint:
stage: validate
image: puppet/pdk:latest
script: [pdk validate]
unit:
stage: test
image: puppet/pdk:latest
script: [pdk test unit]
deploy_staging:
stage: deploy_staging
rules: [{ if: '$CI_COMMIT_BRANCH == "staging"' }]
script:
- ssh deploy@puppet.example.com 'sudo r10k deploy environment staging -p'
deploy_production:
stage: deploy_prod
rules: [{ if: '$CI_COMMIT_BRANCH == "production"' }]
when: manual # human approval
script:
- ssh deploy@puppet.example.com 'sudo r10k deploy environment production -p'
- ssh deploy@puppet.example.com 'puppet job run ... || true' # replace with your canary and checks step
Post-Deploy Verification
bash
# After canary nodes run, check their last status in PuppetDB
curl -s -G http://puppetdb:8080/pdb/query/v4 --data-urlencode \
'query=nodes[certname, latest_report_status] { certname in ["web01.example.com","web02.example.com"] }' | jq
# Fail the pipeline if any is "failed"
curl -s -G http://puppetdb:8080/pdb/query/v4 --data-urlencode \
'query=nodes[certname] { latest_report_status = "failed" }' | jq -e 'length == 0'
Rollback
- Fix forward is easiest: revert the Git commit, let the pipeline deploy it, and agents correct themselves within a run interval
- For urgent cases, trigger runs with Bolt:
bolt command run 'puppet agent -t' --targets web
- Keep the previous environment code (r10k can redeploy a previous commit by tag)
- Use
--noop canaries to detect risky changes before they go to all nodes
Practice Tasks
- Provision a Docker container with Litmus, install the agent and apply your module
- Write an acceptance test with
idempotent_apply and add a failing exec to see it fail
- Create a CI workflow that runs lint, unit and acceptance tests for two operating systems
- Describe your control repo pipeline from pull request to production on one page
- Add a post-deploy PuppetDB check that fails the pipeline if any node reports
failed
Conclusion
Add acceptance tests on top of lint and unit tests, always check idempotence, and automate the full pipeline: validate, unit test, compile catalogs, deploy to staging, canary, then production, with a PuppetDB check after each step.
Quick Summary: Litmus provision/install/test/tear_down; idempotent_apply; onceover for control repo; pipeline with canary and report check.