Skip to content

Commit

Permalink
Merge pull request #267 from mirceaulinic/develop
Browse files Browse the repository at this point in the history
Release 2022.10.0
  • Loading branch information
mirceaulinic authored Oct 20, 2022
2 parents e902a6e + da4a9a1 commit db334f5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
tox==3.21.4
tox==3.24.1
black==19.10b0
pylint==2.6.0
SaltPylint==2020.9.28
CherryPy==18.1.0
CherryPy==18.6.1
44 changes: 32 additions & 12 deletions salt_sproxy/_runners/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ def _receive_replies_sync(ret_queue, static_queue, done_queue, progress_bar):
done_queue.put(_SENTINEL)


class PingBatch(Batch):
def __init__(
self, opts, eauth=None, quiet=False, parser=None
): # pylint: disable=super-init-not-called
self.opts = opts
self.eauth = eauth if eauth else {}
self.pub_kwargs = eauth if eauth else {}
self.quiet = quiet
self.local = salt.client.get_local_client(opts['conf_file'])
self.minions, self.ping_gen, self.down_minions = self.gather_minions()
self.options = parser

def _gather_minions(self):
return self.minions, self.ping_gen, self.down_minions


class NoPingBatch(Batch):
'''
Similar to the native Salt Batch. but without issuing test.ping to ensure
Expand All @@ -221,11 +237,11 @@ def __init__(
self.pub_kwargs = eauth if eauth else {}
self.quiet = quiet
self.local = salt.client.get_local_client(opts['conf_file'])
self.minions, self.ping_gen, self.down_minions = self.__gather_minions()
self.minions, self.ping_gen, self.down_minions = self.opts['tgt'], [], []
self.options = parser

def __gather_minions(self):
return self.opts['tgt'], [], []
def gather_minions(self):
return self.minions, self.ping_gen, self.down_minions


# The SProxyMinion class is back-ported from Salt 2019.2.0 (to be released soon)
Expand Down Expand Up @@ -621,9 +637,11 @@ def salt_call(
opts['proxy_test_ping'] = test_ping
opts['proxy_use_cached_grains'] = use_cached_grains
if use_cached_grains:
opts['proxy_cached_grains'] = __salt__['cache.fetch'](
'minions/{}/data'.format(minion_id), 'grains'
cache_data = __salt__['cache.fetch'](
'minions/{}'.format(minion_id), 'data'
)
if cache_data and 'grains' in cache_data:
opts['proxy_cached_grains'] = cache_data['grains']
opts['roster_opts'] = roster_opts
opts['returner'] = returner
if not returner_kwargs:
Expand Down Expand Up @@ -702,17 +720,17 @@ def salt_call(
log.warning(
'Returner %s is not available. Check that the dependencies are properly installed'
)
cache_data = {}
if cache_grains:
log.debug('Caching Grains for %s', minion_id)
log.debug(sa_proxy.opts['grains'])
cache_store = __salt__['cache.store'](
'minions/{}/data'.format(minion_id), 'grains', sa_proxy.opts['grains']
)
cache_data['grains'] = copy.deepcopy(sa_proxy.opts['grains'])
if cache_pillar:
log.debug('Caching Pillar for %s', minion_id)
cached_store = __salt__['cache.store'](
'minions/{}/data'.format(minion_id), 'pillar', sa_proxy.opts['pillar']
)
cache_data['pillar'] = copy.deepcopy(sa_proxy.opts['pillar'])
cached_store = __salt__['cache.store'](
'minions/{}'.format(minion_id), 'data', cache_data
)
return ret, retcode


Expand Down Expand Up @@ -966,7 +984,9 @@ def execute_devices(
batch_opts['ret_config'] = returner_config
batch_opts['ret_kwargs'] = returner_kwargs
if test_ping:
cli_batch = Batch(batch_opts, quiet=True)
cli_batch = PingBatch(batch_opts, quiet=True)
cli_batch.minions, cli_batch.ping_gen, cli_batch.down_minions = cli_batch.gather_minions()
cli_batch.gather_minions = cli_batch._gather_minions
else:
cli_batch = NoPingBatch(batch_opts, quiet=True)
log.debug('Batching detected the following Minions responsive')
Expand Down
9 changes: 6 additions & 3 deletions salt_sproxy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from salt.ext import six
import salt.defaults.exitcodes # pylint: disable=W0611
import salt.utils.stringutils
import salt.version

try:
from salt.utils.files import fopen
Expand Down Expand Up @@ -62,9 +63,11 @@ def run(self):
sys.stdout.write(safe_dump(self.config, default_flow_style=False))
return self.config

# Setup file logging!
self.setup_logfile_logger()
verify_log(self.config)
if salt.version.__saltstack_version__.major < 3005:
# Setup file logging!
self.setup_logfile_logger()
verify_log(self.config)

profiling_enabled = self.options.profiling_enabled
curpath = os.path.dirname(os.path.realpath(__file__))
saltenv = self.config.get('saltenv_cli', self.config.get('saltenv'))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name=name,
version='2021.6.1',
version='2022.10.0',
namespace_packages=['salt_sproxy'],
packages=find_packages(),
author='Mircea Ulinic',
Expand Down

0 comments on commit db334f5

Please sign in to comment.