mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 08:35:21 +00:00
Merge pull request #51900 from max-arnold/saltutil-sync
Add missing saltutil.sync_* states
This commit is contained in:
parent
d534a79333
commit
752023aac4
@ -255,6 +255,7 @@ state modules
|
||||
rvm
|
||||
salt_proxy
|
||||
saltmod
|
||||
saltutil
|
||||
schedule
|
||||
selinux
|
||||
serverdensity_device
|
||||
|
6
doc/ref/states/all/salt.states.saltutil.rst
Normal file
6
doc/ref/states/all/salt.states.saltutil.rst
Normal file
@ -0,0 +1,6 @@
|
||||
====================
|
||||
salt.states.saltutil
|
||||
====================
|
||||
|
||||
.. automodule:: salt.states.saltutil
|
||||
:members:
|
@ -69,6 +69,16 @@ dynamic modules when states are run. To disable this behavior set
|
||||
When dynamic modules are autoloaded via states, only the modules defined in the
|
||||
same saltenvs as the states currently being run.
|
||||
|
||||
Also it is possible to use the explicit ``saltutil.sync_*`` :py:mod:`state functions <salt.states.saltutil>`
|
||||
to sync the modules (previously it was necessary to use the ``module.run`` state):
|
||||
|
||||
.. code-block::yaml
|
||||
|
||||
synchronize_modules:
|
||||
saltutil.sync_modules:
|
||||
- refresh: True
|
||||
|
||||
|
||||
Sync Via the saltutil Module
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -227,6 +227,20 @@ def sync_proxymodules(name, **kwargs):
|
||||
return _sync_single(name, "proxymodules", **kwargs)
|
||||
|
||||
|
||||
def sync_matchers(name, **kwargs):
|
||||
'''
|
||||
Performs the same task as saltutil.sync_matchers module
|
||||
See :mod:`saltutil module for full list of options <salt.modules.saltutil>`
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
sync_everything:
|
||||
saltutil.sync_matchers:
|
||||
- refresh: True
|
||||
'''
|
||||
return _sync_single(name, "matchers", **kwargs)
|
||||
|
||||
|
||||
def sync_renderers(name, **kwargs):
|
||||
'''
|
||||
Performs the same task as saltutil.sync_renderers module
|
||||
@ -309,3 +323,17 @@ def sync_utils(name, **kwargs):
|
||||
- refresh: True
|
||||
'''
|
||||
return _sync_single(name, "utils", **kwargs)
|
||||
|
||||
|
||||
def sync_serializers(name, **kwargs):
|
||||
'''
|
||||
Performs the same task as saltutil.sync_serializers module
|
||||
See :mod:`saltutil module for full list of options <salt.modules.saltutil>`
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
sync_everything:
|
||||
saltutil.sync_serializers:
|
||||
- refresh: True
|
||||
'''
|
||||
return _sync_single(name, "serializers", **kwargs)
|
||||
|
@ -5,6 +5,8 @@
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import inspect
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
@ -16,7 +18,8 @@ from tests.support.mock import (
|
||||
)
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.states.saltutil as saltutil
|
||||
import salt.states.saltutil as saltutil_state
|
||||
import salt.modules.saltutil as saltutil_module
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@ -25,26 +28,29 @@ class Saltutil(TestCase, LoaderModuleMockMixin):
|
||||
Test cases for salt.states.saltutil
|
||||
'''
|
||||
def setup_loader_modules(self):
|
||||
return {saltutil: {'__opts__': {'test': False}}}
|
||||
return {saltutil_state: {'__opts__': {'test': False}}}
|
||||
|
||||
def test_saltutil_sync_all_nochange(self):
|
||||
sync_output = {
|
||||
"clouds": [],
|
||||
"engines": [],
|
||||
"grains": [],
|
||||
"beacons": [],
|
||||
"utils": [],
|
||||
"returners": [],
|
||||
"modules": [],
|
||||
"renderers": [],
|
||||
"log_handlers": [],
|
||||
"thorium": [],
|
||||
"states": [],
|
||||
"sdb": [],
|
||||
"proxymodules": [],
|
||||
"output": [],
|
||||
"pillar": []
|
||||
}
|
||||
sync_output = {
|
||||
'clouds': [],
|
||||
'engines': [],
|
||||
'executors': [],
|
||||
'grains': [],
|
||||
'beacons': [],
|
||||
'utils': [],
|
||||
'returners': [],
|
||||
'modules': [],
|
||||
'renderers': [],
|
||||
'log_handlers': [],
|
||||
'thorium': [],
|
||||
'states': [],
|
||||
'sdb': [],
|
||||
'proxymodules': [],
|
||||
'output': [],
|
||||
'pillar': [],
|
||||
'matchers': [],
|
||||
'serializers': [],
|
||||
}
|
||||
state_id = 'somename'
|
||||
state_result = {'changes': {},
|
||||
'comment': 'No updates to sync',
|
||||
@ -53,28 +59,31 @@ class Saltutil(TestCase, LoaderModuleMockMixin):
|
||||
}
|
||||
|
||||
mock_moduleout = MagicMock(return_value=sync_output)
|
||||
with patch.dict(saltutil.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
result = saltutil.sync_all(state_id, refresh=True)
|
||||
with patch.dict(saltutil_state.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
result = saltutil_state.sync_all(state_id, refresh=True)
|
||||
self.assertEqual(result, state_result)
|
||||
|
||||
def test_saltutil_sync_all_test(self):
|
||||
sync_output = {
|
||||
"clouds": [],
|
||||
"engines": [],
|
||||
"grains": [],
|
||||
"beacons": [],
|
||||
"utils": [],
|
||||
"returners": [],
|
||||
"modules": [],
|
||||
"renderers": [],
|
||||
"log_handlers": [],
|
||||
"thorium": [],
|
||||
"states": [],
|
||||
"sdb": [],
|
||||
"proxymodules": [],
|
||||
"output": [],
|
||||
"pillar": []
|
||||
}
|
||||
def test_saltutil_sync_all_test(self):
|
||||
sync_output = {
|
||||
'clouds': [],
|
||||
'engines': [],
|
||||
'executors': [],
|
||||
'grains': [],
|
||||
'beacons': [],
|
||||
'utils': [],
|
||||
'returners': [],
|
||||
'modules': [],
|
||||
'renderers': [],
|
||||
'log_handlers': [],
|
||||
'thorium': [],
|
||||
'states': [],
|
||||
'sdb': [],
|
||||
'proxymodules': [],
|
||||
'output': [],
|
||||
'pillar': [],
|
||||
'matchers': [],
|
||||
'serializers': [],
|
||||
}
|
||||
state_id = 'somename'
|
||||
state_result = {'changes': {},
|
||||
'comment': 'saltutil.sync_all would have been run',
|
||||
@ -83,30 +92,33 @@ class Saltutil(TestCase, LoaderModuleMockMixin):
|
||||
}
|
||||
|
||||
mock_moduleout = MagicMock(return_value=sync_output)
|
||||
with patch.dict(saltutil.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
with patch.dict(saltutil.__opts__, {"test": True}):
|
||||
result = saltutil.sync_all(state_id, refresh=True)
|
||||
with patch.dict(saltutil_state.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
with patch.dict(saltutil_state.__opts__, {'test': True}):
|
||||
result = saltutil_state.sync_all(state_id, refresh=True)
|
||||
self.assertEqual(result, state_result)
|
||||
|
||||
|
||||
def test_saltutil_sync_all_change(self):
|
||||
sync_output = {
|
||||
"clouds": [],
|
||||
"engines": [],
|
||||
"grains": [],
|
||||
"beacons": [],
|
||||
"utils": [],
|
||||
"returners": [],
|
||||
"modules": ["modules.file"],
|
||||
"renderers": [],
|
||||
"log_handlers": [],
|
||||
"thorium": [],
|
||||
"states": ["states.saltutil", "states.ssh_auth"],
|
||||
"sdb": [],
|
||||
"proxymodules": [],
|
||||
"output": [],
|
||||
"pillar": []
|
||||
}
|
||||
sync_output = {
|
||||
'clouds': [],
|
||||
'engines': [],
|
||||
'executors': [],
|
||||
'grains': [],
|
||||
'beacons': [],
|
||||
'utils': [],
|
||||
'returners': [],
|
||||
'modules': ['modules.file'],
|
||||
'renderers': [],
|
||||
'log_handlers': [],
|
||||
'thorium': [],
|
||||
'states': ['states.saltutil', 'states.ssh_auth'],
|
||||
'sdb': [],
|
||||
'proxymodules': [],
|
||||
'output': [],
|
||||
'pillar': [],
|
||||
'matchers': [],
|
||||
'serializers': [],
|
||||
}
|
||||
state_id = 'somename'
|
||||
state_result = {'changes': {'modules': ['modules.file'],
|
||||
'states': ['states.saltutil', 'states.ssh_auth']},
|
||||
@ -116,6 +128,22 @@ class Saltutil(TestCase, LoaderModuleMockMixin):
|
||||
}
|
||||
|
||||
mock_moduleout = MagicMock(return_value=sync_output)
|
||||
with patch.dict(saltutil.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
result = saltutil.sync_all(state_id, refresh=True)
|
||||
with patch.dict(saltutil_state.__salt__, {'saltutil.sync_all': mock_moduleout}):
|
||||
result = saltutil_state.sync_all(state_id, refresh=True)
|
||||
self.assertEqual(result, state_result)
|
||||
|
||||
def test_saltutil_sync_states_should_match_saltutil_module(self):
|
||||
module_functions = [
|
||||
f[0] for f in inspect.getmembers(saltutil_module, inspect.isfunction)
|
||||
if f[0].startswith('sync_')
|
||||
]
|
||||
state_functions = [
|
||||
f[0] for f in inspect.getmembers(saltutil_state, inspect.isfunction)
|
||||
if f[0].startswith('sync_')
|
||||
]
|
||||
for fn in module_functions:
|
||||
self.assertIn(
|
||||
fn,
|
||||
state_functions,
|
||||
msg='modules.saltutil.{} has no matching state in states.saltutil'.format(fn)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user