@@ -207,6 +207,22 @@ def _receive_replies_sync(ret_queue, static_queue, done_queue, progress_bar):
207207 done_queue .put (_SENTINEL )
208208
209209
210+ class PingBatch (Batch ):
211+ def __init__ (
212+ self , opts , eauth = None , quiet = False , parser = None
213+ ): # pylint: disable=super-init-not-called
214+ self .opts = opts
215+ self .eauth = eauth if eauth else {}
216+ self .pub_kwargs = eauth if eauth else {}
217+ self .quiet = quiet
218+ self .local = salt .client .get_local_client (opts ['conf_file' ])
219+ self .minions , self .ping_gen , self .down_minions = self .gather_minions ()
220+ self .options = parser
221+
222+ def _gather_minions (self ):
223+ return self .minions , self .ping_gen , self .down_minions
224+
225+
210226class NoPingBatch (Batch ):
211227 '''
212228 Similar to the native Salt Batch. but without issuing test.ping to ensure
@@ -221,11 +237,11 @@ def __init__(
221237 self .pub_kwargs = eauth if eauth else {}
222238 self .quiet = quiet
223239 self .local = salt .client .get_local_client (opts ['conf_file' ])
224- self .minions , self .ping_gen , self .down_minions = self .__gather_minions ()
240+ self .minions , self .ping_gen , self .down_minions = self .opts [ 'tgt' ], [], []
225241 self .options = parser
226242
227- def __gather_minions (self ):
228- return self .opts [ 'tgt' ], [], []
243+ def gather_minions (self ):
244+ return self .minions , self . ping_gen , self . down_minions
229245
230246
231247# The SProxyMinion class is back-ported from Salt 2019.2.0 (to be released soon)
@@ -621,9 +637,11 @@ def salt_call(
621637 opts ['proxy_test_ping' ] = test_ping
622638 opts ['proxy_use_cached_grains' ] = use_cached_grains
623639 if use_cached_grains :
624- opts [ 'proxy_cached_grains' ] = __salt__ ['cache.fetch' ](
625- 'minions/{}/data ' .format (minion_id ), 'grains '
640+ cache_data = __salt__ ['cache.fetch' ](
641+ 'minions/{}' .format (minion_id ), 'data '
626642 )
643+ if cache_data and 'grains' in cache_data :
644+ opts ['proxy_cached_grains' ] = cache_data ['grains' ]
627645 opts ['roster_opts' ] = roster_opts
628646 opts ['returner' ] = returner
629647 if not returner_kwargs :
@@ -702,17 +720,17 @@ def salt_call(
702720 log .warning (
703721 'Returner %s is not available. Check that the dependencies are properly installed'
704722 )
723+ cache_data = {}
705724 if cache_grains :
706725 log .debug ('Caching Grains for %s' , minion_id )
707726 log .debug (sa_proxy .opts ['grains' ])
708- cache_store = __salt__ ['cache.store' ](
709- 'minions/{}/data' .format (minion_id ), 'grains' , sa_proxy .opts ['grains' ]
710- )
727+ cache_data ['grains' ] = copy .deepcopy (sa_proxy .opts ['grains' ])
711728 if cache_pillar :
712729 log .debug ('Caching Pillar for %s' , minion_id )
713- cached_store = __salt__ ['cache.store' ](
714- 'minions/{}/data' .format (minion_id ), 'pillar' , sa_proxy .opts ['pillar' ]
715- )
730+ cache_data ['pillar' ] = copy .deepcopy (sa_proxy .opts ['pillar' ])
731+ cached_store = __salt__ ['cache.store' ](
732+ 'minions/{}' .format (minion_id ), 'data' , cache_data
733+ )
716734 return ret , retcode
717735
718736
@@ -966,7 +984,9 @@ def execute_devices(
966984 batch_opts ['ret_config' ] = returner_config
967985 batch_opts ['ret_kwargs' ] = returner_kwargs
968986 if test_ping :
969- cli_batch = Batch (batch_opts , quiet = True )
987+ cli_batch = PingBatch (batch_opts , quiet = True )
988+ cli_batch .minions , cli_batch .ping_gen , cli_batch .down_minions = cli_batch .gather_minions ()
989+ cli_batch .gather_minions = cli_batch ._gather_minions
970990 else :
971991 cli_batch = NoPingBatch (batch_opts , quiet = True )
972992 log .debug ('Batching detected the following Minions responsive' )
0 commit comments