Merge pull request #24093 from msteed/issue-23464

Make LocalClient.cmd_iter_no_block() not block
This commit is contained in:
Nicole Thomas 2015-05-25 09:56:41 -06:00
commit 39a8f30f06
2 changed files with 25 additions and 23 deletions

View file

@ -42,18 +42,13 @@ class Batch(object):
else:
args.append(self.opts.get('expr_form', 'glob'))
ping_gen = self.local.cmd_iter_no_block(*args, **self.eauth)
wait_until = time.time() + self.opts['timeout']
ping_gen = self.local.cmd_iter(*args, **self.eauth)
fret = set()
for ret in ping_gen:
m = next(ret.iterkeys())
if m is not None:
fret.add(m)
if time.time() > wait_until:
break
if m is None:
time.sleep(0.1)
return (list(fret), ping_gen)
def get_bnum(self):

View file

@ -385,8 +385,8 @@ class LocalClient(object):
.. code-block:: python
>>> returns = local.cmd_batch('*', 'state.highstate', bat='10%')
>>> for return in returns:
... print return
>>> for ret in returns:
... print(ret)
{'jerry': {...}}
{'dave': {...}}
{'stewart': {...}}
@ -611,13 +611,13 @@ class LocalClient(object):
The function signature is the same as :py:meth:`cmd` with the
following exceptions.
:return: A generator
:return: A generator yielding the individual minion returns
.. code-block:: python
>>> ret = local.cmd_iter('*', 'test.ping')
>>> for i in ret:
... print i
... print(i)
{'jerry': {'ret': True}}
{'dave': {'ret': True}}
{'stewart': {'ret': True}}
@ -637,9 +637,9 @@ class LocalClient(object):
else:
for fn_ret in self.get_iter_returns(pub_data['jid'],
pub_data['minions'],
self._get_timeout(timeout),
tgt,
expr_form,
timeout=self._get_timeout(timeout),
tgt=tgt,
tgt_type=expr_form,
**kwargs):
if not fn_ret:
continue
@ -656,19 +656,21 @@ class LocalClient(object):
kwarg=None,
**kwargs):
'''
Blocks while waiting for individual minions to return.
Yields the individual minion returns as they come in, or None
when no returns are available.
The function signature is the same as :py:meth:`cmd` with the
following exceptions.
:returns: None until the next minion returns. This allows for actions
to be injected in between minion returns.
:returns: A generator yielding the individual minion returns, or None
when no returns are available. This allows for actions to be
injected in between minion returns.
.. code-block:: python
>>> ret = local.cmd_iter('*', 'test.ping')
>>> ret = local.cmd_iter_no_block('*', 'test.ping')
>>> for i in ret:
... print i
... print(i)
None
{'jerry': {'ret': True}}
{'dave': {'ret': True}}
@ -690,9 +692,10 @@ class LocalClient(object):
else:
for fn_ret in self.get_iter_returns(pub_data['jid'],
pub_data['minions'],
timeout,
tgt,
expr_form,
timeout=timeout,
tgt=tgt,
tgt_type=expr_form,
block=False,
**kwargs):
yield fn_ret
@ -833,6 +836,7 @@ class LocalClient(object):
tgt='*',
tgt_type='glob',
expect_minions=False,
block=True,
**kwargs):
'''
Watch the event system and return job data as it comes in
@ -995,7 +999,10 @@ class LocalClient(object):
break
# don't spin
time.sleep(0.01)
if block:
time.sleep(0.01)
else:
yield
if expect_minions:
for minion in list((minions - found)):
yield {minion: {'failed': True}}
@ -1238,7 +1245,7 @@ class LocalClient(object):
connected_minions = salt.utils.minions.CkMinions(self.opts).connected_ids()
if connected_minions and id_ not in connected_minions:
yield {id_: {'out': 'no_return',
'ret': 'Minion did not return. [Not connected]'}}
'ret': 'Minion did not return. [Not connected]'}}
else:
yield({
id_: {