Test Suite

The upstream test suite is available in the source directory.

Salt requires a custom testing framework prior v2017.x.

To kickstart the tests, you might need:

apt build-dep salt
apt install python-pip python-psutil python-crypto python-pytest-tornado python-yaml git python-git python-concurrent.futures python-mock python-zmq
cd salt-2016.11.2+ds/ && debi  # for pulling additional run-time dependencies

pip install git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting
# jessie: pip install https://github.com/saltstack/salt-testing/archive/refs/tags/v0.5.4.zip

cd salt-2016.11.2+ds/ && python setup.py test

Behavior:

Unit tests only

# All tests
tests/runtests.py --unit-tests
# Single test
tests/runtests.py -n unit.version_test

See also

salt-2016.11.2+ds/doc/topics/tests/index.rst (2015 online copy)

Smoke test

Installation

master$ service salt-master start
minion$ service salt-minion restart

master$ salt-key -L
Accepted Keys:
Unaccepted Keys:
<your_minion_id>
Rejected Keys:

master$ salt-key -a 'your_minion_id'

Basic commands

master$ salt 'your_minion_id' network.ip_addrs
master$ salt 'your_minion_id' test.ping

SSH-based access

Don't install salt-minion.

Setup SSH keys:

echo 'your_minion_id: 192.168.X.X' >> /etc/salt/roster
salt-ssh your_minion_id -r 'hostname'  # generates master's SSH key if not already
ssh-copy-id -i /etc/salt/pki/master/ssh/salt-ssh.rsa.pub root@192.168.X.X

Test:

salt-ssh your_minion_id -r 'hostname'
salt-ssh your_minion_id -r 'ip a'
salt-ssh your_minion_id test.version

See also: https://docs.saltproject.io/en/latest/topics/ssh/

Simple Salt formula

Place following yaml file in /srv/salt (by default /etc/salt/master/ declares /srv/salt/ as one "base"):

$EDITOR /srv/salt/webserver.sls

webserver:
  pkg:
    - installed
    - pkgs:
      - apache2
      - php
      - php-mysql

To test,

master$ salt     'minion_id' state.sls webserver
master$ salt-ssh 'minion_id' state.sls webserver

TLS module

On the minion:

salt-call tls.create_ca my_little
salt-call tls.create_csr my_little CN=second
salt-call tls.create_self_signed_cert myself

See also: https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.tls.html