mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Return non-zero when group membership change fails, no empty fail list.
There is no point (and it is confusing) to print an empty list when modifying group membership fails, so suppress it. If any membership change fails we should return non-zero. tickets 271, 273, 274
This commit is contained in:
parent
71a032db19
commit
be6aa7039b
@ -844,6 +844,22 @@ class Command(HasParam):
|
||||
continue
|
||||
yield param
|
||||
|
||||
def number_failed(self, failed):
|
||||
"""
|
||||
Return the number of entries in the failed output parameter.
|
||||
|
||||
This is used to determine whether the failed members should be
|
||||
displayed and what the return value should be.
|
||||
"""
|
||||
num_failed = 0
|
||||
for f in failed:
|
||||
if type(failed[f]) is dict:
|
||||
num_failed = num_failed + self.number_failed(failed[f])
|
||||
else:
|
||||
num_failed = num_failed + len(failed[f])
|
||||
|
||||
return num_failed
|
||||
|
||||
def output_for_cli(self, textui, output, *args, **options):
|
||||
"""
|
||||
Generic output method. Prints values the output argument according
|
||||
@ -860,6 +876,8 @@ class Command(HasParam):
|
||||
if not isinstance(output, dict):
|
||||
return
|
||||
|
||||
rv = 0
|
||||
|
||||
order = [p.name for p in self.output_params()]
|
||||
if options.get('all', False):
|
||||
order.insert(0, 'dn')
|
||||
@ -878,6 +896,13 @@ class Command(HasParam):
|
||||
continue
|
||||
result = output[o]
|
||||
|
||||
if o.lower() == 'failed':
|
||||
if self.number_failed(result) == 0:
|
||||
# Don't display an empty failed list
|
||||
continue
|
||||
else:
|
||||
# Return an error to the shell
|
||||
rv = 1
|
||||
if isinstance(outp, ListOfEntries):
|
||||
textui.print_entries(result, order, labels, print_all)
|
||||
elif isinstance(result, (tuple, list)):
|
||||
@ -898,6 +923,7 @@ class Command(HasParam):
|
||||
elif isinstance(result, int):
|
||||
textui.print_count(result, '%s %%d' % unicode(self.output[o].doc))
|
||||
|
||||
return rv
|
||||
|
||||
class LocalOrRemote(Command):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user