Implement Salt tests

- test state application on minions
- add Salt file/pillar root bootstrap script
- add Salt state and pillar
- adjust configuration files respectively

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-05-21 10:59:42 +02:00
parent fd3abc6aec
commit 00c9634579
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
6 changed files with 104 additions and 0 deletions

30
tests/03_test_salt.py Normal file
View File

@ -0,0 +1,30 @@
"""
Copyright 2023, Georg Pfuetzenreuter
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
You may not use this work except in compliance with the Licence.
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
---
Testing functions for Scullery - a SaltStack testing tool.
"""
import pytest
@pytest.mark.parametrize('config', ['complete'], indirect=True)
@pytest.mark.parametrize('suite', [
'one_minion_salt',
'two_minions_one_master_salt',
])
def test_salt(script_runner, script, config, suite):
cmd = (script, '--config', config, '--suite', suite)
result = script_runner.run(*cmd, '--debug', '--env', '--test')
# not possible until we have a way to apply without invoking tests
# assert result.success
assert 'Comment: File /srv/hello_world.txt updated' in result.stderr
assert 'Succeeded: 1 (changed=1)' in result.stderr
assert 'DEBUG - main_interactive: state.apply requested' in result.stderr
assert script_runner.run(*cmd, '--stop')

View File

@ -9,6 +9,10 @@ name=tumbleweed
name=tumbleweed_bootstrap name=tumbleweed_bootstrap
bootstrap=tests/scripts/bootstrap_hello_world.sh bootstrap=tests/scripts/bootstrap_hello_world.sh
[box.tumbleweed_salt]
name=tumbleweed_salt
bootstrap=tests/scripts/bootstrap_salt.sh
[suite.one_minion] [suite.one_minion]
minions=1 minions=1
box=tumbleweed box=tumbleweed
@ -40,6 +44,30 @@ minions=2
masters=1 masters=1
box=tumbleweed box=tumbleweed
[suite.one_minion_bogus_test]
minions=1
box=tumbleweed
test=cashew
[suite.one_minion_bogus_test_2]
minions=1
box=tumbleweed
test=bogus
[test.hello] [test.hello]
apply=hello_world apply=hello_world
test=salt/hello_world/tests/test_hello.py test=salt/hello_world/tests/test_hello.py
[test.bogus]
apply=cashew
[suite.one_minion_salt]
minions=1
box=tumbleweed_salt
test=hello
[suite.two_minions_one_master_salt]
masters=1
minions=2
box=tumbleweed_salt
test=hello

15
tests/configs/salt.ini Normal file
View File

@ -0,0 +1,15 @@
[box]
bootstrap=tests/scripts/bootstrap_salt.sh
image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/Tumbleweed.x86_64-libvirt.box
[box.tumbleweed]
name=tumbleweed
[suite.one_minion]
minions=1
box=tumbleweed
[suite.two_minions_one_master_bootstrap]
minions=2
masters=1
box=tumbleweed

View File

@ -0,0 +1 @@
greeting: 'Hello salted world!'

View File

@ -0,0 +1,3 @@
/srv/hello_world.txt:
file.managed:
- contents_pillar: greeting

View File

@ -0,0 +1,27 @@
testbase='/vagrant/tests/salt/hello_world'
sls='hello_world.sls'
ln -s "$testbase/states/$sls" /srv/salt/
ln -s "$testbase/pillar/$sls" /srv/pillar/
tee /srv/pillar/top.sls >/dev/null <<EOF
base:
'*':
- hello_world
EOF
if systemctl is-enabled salt-master
then
count=0
until salt -t10 scullery-\* test.ping
do
if [ "$count" = 3 ]
then
logger -s 'No minions connected'
break
fi
echo 'Waiting for minions to connect ...'
sleep 5
count=$((count+1))
done
fi