Saltcheck
Easy Salt State Testing
William Cannon
| SaltConf17
1
SALTCHECK
DEMOS
EXTERNAL TOOLS
QUESTIONS
PRESENTATION OVERVIEW
ABOUT ME
LAST YEAR’S SALTCONF
WELCOME
SALT TOOLS
| SaltConf17
2
ABOUT ME
Infrastructure Architect @ hospitalityPulse
SaltStack Certified Engineer (#23) SSC ID: AE07A5E3
Host SaltStack Meetup in Minneapolis
SaltConf Presenter 2015, 2016
Use Salt for infrastructure automation, deployment of custom applications, business continuity and etc.
@wcannon - twitter / github
https://github.com/wcannon/salt-check
| SaltConf17
3
By automating room inventory management in real time,
hospitalityPulse enables hoteliers to maximize guest satisfaction:
…by maximizing attribute fulfillment levels!
…minimizing preventable downgrades!
…streamlining the check in process!
and in the process allow hoteliers to:
…present guests with attribute inventory during the booking process!
…manage their operation based on insightful, real-time data!
…gain new understanding of who their guests really are!
The big issue
At hospitalityPulse we use salt heavily
In the early years simple tests were sufficient to build confidence.
However, with time passing and complexity increasing we needed a way to catch issues early, and easily.
We were left with the question:
What is the best way to test salt states?
| SaltConf17
5
EXTERNAL TOOLS
Predict actions that will happen before a state run
SALT TOOLS
At SaltConf16… a search for the right way to test
Mostly ruby based tools requiring installation, libraries, configuration… lots of work
| SaltConf17
6
Salt Tools
Shows top data a minion will use for a highstate
Show Top
state.show_top
Show what would be applied to a minion
Test = True
state.apply my_state test=True
Shows highstate data from master
Show High State
state.show_highstate
Shows low data that will be applied to a minion
Show Low State
state.show_lowstate
Display state data from a specific sls (or list)
Show SLS
state.show_sls
State compiler processes sls data without calling state functions (good for validating arguments)
Mock = True
state.apply my_state mock=True
| SaltConf17
7
External Tools
RSpecPuppet
unit test
ChefSpec
unit test
RSpec
unit test
ServerSpec
integration testing
Test Kitchen
test harness
TestInfra
ServerSpec in python, plugin to pytest
| SaltConf17
8
EASIEST PROCESS
But not a great one
APPLY A STATE
INSPECT SERVER
Bonus points for spinning up a new VM / container to do this
WRITE / UPDATE A STATE
Reviewing output of state run for any unexpected issues
Manually review all the parts of the system that the state is managing
Hint: If you are testing this way, create an sls that removes all the changes. And, apply it in-between state runs
| SaltConf17
9
Let’s review why we need to test
| SaltConf17
10
What is the ideal situation?
| SaltConf17
11
Saltcheck! - what a nice module
| SaltConf17
12
Saltcheck Requirements and Conventions
| SaltConf17
13
saltcheck in state tree
| SaltConf17
14
CLI translation to saltcheck test
CLI Execution to translate (cli)
salt ‘*’ file.file_exists /tmp/hello
Translation to valid saltcheck test (yaml)
Test-1-hello-file:
module_and_function: file.file_exists
args:
- /tmp/hello
kwargs:
assertion: assertEqual
expected-return: True
| SaltConf17
15
Test Assertions Supported
assertEqual
assertNotEqual
assertTrue
assertFalse
assertIn
assertNotIn
assertGreater
assertGreaterEqual
assertLess
assertLessEqual
| SaltConf17
16
How to run saltcheck
salt ‘*’ saltcheck.run_state_tests MyState
salt ‘*’ saltcheck.run_highstate_tests
salt ‘*’ saltcheck.update_master_cache
Config flag - set on minion, or assigned via pillar
auto_update_master_cache: True
| SaltConf17
17
EASY AND BETTER PROCESS
APPLY A STATE
Bonus points for spinning up a new VM / container to do this
WRITE / UPDATE A STATE
Reviewing output of state run for any unexpected issues
Use salt execution modules for functionality
WRITE / UPDATE SALTCHECK TEST
RUN SALTCHECK
Review test output and update state accordingly
| SaltConf17
18
BASIC SALTCHECK TEST
| SaltConf17
19
SALTCHECK TEST WITH JINJA
| SaltConf17
20
SALTCHECK HIGHSTATE TEST
| SaltConf17
21
Compliance / Auditing
Trouble-Shooting
Catch issues early
Highstate Addition
Dynamic Testing
Use Cases
Other than simple testing
Document systems meeting company policies
Check status of production servers (in parallel)
Pull in testing data from central sources (eg. pillar) at run time
| SaltConf17
22
Thanks for coming!
Questions?
| SaltConf17
23