SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
Puppet Code testing


Modules vs. Control-Repo
Martin Alfke - example42 GmbH


PuppetCamp April 15, 2021
1
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Puppet since 2009, Puppet Trainer since
2011, Puppet Certified Consultant since 2015


CEO & Co-Founder example42 GmbH


tuxmea (Twitter, GitHub, Slack)


Puppet Consulting, Training and
Development
MartinAlfke
2
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Why testing?
3
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Why testing?
4
Can Puppet compiler parse your
code?


Can you upgrade to a newer Puppet
version?


Does the refactoring accidentally
change anything?
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Why testing?
5
What to use?


- puppet-lint


- rspec-puppet


- PDK


- OnceOver


- Beaker


- Litmus


- serverspec


- https://voxpupuli.org/plugins/
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Why testing?
6
But,


I only want to write Puppet code!


And now I must learn testing?


Let’s choose the most simple to use
solution!
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Why testing?
7
Which tests to run?


- Lint tests - check style guide


- Unit tests - check catalog


- Acceptance tests - check system
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
8
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Where do you want to run the test?


On your workstation (Windows, Mac
OS, Linux)


Within an automated CI pipeline (Linux
Shell, Container)
Testing Modules
9
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
10
Image: tatlin
PDK:


- easy to use


- all bundled


- different Puppet version tests possible


pdk validate --puppet-version=7
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Standalone Library (or Component)
Modules, not roles & profiles


Use PDK (Puppet Development Kit) to
generate module, classes, 



- pdk new module


- pdk new class, defined_type, fact,
function, provider, task


- pdk convert, update
Testing Modules
11
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
12
Image: tatlin
Use PDK (Puppet Development Kit) for
testing:


- pdk validate


- pdk test unit
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
13
Image: tatlin
Add dependencies like stdlib or inifile
to .fixtures.yml


Get dependencies from forge or git
(upstream or local)
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
14
Image: tatlin
You want to change the default
behaviour?


Check the pdk-template git repo and
use the possibility to configure PDK
(.sync.yml)


Run pdk update afterwards.
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Modules
15
Image: tatlin
PDK uses Puppet version and
supported OS from metadata.json


But how to proceed with control-repo?
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Control-Repo - PDK
16
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 17
Syntax Tests:


Role and profile modules must be generated
using PDK


pushd site/profile && pdk validate && popd


pushd site/role && pdk validate && popd


Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 18
Using PDK for Unit Testing


Many dependencies (upstream or library
modules) like stdlib, inifile, core modules, ...


You want to use your control-repo Hiera config
and data


You want to use your manifests/site.pp
Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 19
Using PDK for Unit Testing


- profile and role module must be in PDK
format (use pdk convert on existing profile
and role modules)


- modules from Puppetfile must be installed
locally (r10k puppetfile install)
Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 20
Using PDK - solution


One needs:


- .fixtures.yml


- spec/spec_helper_local.rb
Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 21
Using PDK on profile module
-.fixtures.yml


# site/profile/.fixtures.yml


---


fixtures:


symlinks:


profile: "#{source_dir}"


../r10k: ‘../../../../modules'
Testing Control-Repo - PDK
Using PDK on role module
-.fixtures.yml


# site/role/.fixtures.yml


---


fixtures:


symlinks:


role: "#{source_dir}"


profile: "#{source_dir}/../profile"


../r10k: ‘../../../../modules'
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 22
Using PDK - spec/spec_helper_local.rb


# site/{role|profile}/spec/spec_helper_local.rb


fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))


RSpec.configure do |c|


c.module_path = File.join(fixture_path, 'modules') + ':' + File.join(fixture_path, ‘r10k')


c.manifest_dir = File.join(fixture_path, ‘../../../../manifests’)


c.manifest = File.join(fixture_path, ‘../../../../manifests/site.pp’)


c.hiera_config = File.join(fixture_path, '../../../../hiera.yaml')


end
Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 23
Run your control-repo tests:


r10k puppetfile install


pushd site/profile && pdk test unit && popd


pushd site/role && pdk test unit && popd


Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 24
Using PDK for Acceptance Testing


PDK does not officially support acceptance
testing.


Yes, PDK ships beaker and litmus


- pdk bundle exec rake -T


pdk bundle: not officially supported!


Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 25
How to deal with role or profile classes which
are designed for a specific OS only?


Reminder: PDK uses supported OS from
metadata.json


Many adoptions required.


Is there a more simple way?
Image: tatlin
Testing Control-Repo - PDK
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Testing Control-Repo - OnceOver
26
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 27
https://github.com/dylanratcliffe/onceover


Specially created to test Puppet control-repo


Separation of concerns: tests for library
modules vs. tests for control-repo


Run syntax, unit and acceptance tests 
 and
one more thing ;-)
Image: tatlin
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 28
Delivered as Ruby GEM:


gem install onceover onceover-codequality


Or: Gemfile: gem ‘onceover’


gem ‘onceover-codequality’


Initialize OnceOver on your control-repo:
onceover init


Run syntax tests: onceover run codequality
Image: tatlin
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 29
onceover run codequality


INFO
	
-> Running Code Quality tests


INFO
	
-> Checking Puppetfile...


INFO
	
-> ...OK


INFO
	
-> Checking puppet-syntax rake task



INFO
	
-> ...OK


WARN
	
-> Please install python and pyyaml for enhanced YAML validation (pip install pyyam


INFO
	
-> Checking lint in manifests...


INFO
	
-> ...OK


INFO
	
-> Checking lint in site...
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 30
spec/onceover.yaml


- add classes and nodes,


- create class_groups and node_groups,


- build your test_matrix


Describe the unit tests in spec/classes/
<class>_spec.rb
Image: tatlin
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 31
# spec/onceover.yaml


classes:


- role::base


nodes:


- CentOS-7.0-64


class_groups:


all_classes:


- role::base




Testing Control-Repo - OnceOver
# spec/onceover.yaml continued






node_groups:


testnodes:


- CentOS-7.0-64


test_matrix:


- all_nodes:


classes: 'role::base'


tests: 'spec'
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 32
onceover run spec


INFO
	
-> Using Puppetfile ‘
/control-repo/.onceover/etc/puppetlabs/code/
environments/production/Puppetfile’


INFO
	
-> Updating module 
/control-repo/.onceover/etc/puppetlabs/code/
environments/production/modules/yumrepo_core






role::base: P P P P
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 33
Acceptance Tests are configures in spec/
acceptance/<class>_spec.rb


Nodesets are configured in spec/acceptance/
nodesets/onceover-nodes.yaml


Hint: onceover needs beaker and will print a
complaint about beaker deprecation.


One more thing!
Image: tatlin
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 34
OnceOver Catalog diff


gem ‘onceover-octocatalog-diff’


onceover run diff --from <branch> --to <branch>
Image: tatlin
Testing Control-Repo - OnceOver
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Summary
35
Image: tatlin
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Summary
36
Image: tatlin
Testing is important but has a learning
curve!


Syntax and unit tests are essential and
easy to do


Acceptance tests are useful, but
harder to do
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Summary
37
Image: tatlin
Move from simple to harder.


Start using PDK.


Learn rspec-puppet.


Move to OnceOver for contro-repo testing.


Build an infrastructure for acceptance testing.
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Summary
38
Image: tatlin
PDK uses OS information from a modules
metadata.json.


Different tests for different OS needs adoption of spec
tests.


OnceOver lets you build a test matrix regarding
classes and OS to tests.
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Summary
39
Image: tatlin
Check the possibilities of your infrastructure and
your test requirements.


VM tests are possible in Docker, VMware,
Vagrant, AWS, 



https://github.com/voxpupuli/beaker/blob/master/
docs/how_to/hypervisors/README.md


https://github.com/puppetlabs/provision
Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH
Please take care!
40
We are living in difficult times.


Cities and towns need diversity.


Diversity is provided by small businesses.


Support your local, small, owner or family run
businesses.


Stay healthy and take care!
Puppet Code testing


Modules vs. Control-Repo
Q&A


Martin Alfke - example42 GmbH

Weitere Àhnliche Inhalte

Was ist angesagt?

Las 12 pruebas de Asterisk
Las 12 pruebas de AsteriskLas 12 pruebas de Asterisk
Las 12 pruebas de AsteriskElio Rojano
 
Getting started with Puppet
Getting started with PuppetGetting started with Puppet
Getting started with Puppetjeyg
 
IBM Health Center Details
IBM Health Center DetailsIBM Health Center Details
IBM Health Center DetailsRohit Kelapure
 
10 Tips for AIX Security
10 Tips for AIX Security10 Tips for AIX Security
10 Tips for AIX SecurityHelpSystems
 
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-ServerBewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Serverpanagenda
 
A very quick introduction to HFC, DOCSIS 3.0 and 3.1
A very quick introduction to HFC, DOCSIS 3.0 and 3.1A very quick introduction to HFC, DOCSIS 3.0 and 3.1
A very quick introduction to HFC, DOCSIS 3.0 and 3.1Erik Vloothuis
 

Was ist angesagt? (10)

Ansible
AnsibleAnsible
Ansible
 
Las 12 pruebas de Asterisk
Las 12 pruebas de AsteriskLas 12 pruebas de Asterisk
Las 12 pruebas de Asterisk
 
Getting started with Puppet
Getting started with PuppetGetting started with Puppet
Getting started with Puppet
 
IBM Health Center Details
IBM Health Center DetailsIBM Health Center Details
IBM Health Center Details
 
10 Tips for AIX Security
10 Tips for AIX Security10 Tips for AIX Security
10 Tips for AIX Security
 
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-ServerBewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
BewĂ€hrte Praktiken fĂŒr HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
 
A very quick introduction to HFC, DOCSIS 3.0 and 3.1
A very quick introduction to HFC, DOCSIS 3.0 and 3.1A very quick introduction to HFC, DOCSIS 3.0 and 3.1
A very quick introduction to HFC, DOCSIS 3.0 and 3.1
 
Cisco ios overview
Cisco ios overviewCisco ios overview
Cisco ios overview
 
Advanced rf troubleshooting_peter lane
Advanced rf troubleshooting_peter laneAdvanced rf troubleshooting_peter lane
Advanced rf troubleshooting_peter lane
 
DHCP PROTOCOL
DHCP PROTOCOLDHCP PROTOCOL
DHCP PROTOCOL
 

Ähnlich wie Puppet camp2021 testing modules and controlrepo

Puppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GITPuppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GITMartin Alfke
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Puppet
 
Jenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-PipelinesJenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-PipelinesChristian MĂŒnch
 
Introduction to Polyaxon
Introduction to PolyaxonIntroduction to Polyaxon
Introduction to PolyaxonYu Ishikawa
 
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...Puppet
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppetPuppet
 
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...Puppet
 
Autotools adaptation for integrating autotmatic unit tests and covering for K...
Autotools adaptation for integrating autotmatic unit tests and covering for K...Autotools adaptation for integrating autotmatic unit tests and covering for K...
Autotools adaptation for integrating autotmatic unit tests and covering for K...Thierry Gayet
 
Iteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey MillerIteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey MillerPuppet
 
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...Work-Bench
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontendHeiko Hardt
 
2018 Cisco DevNet Create : How to Treat a Network as a Container
2018 Cisco DevNet Create : How to Treat a Network as a Container2018 Cisco DevNet Create : How to Treat a Network as a Container
2018 Cisco DevNet Create : How to Treat a Network as a ContainerRosemary Wang
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringAlessandro Franceschi
 
Learning puppet chapter 3
Learning puppet chapter 3Learning puppet chapter 3
Learning puppet chapter 3Vishal Biyani
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareLaura Frank Tacho
 
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Evgeniy Kuzmin
 
PuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetPuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetWalter Heck
 

Ähnlich wie Puppet camp2021 testing modules and controlrepo (20)

Intro to PDK
Intro to PDKIntro to PDK
Intro to PDK
 
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GITPuppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014
 
Mcollective introduction
Mcollective introductionMcollective introduction
Mcollective introduction
 
Jenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-PipelinesJenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-Pipelines
 
Introduction to Polyaxon
Introduction to PolyaxonIntroduction to Polyaxon
Introduction to Polyaxon
 
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppet
 
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...
 
Autotools adaptation for integrating autotmatic unit tests and covering for K...
Autotools adaptation for integrating autotmatic unit tests and covering for K...Autotools adaptation for integrating autotmatic unit tests and covering for K...
Autotools adaptation for integrating autotmatic unit tests and covering for K...
 
Iteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey MillerIteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
 
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...
Nobody Knows What It’s Like To Be the Bad Man: The Development Process for th...
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontend
 
2018 Cisco DevNet Create : How to Treat a Network as a Container
2018 Cisco DevNet Create : How to Treat a Network as a Container2018 Cisco DevNet Create : How to Treat a Network as a Container
2018 Cisco DevNet Create : How to Treat a Network as a Container
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoring
 
Learning puppet chapter 3
Learning puppet chapter 3Learning puppet chapter 3
Learning puppet chapter 3
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate Everything
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your Software
 
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
 
PuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetPuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of Puppet
 

Mehr von Puppet

Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyamlPuppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)Puppet
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscodePuppet
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twentiesPuppet
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codePuppet
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approachPuppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationPuppet
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliancePuppet
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowPuppet
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Puppet
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppetPuppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkPuppet
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping groundPuppet
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy SoftwarePuppet
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User GroupPuppet
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsPuppet
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyPuppet
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkPuppet
 

Mehr von Puppet (20)

Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 

KĂŒrzlich hochgeladen

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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.pptxEarley Information Science
 
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.pptxHampshireHUG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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...apidays
 
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 interpreternaman860154
 
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 organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

KĂŒrzlich hochgeladen (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Puppet camp2021 testing modules and controlrepo

  • 1. Puppet Code testing Modules vs. Control-Repo Martin Alfke - example42 GmbH PuppetCamp April 15, 2021 1
  • 2. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Puppet since 2009, Puppet Trainer since 2011, Puppet Certified Consultant since 2015 CEO & Co-Founder example42 GmbH tuxmea (Twitter, GitHub, Slack) Puppet Consulting, Training and Development MartinAlfke 2
  • 3. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Why testing? 3 Image: tatlin
  • 4. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Why testing? 4 Can Puppet compiler parse your code? Can you upgrade to a newer Puppet version? Does the refactoring accidentally change anything? Image: tatlin
  • 5. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Why testing? 5 What to use? - puppet-lint - rspec-puppet - PDK - OnceOver - Beaker - Litmus - serverspec - https://voxpupuli.org/plugins/ Image: tatlin
  • 6. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Why testing? 6 But, I only want to write Puppet code! And now I must learn testing? Let’s choose the most simple to use solution! Image: tatlin
  • 7. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Why testing? 7 Which tests to run? - Lint tests - check style guide - Unit tests - check catalog - Acceptance tests - check system Image: tatlin
  • 8. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 8 Image: tatlin
  • 9. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Where do you want to run the test? On your workstation (Windows, Mac OS, Linux) Within an automated CI pipeline (Linux Shell, Container) Testing Modules 9 Image: tatlin
  • 10. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 10 Image: tatlin PDK: - easy to use - all bundled - different Puppet version tests possible pdk validate --puppet-version=7
  • 11. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Standalone Library (or Component) Modules, not roles & profiles Use PDK (Puppet Development Kit) to generate module, classes, 
 - pdk new module - pdk new class, defined_type, fact, function, provider, task - pdk convert, update Testing Modules 11 Image: tatlin
  • 12. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 12 Image: tatlin Use PDK (Puppet Development Kit) for testing: - pdk validate - pdk test unit
  • 13. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 13 Image: tatlin Add dependencies like stdlib or inifile to .fixtures.yml Get dependencies from forge or git (upstream or local)
  • 14. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 14 Image: tatlin You want to change the default behaviour? Check the pdk-template git repo and use the possibility to configure PDK (.sync.yml) Run pdk update afterwards.
  • 15. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Modules 15 Image: tatlin PDK uses Puppet version and supported OS from metadata.json But how to proceed with control-repo?
  • 16. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Control-Repo - PDK 16 Image: tatlin
  • 17. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 17 Syntax Tests: Role and profile modules must be generated using PDK pushd site/profile && pdk validate && popd pushd site/role && pdk validate && popd Image: tatlin Testing Control-Repo - PDK
  • 18. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 18 Using PDK for Unit Testing Many dependencies (upstream or library modules) like stdlib, inifile, core modules, ... You want to use your control-repo Hiera config and data You want to use your manifests/site.pp Image: tatlin Testing Control-Repo - PDK
  • 19. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 19 Using PDK for Unit Testing - profile and role module must be in PDK format (use pdk convert on existing profile and role modules) - modules from Puppetfile must be installed locally (r10k puppetfile install) Image: tatlin Testing Control-Repo - PDK
  • 20. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 20 Using PDK - solution One needs: - .fixtures.yml - spec/spec_helper_local.rb Image: tatlin Testing Control-Repo - PDK
  • 21. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 21 Using PDK on profile module -.fixtures.yml # site/profile/.fixtures.yml --- fixtures: symlinks: profile: "#{source_dir}" ../r10k: ‘../../../../modules' Testing Control-Repo - PDK Using PDK on role module -.fixtures.yml # site/role/.fixtures.yml --- fixtures: symlinks: role: "#{source_dir}" profile: "#{source_dir}/../profile" ../r10k: ‘../../../../modules'
  • 22. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 22 Using PDK - spec/spec_helper_local.rb # site/{role|profile}/spec/spec_helper_local.rb fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| c.module_path = File.join(fixture_path, 'modules') + ':' + File.join(fixture_path, ‘r10k') c.manifest_dir = File.join(fixture_path, ‘../../../../manifests’) c.manifest = File.join(fixture_path, ‘../../../../manifests/site.pp’) c.hiera_config = File.join(fixture_path, '../../../../hiera.yaml') end Image: tatlin Testing Control-Repo - PDK
  • 23. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 23 Run your control-repo tests: r10k puppetfile install pushd site/profile && pdk test unit && popd pushd site/role && pdk test unit && popd Image: tatlin Testing Control-Repo - PDK
  • 24. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 24 Using PDK for Acceptance Testing PDK does not officially support acceptance testing. Yes, PDK ships beaker and litmus - pdk bundle exec rake -T pdk bundle: not officially supported! Image: tatlin Testing Control-Repo - PDK
  • 25. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 25 How to deal with role or profile classes which are designed for a specific OS only? Reminder: PDK uses supported OS from metadata.json Many adoptions required. Is there a more simple way? Image: tatlin Testing Control-Repo - PDK
  • 26. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Testing Control-Repo - OnceOver 26 Image: tatlin
  • 27. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 27 https://github.com/dylanratcliffe/onceover Specially created to test Puppet control-repo Separation of concerns: tests for library modules vs. tests for control-repo Run syntax, unit and acceptance tests 
 and one more thing ;-) Image: tatlin Testing Control-Repo - OnceOver
  • 28. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 28 Delivered as Ruby GEM: gem install onceover onceover-codequality Or: Gemfile: gem ‘onceover’ gem ‘onceover-codequality’ Initialize OnceOver on your control-repo: onceover init Run syntax tests: onceover run codequality Image: tatlin Testing Control-Repo - OnceOver
  • 29. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 29 onceover run codequality INFO -> Running Code Quality tests INFO -> Checking Puppetfile... INFO -> ...OK INFO -> Checking puppet-syntax rake task
 INFO -> ...OK WARN -> Please install python and pyyaml for enhanced YAML validation (pip install pyyam INFO -> Checking lint in manifests... INFO -> ...OK INFO -> Checking lint in site... Testing Control-Repo - OnceOver
  • 30. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 30 spec/onceover.yaml - add classes and nodes, - create class_groups and node_groups, - build your test_matrix Describe the unit tests in spec/classes/ <class>_spec.rb Image: tatlin Testing Control-Repo - OnceOver
  • 31. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 31 # spec/onceover.yaml classes: - role::base nodes: - CentOS-7.0-64 class_groups: all_classes: - role::base 
 Testing Control-Repo - OnceOver # spec/onceover.yaml continued 
 node_groups: testnodes: - CentOS-7.0-64 test_matrix: - all_nodes: classes: 'role::base' tests: 'spec'
  • 32. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 32 onceover run spec INFO -> Using Puppetfile ‘
/control-repo/.onceover/etc/puppetlabs/code/ environments/production/Puppetfile’ INFO -> Updating module 
/control-repo/.onceover/etc/puppetlabs/code/ environments/production/modules/yumrepo_core 
 role::base: P P P P Testing Control-Repo - OnceOver
  • 33. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 33 Acceptance Tests are configures in spec/ acceptance/<class>_spec.rb Nodesets are configured in spec/acceptance/ nodesets/onceover-nodes.yaml Hint: onceover needs beaker and will print a complaint about beaker deprecation. One more thing! Image: tatlin Testing Control-Repo - OnceOver
  • 34. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH 34 OnceOver Catalog diff gem ‘onceover-octocatalog-diff’ onceover run diff --from <branch> --to <branch> Image: tatlin Testing Control-Repo - OnceOver
  • 35. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Summary 35 Image: tatlin
  • 36. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Summary 36 Image: tatlin Testing is important but has a learning curve! Syntax and unit tests are essential and easy to do Acceptance tests are useful, but harder to do
  • 37. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Summary 37 Image: tatlin Move from simple to harder. Start using PDK. Learn rspec-puppet. Move to OnceOver for contro-repo testing. Build an infrastructure for acceptance testing.
  • 38. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Summary 38 Image: tatlin PDK uses OS information from a modules metadata.json. Different tests for different OS needs adoption of spec tests. OnceOver lets you build a test matrix regarding classes and OS to tests.
  • 39. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Summary 39 Image: tatlin Check the possibilities of your infrastructure and your test requirements. VM tests are possible in Docker, VMware, Vagrant, AWS, 
 https://github.com/voxpupuli/beaker/blob/master/ docs/how_to/hypervisors/README.md https://github.com/puppetlabs/provision
  • 40. Puppet Code Testing - Modules vs. Control-Repo - PuppetCamp 2021 - Martin Alfke © example42 GmbH Please take care! 40 We are living in difficult times. Cities and towns need diversity. Diversity is provided by small businesses. Support your local, small, owner or family run businesses. Stay healthy and take care!
  • 41. Puppet Code testing Modules vs. Control-Repo Q&A Martin Alfke - example42 GmbH