Compare commits

...

4 Commits

Author SHA1 Message Date
00c9634579
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>
2023-05-21 11:00:35 +02:00
fd3abc6aec
Rename test scripts
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-05-21 10:57:51 +02:00
f2e6df7448
Implement test.ping
Wait for minions to respond to test.ping before attempting a state.apply.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-05-21 10:42:09 +02:00
3ad04b0e1a
Add license headers to test scripts
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-05-21 10:41:36 +02:00
10 changed files with 181 additions and 2 deletions

View File

@ -141,11 +141,21 @@ def vagrant_sshconfig(outfile):
with open(outfile, 'w') as fh:
fh.write(ssh_config)
def runapply(state, target):
def _saltcmd(target):
if target == 'local':
saltcmd = 'salt-call --local'
else:
saltcmd = 'salt {}'.format(target)
saltcmd = 'salt -t10 {}'.format(target)
return saltcmd
def runping(target):
saltcmd = _saltcmd(target)
sshout = v.ssh(command='sudo {} test.ping'.format(saltcmd))
log.info('\n{}\n'.format(str(sshout)))
return sshout
def runapply(state, target):
saltcmd = _saltcmd(target)
sshout = v.ssh(command='sudo {} state.apply {}'.format(saltcmd, state))
log.info('\n{}\n'.format(str(sshout)))
@ -241,6 +251,11 @@ def main_interactive():
log.debug('state.apply requested')
if masters is not None:
target = 'scullery-*'
count = 0
while not runping(target):
if count == 5:
_abort('Unable to reach minions')
count += 1
else:
target = 'local'
runapply(testconf['apply'], target)

View File

@ -1,3 +1,16 @@
"""
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
#import os
import dotenv
@ -108,6 +121,27 @@ def test_envfile(script_runner, script, config, suite, masters, minions):
assert os.path.isfile(envfile) is False
@pytest.mark.parametrize('config', ['complete'], indirect=True)
def test_test_undeclared(script_runner, script, config):
result = script_runner.run(script, '--config', config, '--suite', 'one_minion', '--test')
assert not result.success
assert result.stderr.endswith('Tests requested but not declared in suite configuration\n')
@pytest.mark.parametrize('config', ['complete'], indirect=True)
def test_test_undefined(script_runner, script, config):
result = script_runner.run(script, '--config', config, '--suite', 'one_minion_bogus_test', '--test')
assert not result.success
assert result.stderr.endswith('Specified test is not defined\n')
@pytest.mark.parametrize('config', ['complete'], indirect=True)
def test_test_incomplete(script_runner, script, config):
result = script_runner.run(script, '--config', config, '--suite', 'one_minion_bogus_test_2', '--test')
assert not result.success
assert result.stderr.endswith('Incomplete test configuration\n')
@pytest.mark.parametrize('config', ['complete'], indirect=True)
@pytest.mark.parametrize('suite', [
'one_minion',

View File

@ -1,3 +1,16 @@
"""
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
import os
from conftest import loadenv

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
bootstrap=tests/scripts/bootstrap_hello_world.sh
[box.tumbleweed_salt]
name=tumbleweed_salt
bootstrap=tests/scripts/bootstrap_salt.sh
[suite.one_minion]
minions=1
box=tumbleweed
@ -40,6 +44,30 @@ minions=2
masters=1
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]
apply=hello_world
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

@ -1,3 +1,16 @@
"""
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
import os
import libvirt

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