SlideShare a Scribd company logo
Testing Salt States: Part 1
The Basics
About Me (Jason Denning)
• DevOps Engineer
• SaltStack user for ~ 3 years
• SaltStack Certified Engineer #2
• AWS Certified Architect
• OSS Advocate (first Linux install ~ 1998)
• Pythonista
• jasondenning on GitHub / @jason_denning on Twitter
● Provide analytics and
marketing/segmentation tools for
mobile app developers
● Hosted backend APIs available world-
wide
● Lots of traffic
● Big fans of SaltStack
● upsight.com
WARNING: Work In Progress
● Testing infrastructure is not a common practice
● These slides are rough
● Your Mileage May Vary!
● We should work (together) on improving this
Why Test?
● DevOps: Infrastructure is code
● Code should be tested
● ⇒ Infrastructure should be tested
Why Test? (continued)
● Find errors faster
● Prevent regressions
● Allow others to contribute
● Simplify Code Reviews (CI)
● Improve Documentation
What to Test
● Basic Syntax (linting)
● Individual States
● State Relationships
● Different Environments
● As much as possible (within reason)
Testing Basics
● Tests should run quickly (and automatically)
● Tests should be isolated - know what you’re testing!
● Unit Tests: Test a single ‘unit’ of code
● Integration Tests: Test interactions between units
● Acceptance Tests: Test that code does what we want
Minimal Testing
$ salt-call state.highstate test=True
● Better than blindly applying
states
● Still not what we’re looking for
○ Manual
○ Slow
○ No isolation
○ Error-prone (“Oops, I
didn’t see the red line!”)
First Improvement
Test states individually:
$ salt-call state.sls foo test=True
● Slight improvement
○ More isolation
○ Faster than highstate
● Still not what we want
Testing Basic Syntax of SLS Files
● First Attempt: Verify SLS files are valid YAML
○ Problem: Only works for very basic states - Jinja breaks the test!
○ Problem: What about other renderers?
●
● Improvement: Test that Salt can render the SLS file
○ “salt-call state.sls foo test=True” works for this
○ Alternative: “salt-call state.show_sls foo”
Testing Basic Syntax
$ salt-call state.sls foo test=True
(with syntax error)
$ salt-call state.show_sls foo
(with syntax error)
Note: Better error message!
Testing Basic Syntax
$ salt-call state.show_sls foo
(no syntax error)
Testing Basic Syntax - Notes
● Salt built-ins are useful!
● Better: A separate tool for validating syntax
(somebody should build one!)
● Don’t forget about outputters:
● salt-call state.show_sls foo --output=json
Testing in Isolation
● We need to be sure that test results are not influenced
by previous tests
● Unit testing frameworks handle this automatically
● Ideal: Create a new, clean infrastructure for each test
○ Problem: Tests must run quickly!
● Solutions:
○ Use VMs (still to slow if we’re running lots of tests)
○ Use Containers (e.g. LXC / Docker)
Docker Containers vs. Full VMs
Docker Pros:
● Easy
● Quick to build and destroy
Docker Cons:
● Missing Functionality (testing services will take
more work)
● Linux only
VM Pros:
● Full OS install - services work / any OS
● Easy to manage if using tools such as Vagrant
● Might be identical to your actual environment
VM Cons:
● Slow(er) to build and destroy
Best Practice: Use both! (For different types of test)
Docker: Quickstart
● Docker makes it easy to build & manage LXC containers
● Allows one to quickly customize existing container images
● Mount host directories in the container
Basic Dockerfile (~/saltpdx/Dockerfile):
FROM phusion/baseimage
RUN sudo add-apt-repository -y ppa:saltstack/salt
RUN sudo apt-get update
RUN sudo apt-get -y install salt-minion
VOLUME ["/etc/salt", "/salt/states", "/salt/pillar"]
CMD salt-call state.highstate
● Build an image (tagged salt/test, version 1):
$ docker build -t ‘salt/test:1’ .
● Start a container using the image:
$ docker run --rm -it -v ~/saltpdx/salt:/etc/salt -v ~/saltpdx/states:/salt/states -v /
~/saltpdx/pillar:/salt/pillar salt/test:1
Docker Quickstart
● Docker creates a container
based on the image
● Host directories are
specified using the -v flag
● Docker starts the container
and runs the CMD specified
in the Dockerfile
● --rm flag tells docker to
delete the container after
the command has run
● -it (or -i -t) for interactive
terminal mode (add
‘/bin/bash’ to end of
command to get a shell)
Docker Tips
● Mount host directories as volumes for:
○ Salt configuration
○ States
○ Pillar
○ Logs?
● Configure containers as salt-masterless to avoid networking & PKI
issues
● Use the --rm flag to automatically delete container instances after
they’ve run
● Tag & version images
Docker: Entrypoint
● When you run a Docker container, Docker executes a binary called ENTRYPOINT
● The CMD that you pass to Docker (via Dockerfile or the cli) is passed as an argument to
the ENTRYPOINT
● By default, Docker will use “/bin/sh -c” as the ENTRYPOINT - this can be overridden
● e.g.:
$ docker run --rm --entrypoint /bin/echo salt/test:1 foo
● We can exploit this to make a simple test runner
● Dockerfile:
FROM phusion/baseimage
RUN sudo add-apt-repository -y ppa:saltstack/salt
RUN sudo apt-get update
RUN sudo apt-get -y install salt-minion
VOLUME ["/etc/salt", "/salt/states", "/salt/pillar"]
ADD test_salt.sh /test_salt.sh
RUN chmod +x /test_salt.sh
ENTRYPOINT ["/bin/bash", "/test_salt.sh"]
Docker: Entrypoint (con’t)
● test_salt.sh:
Docker: Entrypoint (con’t)
After building a new image, we can
run:
$ docker run --rm -v / ~/saltpdx/salt:
/etc/salt -v / ~/saltpdx/states:
/salt/states -v / ~/saltpdx/pillar:
/salt/pillar salt/test:2 / highstate
Which will start a container, run “salt-
call state.highstate”, and exit.
Docker: Entrypoint (con’t)
Or, we can run:
$ docker run --rm -v / ~/saltpdx/salt:
/etc/salt -v / ~/saltpdx/states:
/salt/states -v / ~/saltpdx/pillar:
/salt/pillar salt/test:2 / foo
Which will run “salt-call state.
show_sls foo”, then “salt-call state.sls
foo”, and exit.
Next Step: Automation
● We’ve got the basic tools - the next step is to add some automation
● Host-side automation:
○ Starting and destroying containers
○ Determine what states to test
○ Collect & summarize test results
○ Test various permutations (different Linux version, different
grains, etc.)
● Container-side automation
○ Discover & test sub-components (e.g. file templates)
○ Integration/Acceptance/Behavioral Tests
Automation Overview
● Testing is initiated by running a test-controller script on the host
● The test-controller should:
○ Generate a list of states to test and environment permutations
○ Start a container and trigger the test runner
○ Collect test results
○ Destroy the container
○ Repeat for each state
● The Docker image should have a test-runner script that is used as
the ENTRYPOINT
● The test-runner script should:
○ Determine specific tests to run
○ Run the tests
○ Output Results
Next Time - Part 2
● Actual code for these automation scripts
● Behavioral Testing (for acceptance/integration tests)
● Collecting and Summarizing Results in a useful fashion
● Continuous Integration
● Adding Vagrant VMs for additional tests
● Testing multi-machine infrastructures
● …???
Thanks!
Discussion / Questions?
salt@jasondenning.com
GitHub: jasondenning
Twitter: @jason_denning

More Related Content

What's hot

Open Source tools overview
Open Source tools overviewOpen Source tools overview
Open Source tools overview
Luciano Resende
 
Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014
Puppet
 
Continuous Delivery of Puppet Manifests
Continuous Delivery of Puppet ManifestsContinuous Delivery of Puppet Manifests
Continuous Delivery of Puppet Manifests
Kris Buytaert
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
Steffen Gebert
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
ericlongtx
 
DrupalCon Los Angeles - Continuous Integration Toolbox
DrupalCon Los Angeles - Continuous Integration ToolboxDrupalCon Los Angeles - Continuous Integration Toolbox
DrupalCon Los Angeles - Continuous Integration Toolbox
Andrii Podanenko
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
Michal Ziarnik
 
Continuous Delivery in OSS using Shipkit.org
Continuous Delivery in OSS using Shipkit.orgContinuous Delivery in OSS using Shipkit.org
Continuous Delivery in OSS using Shipkit.org
MarcinStachniuk
 
Perl Continous Integration
Perl Continous IntegrationPerl Continous Integration
Perl Continous Integration
Michael Peters
 
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
謝 宗穎
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
Steffen Gebert
 
[WroclawJUG] Continuous Delivery in OSS using Shipkit
[WroclawJUG] Continuous Delivery in OSS using Shipkit[WroclawJUG] Continuous Delivery in OSS using Shipkit
[WroclawJUG] Continuous Delivery in OSS using Shipkit
MarcinStachniuk
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
Annie Huang
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
Bert Jan Schrijver
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
Steffen Gebert
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
Anna Kennedy
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and Jenkins
Micael Gallego
 
Deployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails WorldDeployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails World
Nikhil Mungel
 
Drupal contrib module maintaining
Drupal contrib module maintainingDrupal contrib module maintaining
Drupal contrib module maintaining
Andrii Podanenko
 

What's hot (20)

Open Source tools overview
Open Source tools overviewOpen Source tools overview
Open Source tools overview
 
Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014
 
Continuous Delivery of Puppet Manifests
Continuous Delivery of Puppet ManifestsContinuous Delivery of Puppet Manifests
Continuous Delivery of Puppet Manifests
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
 
DrupalCon Los Angeles - Continuous Integration Toolbox
DrupalCon Los Angeles - Continuous Integration ToolboxDrupalCon Los Angeles - Continuous Integration Toolbox
DrupalCon Los Angeles - Continuous Integration Toolbox
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
 
Continuous Delivery in OSS using Shipkit.org
Continuous Delivery in OSS using Shipkit.orgContinuous Delivery in OSS using Shipkit.org
Continuous Delivery in OSS using Shipkit.org
 
Perl Continous Integration
Perl Continous IntegrationPerl Continous Integration
Perl Continous Integration
 
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
JSDC 2015 - TDD 的開發哲學,以 Node.js 為例
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
[WroclawJUG] Continuous Delivery in OSS using Shipkit
[WroclawJUG] Continuous Delivery in OSS using Shipkit[WroclawJUG] Continuous Delivery in OSS using Shipkit
[WroclawJUG] Continuous Delivery in OSS using Shipkit
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and Jenkins
 
Deployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails WorldDeployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails World
 
Drupal contrib module maintaining
Drupal contrib module maintainingDrupal contrib module maintaining
Drupal contrib module maintaining
 

Similar to Testing Salt States (part 1)

Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
Eugene Yokota
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
Georg Sorst
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
Javier López
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
Ortus Solutions, Corp
 
Salt at school
Salt at schoolSalt at school
Salt at school
Flavio Castelli
 
Open Source Swift: Up and Running
Open Source Swift: Up and RunningOpen Source Swift: Up and Running
Open Source Swift: Up and Running
Carl Brown
 
CoreOS Intro
CoreOS IntroCoreOS Intro
CoreOS Intro
Isaac Johnston
 
AEO Training - 2023.pdf
AEO Training - 2023.pdfAEO Training - 2023.pdf
AEO Training - 2023.pdf
Mohamed Taoufik TEKAYA
 
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Badoo
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
Adrian Otto
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management tools
SaltStack
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
Javier López
 
OSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
OSCamp #4 on Foreman | Salted Foreman by Bernhard SuttnerOSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
OSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
NETWAYS
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
Pablo Godel
 
Wrangling 3rd Party Installers from Puppet
Wrangling 3rd Party Installers from PuppetWrangling 3rd Party Installers from Puppet
Wrangling 3rd Party Installers from Puppet
Puppet
 
Mojolicious
MojoliciousMojolicious
Mojolicious
Marcus Ramberg
 
How to Begin to Develop Ruby Core
How to Begin to Develop Ruby CoreHow to Begin to Develop Ruby Core
How to Begin to Develop Ruby Core
Hiroshi SHIBATA
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
Ilya Puchka
 

Similar to Testing Salt States (part 1) (20)

Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
 
Salt at school
Salt at schoolSalt at school
Salt at school
 
Open Source Swift: Up and Running
Open Source Swift: Up and RunningOpen Source Swift: Up and Running
Open Source Swift: Up and Running
 
CoreOS Intro
CoreOS IntroCoreOS Intro
CoreOS Intro
 
AEO Training - 2023.pdf
AEO Training - 2023.pdfAEO Training - 2023.pdf
AEO Training - 2023.pdf
 
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management tools
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
OSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
OSCamp #4 on Foreman | Salted Foreman by Bernhard SuttnerOSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
OSCamp #4 on Foreman | Salted Foreman by Bernhard Suttner
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Wrangling 3rd Party Installers from Puppet
Wrangling 3rd Party Installers from PuppetWrangling 3rd Party Installers from Puppet
Wrangling 3rd Party Installers from Puppet
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
How to Begin to Develop Ruby Core
How to Begin to Develop Ruby CoreHow to Begin to Develop Ruby Core
How to Begin to Develop Ruby Core
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Testing Salt States (part 1)

  • 1. Testing Salt States: Part 1 The Basics
  • 2. About Me (Jason Denning) • DevOps Engineer • SaltStack user for ~ 3 years • SaltStack Certified Engineer #2 • AWS Certified Architect • OSS Advocate (first Linux install ~ 1998) • Pythonista • jasondenning on GitHub / @jason_denning on Twitter
  • 3. ● Provide analytics and marketing/segmentation tools for mobile app developers ● Hosted backend APIs available world- wide ● Lots of traffic ● Big fans of SaltStack ● upsight.com
  • 4. WARNING: Work In Progress ● Testing infrastructure is not a common practice ● These slides are rough ● Your Mileage May Vary! ● We should work (together) on improving this
  • 5. Why Test? ● DevOps: Infrastructure is code ● Code should be tested ● ⇒ Infrastructure should be tested
  • 6. Why Test? (continued) ● Find errors faster ● Prevent regressions ● Allow others to contribute ● Simplify Code Reviews (CI) ● Improve Documentation
  • 7. What to Test ● Basic Syntax (linting) ● Individual States ● State Relationships ● Different Environments ● As much as possible (within reason)
  • 8. Testing Basics ● Tests should run quickly (and automatically) ● Tests should be isolated - know what you’re testing! ● Unit Tests: Test a single ‘unit’ of code ● Integration Tests: Test interactions between units ● Acceptance Tests: Test that code does what we want
  • 9. Minimal Testing $ salt-call state.highstate test=True ● Better than blindly applying states ● Still not what we’re looking for ○ Manual ○ Slow ○ No isolation ○ Error-prone (“Oops, I didn’t see the red line!”)
  • 10. First Improvement Test states individually: $ salt-call state.sls foo test=True ● Slight improvement ○ More isolation ○ Faster than highstate ● Still not what we want
  • 11. Testing Basic Syntax of SLS Files ● First Attempt: Verify SLS files are valid YAML ○ Problem: Only works for very basic states - Jinja breaks the test! ○ Problem: What about other renderers? ● ● Improvement: Test that Salt can render the SLS file ○ “salt-call state.sls foo test=True” works for this ○ Alternative: “salt-call state.show_sls foo”
  • 12. Testing Basic Syntax $ salt-call state.sls foo test=True (with syntax error) $ salt-call state.show_sls foo (with syntax error) Note: Better error message!
  • 13. Testing Basic Syntax $ salt-call state.show_sls foo (no syntax error)
  • 14. Testing Basic Syntax - Notes ● Salt built-ins are useful! ● Better: A separate tool for validating syntax (somebody should build one!) ● Don’t forget about outputters: ● salt-call state.show_sls foo --output=json
  • 15. Testing in Isolation ● We need to be sure that test results are not influenced by previous tests ● Unit testing frameworks handle this automatically ● Ideal: Create a new, clean infrastructure for each test ○ Problem: Tests must run quickly! ● Solutions: ○ Use VMs (still to slow if we’re running lots of tests) ○ Use Containers (e.g. LXC / Docker)
  • 16. Docker Containers vs. Full VMs Docker Pros: ● Easy ● Quick to build and destroy Docker Cons: ● Missing Functionality (testing services will take more work) ● Linux only VM Pros: ● Full OS install - services work / any OS ● Easy to manage if using tools such as Vagrant ● Might be identical to your actual environment VM Cons: ● Slow(er) to build and destroy Best Practice: Use both! (For different types of test)
  • 17. Docker: Quickstart ● Docker makes it easy to build & manage LXC containers ● Allows one to quickly customize existing container images ● Mount host directories in the container Basic Dockerfile (~/saltpdx/Dockerfile): FROM phusion/baseimage RUN sudo add-apt-repository -y ppa:saltstack/salt RUN sudo apt-get update RUN sudo apt-get -y install salt-minion VOLUME ["/etc/salt", "/salt/states", "/salt/pillar"] CMD salt-call state.highstate ● Build an image (tagged salt/test, version 1): $ docker build -t ‘salt/test:1’ . ● Start a container using the image: $ docker run --rm -it -v ~/saltpdx/salt:/etc/salt -v ~/saltpdx/states:/salt/states -v / ~/saltpdx/pillar:/salt/pillar salt/test:1
  • 18. Docker Quickstart ● Docker creates a container based on the image ● Host directories are specified using the -v flag ● Docker starts the container and runs the CMD specified in the Dockerfile ● --rm flag tells docker to delete the container after the command has run ● -it (or -i -t) for interactive terminal mode (add ‘/bin/bash’ to end of command to get a shell)
  • 19. Docker Tips ● Mount host directories as volumes for: ○ Salt configuration ○ States ○ Pillar ○ Logs? ● Configure containers as salt-masterless to avoid networking & PKI issues ● Use the --rm flag to automatically delete container instances after they’ve run ● Tag & version images
  • 20. Docker: Entrypoint ● When you run a Docker container, Docker executes a binary called ENTRYPOINT ● The CMD that you pass to Docker (via Dockerfile or the cli) is passed as an argument to the ENTRYPOINT ● By default, Docker will use “/bin/sh -c” as the ENTRYPOINT - this can be overridden ● e.g.: $ docker run --rm --entrypoint /bin/echo salt/test:1 foo ● We can exploit this to make a simple test runner ● Dockerfile: FROM phusion/baseimage RUN sudo add-apt-repository -y ppa:saltstack/salt RUN sudo apt-get update RUN sudo apt-get -y install salt-minion VOLUME ["/etc/salt", "/salt/states", "/salt/pillar"] ADD test_salt.sh /test_salt.sh RUN chmod +x /test_salt.sh ENTRYPOINT ["/bin/bash", "/test_salt.sh"]
  • 22. Docker: Entrypoint (con’t) After building a new image, we can run: $ docker run --rm -v / ~/saltpdx/salt: /etc/salt -v / ~/saltpdx/states: /salt/states -v / ~/saltpdx/pillar: /salt/pillar salt/test:2 / highstate Which will start a container, run “salt- call state.highstate”, and exit.
  • 23. Docker: Entrypoint (con’t) Or, we can run: $ docker run --rm -v / ~/saltpdx/salt: /etc/salt -v / ~/saltpdx/states: /salt/states -v / ~/saltpdx/pillar: /salt/pillar salt/test:2 / foo Which will run “salt-call state. show_sls foo”, then “salt-call state.sls foo”, and exit.
  • 24. Next Step: Automation ● We’ve got the basic tools - the next step is to add some automation ● Host-side automation: ○ Starting and destroying containers ○ Determine what states to test ○ Collect & summarize test results ○ Test various permutations (different Linux version, different grains, etc.) ● Container-side automation ○ Discover & test sub-components (e.g. file templates) ○ Integration/Acceptance/Behavioral Tests
  • 25. Automation Overview ● Testing is initiated by running a test-controller script on the host ● The test-controller should: ○ Generate a list of states to test and environment permutations ○ Start a container and trigger the test runner ○ Collect test results ○ Destroy the container ○ Repeat for each state ● The Docker image should have a test-runner script that is used as the ENTRYPOINT ● The test-runner script should: ○ Determine specific tests to run ○ Run the tests ○ Output Results
  • 26. Next Time - Part 2 ● Actual code for these automation scripts ● Behavioral Testing (for acceptance/integration tests) ● Collecting and Summarizing Results in a useful fashion ● Continuous Integration ● Adding Vagrant VMs for additional tests ● Testing multi-machine infrastructures ● …???