diff --git a/tests/03_test_salt.py b/tests/03_test_salt.py new file mode 100644 index 0000000..d9ef598 --- /dev/null +++ b/tests/03_test_salt.py @@ -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') + diff --git a/tests/configs/complete.ini b/tests/configs/complete.ini index ee795d1..fdee52b 100644 --- a/tests/configs/complete.ini +++ b/tests/configs/complete.ini @@ -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 diff --git a/tests/configs/salt.ini b/tests/configs/salt.ini new file mode 100644 index 0000000..3b2aa11 --- /dev/null +++ b/tests/configs/salt.ini @@ -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 diff --git a/tests/salt/hello_world/pillar/hello_world.sls b/tests/salt/hello_world/pillar/hello_world.sls new file mode 100644 index 0000000..cff37f5 --- /dev/null +++ b/tests/salt/hello_world/pillar/hello_world.sls @@ -0,0 +1 @@ +greeting: 'Hello salted world!' diff --git a/tests/salt/hello_world/states/hello_world.sls b/tests/salt/hello_world/states/hello_world.sls new file mode 100644 index 0000000..c32932c --- /dev/null +++ b/tests/salt/hello_world/states/hello_world.sls @@ -0,0 +1,3 @@ +/srv/hello_world.txt: + file.managed: + - contents_pillar: greeting diff --git a/tests/scripts/bootstrap_salt.sh b/tests/scripts/bootstrap_salt.sh new file mode 100644 index 0000000..73ac37f --- /dev/null +++ b/tests/scripts/bootstrap_salt.sh @@ -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 <