saltfactories.utils.functional#
Salt functional testing support.
- class saltfactories.utils.functional.Loaders(opts, loaded_base_name=None)[source]#
Bases:
object
This class provides the required functionality for functional testing against the salt loaders.
- Parameters:
opts (dict) – The options dictionary to load the salt loaders.
Example usage:
import salt.config from saltfactories.utils.functional import Loaders @pytest.fixture(scope="module") def minion_opts(): return salt.config.minion_config(None) @pytest.fixture(scope="module") def loaders(minion_opts): return Loaders(minion_opts) @pytest.fixture(autouse=True) def reset_loaders_state(loaders): try: # Run the tests yield finally: # Reset the loaders state loaders.reset_state()
- property grains#
The grains loaded by the salt loader.
- property utils#
The utils loaded by the salt loader.
- property modules#
The execution modules loaded by the salt loader.
- property serializers#
The serializers loaded by the salt loader.
- property states#
The state modules loaded by the salt loader.
- property pillar#
The pillar loaded by the salt loader.
- class saltfactories.utils.functional.StateResult(raw)[source]#
Bases:
object
This class wraps a single salt state return into a more pythonic object in order to simplify assertions.
- Parameters:
raw (dict) – A single salt state return result
def test_user_absent(loaders): ret = loaders.states.user.absent(name=random_string("account-", uppercase=False)) assert ret.result is True
- property run_num#
The
__run_num__
key on the full state return dictionary.
- property id#
The
__id__
key on the full state return dictionary.
- property name#
The
name
key on the full state return dictionary.
- property result#
The
result
key on the full state return dictionary.
- property changes#
The
changes
key on the full state return dictionary.
- property comment: MatchString#
The
comment
key on the full state return dictionary.
- property warnings#
The
warnings
key on the full state return dictionary.
- class saltfactories.utils.functional.StateFunction(proxy_func, state_func)[source]#
Bases:
object
Salt state module functions wrapper.
Simple wrapper around Salt’s state execution module functions which actually proxies the call through Salt’s
state.single
execution module
- class saltfactories.utils.functional.MultiStateResult(raw)[source]#
Bases:
object
Multiple state returns wrapper class.
This class wraps multiple salt state returns, for example, running the
state.sls
execution module, into a more pythonic object in order to simplify assertions- Parameters:
raw (dict,list) – The multiple salt state returns result, a dictionary on success or a list on failure
Example usage on the test suite:
def test_issue_1876_syntax_error(loaders, state_tree, tmp_path): testfile = tmp_path / "issue-1876.txt" sls_contents = """ {}: file: - managed - source: salt://testfile file.append: - text: foo """.format( testfile ) with pytest.helpers.temp_file("issue-1876.sls", sls_contents, state_tree): ret = loaders.modules.state.sls("issue-1876") assert ret.failed errmsg = ( "ID '{}' in SLS 'issue-1876' contains multiple state declarations of the" " same type".format(testfile) ) assert errmsg in ret.errors def test_pydsl(loaders, state_tree, tmp_path): testfile = tmp_path / "testfile" sls_contents = """ #!pydsl state("{}").file("touch") """.format( testfile ) with pytest.helpers.temp_file("pydsl.sls", sls_contents, state_tree): ret = loaders.modules.state.sls("pydsl") for staterun in ret: assert staterun.result is True assert testfile.exists()
- property failed#
Return
True
orFalse
if the multiple state run was not successful.
- property errors#
Return the list of errors in case the multiple state run was not successful.
- class saltfactories.utils.functional.StateModuleFuncWrapper(func, wrapper)[source]#
Bases:
object
This class simply wraps a single or multiple state returns into a more pythonic object.
StateResult
or py:class:~saltfactories.utils.functional.MultiStateResult- Parameters:
func (callable) – A salt loader function
wrapper (StateResult,MultiStateResult) – The wrapper to use for the return of the salt loader function’s return