File 0051-Allows-to-set-timeout-and-gather_job_timeout-via-kwa.patch of Package salt.4663

From 93d31670abd34fa34d3d2973a61f553e6d7fd94f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Tue, 14 Mar 2017 16:01:07 +0000
Subject: [PATCH 51/51] Allows to set 'timeout' and 'gather_job_timeout' via
 kwargs

Allows to set custom timeouts for 'manage.up' and 'manage.status'
---
 salt/client/__init__.py | 12 +++++++-----
 salt/runners/manage.py  | 19 +++++++++++++++----
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/salt/client/__init__.py b/salt/client/__init__.py
index 1373f00..7665cd4 100644
--- a/salt/client/__init__.py
+++ b/salt/client/__init__.py
@@ -188,12 +188,12 @@ class LocalClient(object):
         # Looks like the timeout is invalid, use config
         return self.opts['timeout']
 
-    def gather_job_info(self, jid, tgt, tgt_type):
+    def gather_job_info(self, jid, tgt, tgt_type, **kwargs):
         '''
         Return the information about a given job
         '''
         log.debug('Checking whether jid {0} is still running'.format(jid))
-        timeout = self.opts['gather_job_timeout']
+        timeout = kwargs.get('gather_job_timeout', self.opts['gather_job_timeout'])
 
         pub_data = self.run_job(tgt,
                                 'saltutil.find_job',
@@ -848,6 +848,7 @@ class LocalClient(object):
 
         if timeout is None:
             timeout = self.opts['timeout']
+        gather_job_timeout = kwargs.get('gather_job_timeout', self.opts['gather_job_timeout'])
         start = int(time.time())
 
         # timeouts per minion, id_ -> timeout time
@@ -938,7 +939,7 @@ class LocalClient(object):
             # re-do the ping
             if time.time() > timeout_at and minions_running:
                 # since this is a new ping, no one has responded yet
-                jinfo = self.gather_job_info(jid, tgt, tgt_type)
+                jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
                 minions_running = False
                 # if we weren't assigned any jid that means the master thinks
                 # we have nothing to send
@@ -946,7 +947,7 @@ class LocalClient(object):
                     jinfo_iter = []
                 else:
                     jinfo_iter = self.get_returns_no_block('salt/job/{0}'.format(jinfo['jid']))
-                timeout_at = time.time() + self.opts['gather_job_timeout']
+                timeout_at = time.time() + gather_job_timeout
                 # if you are a syndic, wait a little longer
                 if self.opts['order_masters']:
                     timeout_at += self.opts.get('syndic_wait', 1)
@@ -1267,7 +1268,8 @@ class LocalClient(object):
                                          timeout=timeout,
                                          tgt=tgt,
                                          tgt_type=tgt_type,
-                                         expect_minions=(verbose or show_timeout)
+                                         expect_minions=(verbose or show_timeout),
+                                         **kwargs
                                          ):
             return_count = return_count + 1
             if progress:
diff --git a/salt/runners/manage.py b/salt/runners/manage.py
index 240c278..fc3af57 100644
--- a/salt/runners/manage.py
+++ b/salt/runners/manage.py
@@ -30,7 +30,7 @@ from salt.exceptions import SaltClientError
 FINGERPRINT_REGEX = re.compile(r'^([a-f0-9]{2}:){15}([a-f0-9]{2})$')
 
 
-def status(output=True):
+def status(output=True, timeout=None, gather_job_timeout=None):
     '''
     Print the status of all known salt minions
 
@@ -42,8 +42,14 @@ def status(output=True):
     '''
     ret = {}
     client = salt.client.get_local_client(__opts__['conf_file'])
+
+    if not timeout:
+        timeout = __opts__['timeout']
+    if not gather_job_timeout:
+        gather_job_timeout = __opts__['gather_job_timeout']
+
     try:
-        minions = client.cmd('*', 'test.ping', timeout=__opts__['timeout'])
+        minions = client.cmd('*', 'test.ping', timeout=timeout, gather_job_timeout=gather_job_timeout)
     except SaltClientError as client_error:
         print(client_error)
         return ret
@@ -128,7 +134,7 @@ def down(removekeys=False):
     return ret
 
 
-def up():  # pylint: disable=C0103
+def up(timeout=None, gather_job_timeout=None):  # pylint: disable=C0103
     '''
     Print a list of all of the minions that are up
 
@@ -137,8 +143,13 @@ def up():  # pylint: disable=C0103
     .. code-block:: bash
 
         salt-run manage.up
+        salt-run manage.up timeout=5 gather_job_timeout=5
     '''
-    ret = status(output=False).get('up', [])
+    ret = status(
+        output=False,
+        timeout=timeout,
+        gather_job_timeout=gather_job_timeout
+    ).get('up', [])
     return ret
 
 
-- 
2.10.1

openSUSE Build Service is sponsored by