Compare commits
4 Commits
d37bd67b2e
...
00c9634579
Author | SHA1 | Date | |
---|---|---|---|
00c9634579 | |||
fd3abc6aec | |||
f2e6df7448 | |||
3ad04b0e1a |
19
scullery.py
19
scullery.py
@ -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)
|
||||
|
@ -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',
|
@ -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
30
tests/03_test_salt.py
Normal 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')
|
||||
|
@ -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
15
tests/configs/salt.ini
Normal 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
|
@ -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
|
||||
|
1
tests/salt/hello_world/pillar/hello_world.sls
Normal file
1
tests/salt/hello_world/pillar/hello_world.sls
Normal file
@ -0,0 +1 @@
|
||||
greeting: 'Hello salted world!'
|
3
tests/salt/hello_world/states/hello_world.sls
Normal file
3
tests/salt/hello_world/states/hello_world.sls
Normal file
@ -0,0 +1,3 @@
|
||||
/srv/hello_world.txt:
|
||||
file.managed:
|
||||
- contents_pillar: greeting
|
27
tests/scripts/bootstrap_salt.sh
Normal file
27
tests/scripts/bootstrap_salt.sh
Normal 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
|
Loading…
x
Reference in New Issue
Block a user