From ea9edb8eeba5ca43ccb9e378857608046afc08b8 Mon Sep 17 00:00:00 2001 From: Max Arnold Date: Wed, 30 Jan 2019 19:59:30 +0700 Subject: [PATCH] Allow loading executor modules from the fileserver --- doc/topics/development/modules/index.rst | 8 ++--- salt/modules/saltutil.py | 40 ++++++++++++++++++++++ salt/states/saltutil.py | 14 ++++++++ tests/integration/modules/test_saltutil.py | 12 ++++--- tests/unit/states/test_saltutil.py | 3 ++ 5 files changed, 69 insertions(+), 8 deletions(-) diff --git a/doc/topics/development/modules/index.rst b/doc/topics/development/modules/index.rst index e95a485759c3..0b037bc5e8c1 100644 --- a/doc/topics/development/modules/index.rst +++ b/doc/topics/development/modules/index.rst @@ -73,7 +73,7 @@ Sync Via the saltutil Module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The saltutil module has a number of functions that can be used to sync all -or specific dynamic modules. The ``saltutil.sync_*`` +or specific dynamic modules. The ``saltutil.sync_*`` :py:mod:`execution functions ` and :py:mod:`runner functions ` can be used to sync modules to minions and the master, respectively. @@ -110,7 +110,7 @@ This is done via setuptools entry points: ) Note that these are not synced from the Salt Master to the Minions. They must be -installed indepdendently on each Minion. +installed independently on each Minion. Module Types ============ @@ -129,7 +129,7 @@ Cache ``salt.cache`` (:ref:`index `) `` Cloud ``salt.cloud.clouds`` (:ref:`index `) ``clouds`` ``cloud_dirs`` Engine ``salt.engines`` (:ref:`index `) ``engines`` ``engines_dirs`` Execution ``salt.modules`` (:ref:`index `) ``modules`` ``module_dirs`` -Executor ``salt.executors`` (:ref:`index `) ``executors`` [#no-fs]_ ``executor_dirs`` +Executor ``salt.executors`` (:ref:`index `) ``executors`` ``executor_dirs`` File Server ``salt.fileserver`` (:ref:`index `) ``fileserver`` ``fileserver_dirs`` Grain ``salt.grains`` (:ref:`index `) ``grains`` ``grains_dirs`` Log Handler ``salt.log.handlers`` (:ref:`index `) ``log_handlers`` ``log_handlers_dirs`` @@ -395,7 +395,7 @@ the state system. Util ---- -Just utility modules to use with other modules via ``__utils__`` (see +Just utility modules to use with other modules via ``__utils__`` (see :ref:`Dunder Dictionaries `). Wheel diff --git a/salt/modules/saltutil.py b/salt/modules/saltutil.py index 4c159dc2aea0..b458f6d81a13 100644 --- a/salt/modules/saltutil.py +++ b/salt/modules/saltutil.py @@ -817,6 +817,45 @@ def sync_serializers(saltenv=None, refresh=True, extmod_whitelist=None, extmod_b return ret +def sync_executors(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blacklist=None): + ''' + .. versionadded:: Neon + + Sync executors from ``salt://_executors`` to the minion + + saltenv + The fileserver environment from which to sync. To sync from more than + one environment, pass a comma-separated list. + + If not passed, then all environments configured in the :ref:`top files + ` will be checked for executor modules to sync. If no top + files are found, then the ``base`` environment will be synced. + + refresh : True + If ``True``, refresh the available execution modules on the minion. + This refresh will be performed even if no new serializer modules are + synced. Set to ``False`` to prevent this refresh. + + extmod_whitelist : None + comma-seperated list of modules to sync + + extmod_blacklist : None + comma-seperated list of modules to blacklist based on type + + CLI Examples: + + .. code-block:: bash + + salt '*' saltutil.sync_executors + salt '*' saltutil.sync_executors saltenv=dev + salt '*' saltutil.sync_executors saltenv=base,dev + ''' + ret = _sync('executors', saltenv, extmod_whitelist, extmod_blacklist) + if refresh: + refresh_modules() + return ret + + def list_extmods(): ''' .. versionadded:: 2017.7.0 @@ -986,6 +1025,7 @@ def sync_all(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blacklist ret['thorium'] = sync_thorium(saltenv, False, extmod_whitelist, extmod_blacklist) ret['serializers'] = sync_serializers(saltenv, False, extmod_whitelist, extmod_blacklist) ret['matchers'] = sync_matchers(saltenv, False, extmod_whitelist, extmod_blacklist) + ret['executors'] = sync_executors(saltenv, False, extmod_whitelist, extmod_blacklist) if __opts__['file_client'] == 'local': ret['pillar'] = sync_pillar(saltenv, False, extmod_whitelist, extmod_blacklist) if refresh: diff --git a/salt/states/saltutil.py b/salt/states/saltutil.py index 99952a1b7d1b..9e4fd99ece40 100644 --- a/salt/states/saltutil.py +++ b/salt/states/saltutil.py @@ -129,6 +129,20 @@ def sync_engines(name, **kwargs): return _sync_single(name, "engines", **kwargs) +def sync_executors(name, **kwargs): + ''' + Performs the same task as saltutil.sync_executors module + See :mod:`saltutil module for full list of options ` + + .. code-block:: yaml + + sync_everything: + saltutil.sync_executors: + - refresh: True + ''' + return _sync_single(name, "executors", **kwargs) + + def sync_grains(name, **kwargs): ''' Performs the same task as saltutil.sync_grains module diff --git a/tests/integration/modules/test_saltutil.py b/tests/integration/modules/test_saltutil.py index 2e0c1706c39e..d60039682c86 100644 --- a/tests/integration/modules/test_saltutil.py +++ b/tests/integration/modules/test_saltutil.py @@ -107,7 +107,8 @@ def test_sync_all(self): 'proxymodules': [], 'output': [], 'thorium': [], - 'serializers': []} + 'serializers': [], + 'executors': []} ret = self.run_function('saltutil.sync_all') self.assertEqual(ret, expected_return) @@ -130,7 +131,8 @@ def test_sync_all_whitelist(self): 'proxymodules': [], 'output': [], 'thorium': [], - 'serializers': []} + 'serializers': [], + 'executors': []} ret = self.run_function('saltutil.sync_all', extmod_whitelist={'modules': ['salttest']}) self.assertEqual(ret, expected_return) @@ -156,7 +158,8 @@ def test_sync_all_blacklist(self): 'proxymodules': [], 'output': [], 'thorium': [], - 'serializers': []} + 'serializers': [], + 'executors': []} ret = self.run_function('saltutil.sync_all', extmod_blacklist={'modules': ['runtests_decorators']}) self.assertEqual(ret, expected_return) @@ -179,7 +182,8 @@ def test_sync_all_blacklist_and_whitelist(self): 'proxymodules': [], 'output': [], 'thorium': [], - 'serializers': []} + 'serializers': [], + 'executors': []} ret = self.run_function('saltutil.sync_all', extmod_whitelist={'modules': ['runtests_decorators']}, extmod_blacklist={'modules': ['runtests_decorators']}) self.assertEqual(ret, expected_return) diff --git a/tests/unit/states/test_saltutil.py b/tests/unit/states/test_saltutil.py index 93056f17da19..222b2bd10ce5 100644 --- a/tests/unit/states/test_saltutil.py +++ b/tests/unit/states/test_saltutil.py @@ -31,6 +31,7 @@ def test_saltutil_sync_all_nochange(self): sync_output = { 'clouds': [], 'engines': [], + 'executors': [], 'grains': [], 'beacons': [], 'utils': [], @@ -61,6 +62,7 @@ def test_saltutil_sync_all_test(self): sync_output = { 'clouds': [], 'engines': [], + 'executors': [], 'grains': [], 'beacons': [], 'utils': [], @@ -92,6 +94,7 @@ def test_saltutil_sync_all_change(self): sync_output = { 'clouds': [], 'engines': [], + 'executors': [], 'grains': [], 'beacons': [], 'utils': [],