Raise clean error when no minions targeted in batch mode

Closes #26343
This commit is contained in:
Mike Place 2015-08-18 14:46:49 -06:00
parent c1458980f3
commit 1600f3eccd
2 changed files with 14 additions and 6 deletions

View file

@ -13,6 +13,7 @@ import copy
# Import salt libs
import salt.client
import salt.output
import salt.exceptions
from salt.utils import print_cli
from salt.ext.six.moves import range
@ -47,11 +48,14 @@ class Batch(object):
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)
return (list(fret), ping_gen)
try:
for ret in ping_gen:
m = next(ret.iterkeys())
if m is not None:
fret.add(m)
return (list(fret), ping_gen)
except StopIteration:
raise salt.exceptions.SaltClientError('No minions matched the target.')
def get_bnum(self):
'''

View file

@ -94,7 +94,11 @@ class SaltCMD(parsers.SaltCMDOptionParser):
self._output_ret(ret, '')
else:
batch = salt.cli.batch.Batch(self.config, eauth=eauth)
try:
batch = salt.cli.batch.Batch(self.config, eauth=eauth)
except salt.exceptions.SaltClientError as exc:
# We will print errors to the console further down the stack
sys.exit(1)
# Printing the output is already taken care of in run() itself
for res in batch.run():
if self.options.failhard: