I started developing a new salt formula and I need to test it...
- in an isolated environment.
- in a ci/cd tool such as travis.
- run a series of pytests.
- run an interactive test sandbox
There are many ways to solve this problem. This demo will cover the formula-test-harness option. This test harness utilizes allsalt to spin up salt master/minion containers.
This demo is using a trimmed down version of the gpg-formula.
Run this command to start a test container:
docker run --rm -d -v $(pwd):/opt -v $(pwd)/gpg:/srv/salt/gpg -h salt-master-sandbox --name salt-master-sandbox simplyadrian/allsalt:centos_master_2017.7.2
Let's shell into the container and verify our state is in place:
docker exec -it salt-master-sandbox bash
# ensure the state is in the right place
ls /srv/salt/gpg
Now we can run the state and verify a key was generated:
# run the state
salt-call -l debug state.apply gpg
# verify the key was generated
salt-call gpg.list_keys gnupghome='/etc/salt/gpgkeys'
Exit the shell and kill the container
docker kill salt-master-sandbox
- Fork this repository
- Follow the install instructions in the
formula-test-harness
docs - Start a virtualenv and run the setup:
pip install -U virtualenv
virtualenv .venv
source .venv/bin/activate
make setup
- Run the centos test:
make test-centos_master_2017.7.2
- go to travis-ci.org and create an account if you don't have one
- on the left side of the screen click on the
+
next toMy Repositories
- search for
saltstack-meetup
(if it does not show up try syncing your account and search again) - click on the gray toggle thing next to the repository name
- commit and push the changes to your fork
- view the test status here: https://travis-ci.org/YOUR-GITHUB-USERNAME/saltstack-meetup-2018-03-13
Dig into it...
- write another test
- your ideas?