Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Port #52773 and #51427 #55190

Merged
merged 3 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/topics/development/modules/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 <salt.modules.saltutil>` and
:py:mod:`runner functions <salt.runners.saltutil>` can be used to sync modules
to minions and the master, respectively.
Expand Down Expand Up @@ -120,7 +120,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
============
Expand All @@ -139,7 +139,7 @@ Cache ``salt.cache`` (:ref:`index <all-salt.cache>`) ``
Cloud ``salt.cloud.clouds`` (:ref:`index <all-salt.clouds>`) ``clouds`` ``cloud_dirs``
Engine ``salt.engines`` (:ref:`index <engines>`) ``engines`` ``engines_dirs``
Execution ``salt.modules`` (:ref:`index <all-salt.modules>`) ``modules`` ``module_dirs``
Executor ``salt.executors`` (:ref:`index <all-salt.executors>`) ``executors`` [#no-fs]_ ``executor_dirs``
Executor ``salt.executors`` (:ref:`index <all-salt.executors>`) ``executors`` ``executor_dirs``
File Server ``salt.fileserver`` (:ref:`index <file-server>`) ``fileserver`` ``fileserver_dirs``
Grain ``salt.grains`` (:ref:`index <all-salt.grains>`) ``grains`` ``grains_dirs``
Log Handler ``salt.log.handlers`` (:ref:`index <external-logging-handlers>`) ``log_handlers`` ``log_handlers_dirs``
Expand Down
2 changes: 1 addition & 1 deletion salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def gen_modules(self, initial_load=False):
# self.matcher = Matcher(self.opts, self.functions)
self.matchers = salt.loader.matchers(self.opts)
self.functions['sys.reload_modules'] = self.gen_modules
self.executors = salt.loader.executors(self.opts, self.functions)
self.executors = salt.loader.executors(self.opts, self.functions, proxy=self.proxy)

@staticmethod
def process_schedule(minion, loop_interval):
Expand Down
40 changes: 40 additions & 0 deletions salt/modules/saltutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,45 @@ def sync_pillar(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blackl
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
<states-top>` will be checked for log handlers 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 log handlers 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 sync_all(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blacklist=None):
'''
.. versionchanged:: 2015.8.11,2016.3.2
Expand Down Expand Up @@ -978,6 +1017,7 @@ def sync_all(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blacklist
ret['output'] = sync_output(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['utils'] = sync_utils(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['log_handlers'] = sync_log_handlers(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['executors'] = sync_executors(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['proxymodules'] = sync_proxymodules(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['engines'] = sync_engines(saltenv, False, extmod_whitelist, extmod_blacklist)
ret['thorium'] = sync_thorium(saltenv, False, extmod_whitelist, extmod_blacklist)
Expand Down
27 changes: 27 additions & 0 deletions salt/runners/saltutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def sync_all(saltenv='base', extmod_whitelist=None, extmod_blacklist=None):
ret['tops'] = sync_tops(saltenv=saltenv, extmod_whitelist=extmod_whitelist, extmod_blacklist=extmod_blacklist)
ret['tokens'] = sync_eauth_tokens(saltenv=saltenv, extmod_whitelist=extmod_whitelist, extmod_blacklist=extmod_blacklist)
ret['serializers'] = sync_serializers(saltenv=saltenv, extmod_whitelist=extmod_whitelist, extmod_blacklist=extmod_blacklist)
ret['executors'] = sync_executors(saltenv=saltenv, extmod_whitelist=extmod_whitelist, extmod_blacklist=extmod_blacklist)
return ret


Expand Down Expand Up @@ -607,3 +608,29 @@ def sync_serializers(saltenv='base', extmod_whitelist=None, extmod_blacklist=Non
'''
return salt.utils.extmods.sync(__opts__, 'serializers', saltenv=saltenv, extmod_whitelist=extmod_whitelist,
extmod_blacklist=extmod_blacklist)[0]


def sync_executors(saltenv='base', extmod_whitelist=None, extmod_blacklist=None):
'''
.. versionadded:: Neon

Sync executor modules from ``salt://_executors`` to the master

saltenv : base
The fileserver environment from which to sync. To sync from more than
one environment, pass a comma-separated list.

extmod_whitelist : None
comma-seperated list of modules to sync

extmod_blacklist : None
comma-seperated list of modules to blacklist based on type

CLI Example:

.. code-block:: bash

salt-run saltutil.sync_executors
'''
return salt.utils.extmods.sync(__opts__, 'executors', saltenv=saltenv, extmod_whitelist=extmod_whitelist,
extmod_blacklist=extmod_blacklist)[0]
14 changes: 14 additions & 0 deletions salt/states/saltutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ def sync_grains(name, **kwargs):
return _sync_single(name, "grains", **kwargs)


def sync_executors(name, **kwargs):
'''
Performs the same task as saltutil.sync_executors module
See :mod:`saltutil module for full list of options <salt.modules.saltutil>`

.. code-block:: yaml

sync_everything:
saltutil.sync_executors:
- refresh: True
'''
return _sync_single(name, "executors", **kwargs)


def sync_log_handlers(name, **kwargs):
'''
Performs the same task as saltutil.sync_log_handlers module
Expand Down
1 change: 1 addition & 0 deletions tests/integration/executors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
10 changes: 10 additions & 0 deletions tests/integration/files/file/base/_executors/arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-


def __virtual__():
return True


def execute(*args, **kwargs):
# we use the dunder to assert the loader is provided minionmods
return __salt__['test.arg']('test.arg fired')
24 changes: 24 additions & 0 deletions tests/integration/minion/test_executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging

# Import Salt Testing libs
from tests.support.case import ModuleCase, ShellCase

log = logging.getLogger(__name__)


class ExecutorTest(ModuleCase, ShellCase):

def setup(self):
self.run_function('saltutil.sync_all')

def test_executor(self):
'''
test that dunders are set
'''
data = self.run_call('test.arg --module-executors=arg')
self.assertIn('test.arg fired', "".join(data))
4 changes: 4 additions & 0 deletions tests/integration/modules/test_saltutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_sync_all(self):
'states': [],
'sdb': [],
'proxymodules': [],
'executors': [],
'output': [],
'thorium': [],
'serializers': []}
Expand All @@ -121,6 +122,7 @@ def test_sync_all_whitelist(self):
'states': [],
'sdb': [],
'proxymodules': [],
'executors': [],
'output': [],
'thorium': [],
'serializers': []}
Expand All @@ -147,6 +149,7 @@ def test_sync_all_blacklist(self):
'states': [],
'sdb': [],
'proxymodules': [],
'executors': [],
'output': [],
'thorium': [],
'serializers': []}
Expand All @@ -163,6 +166,7 @@ def test_sync_all_blacklist_and_whitelist(self):
'beacons': [],
'utils': [],
'returners': [],
'executors': [],
'modules': [],
'renderers': [],
'log_handlers': [],
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_module_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def test_module_name_source_match(self):
'integration.master.test_event_return',
'integration.minion.test_blackout',
'integration.minion.test_pillar',
'integration.minion.test_executor',
'integration.minion.test_timeout',
'integration.modules.test_decorators',
'integration.modules.test_pkg',
Expand Down