summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2010-10-01 14:55:43 -0400
committerRob Crittenden <rcritten@redhat.com>2010-10-08 10:11:54 -0400
commitbe6aa7039bdb2ab512caaba3316700ddbb97335f (patch)
tree0ae42137fad6768d5bc61524a8e3cf5133498d2d
parent71a032db19fcebfeb5f258f6855987749e3a4e21 (diff)
downloadfreeipa-be6aa7039bdb2ab512caaba3316700ddbb97335f.tar.gz
freeipa-be6aa7039bdb2ab512caaba3316700ddbb97335f.tar.xz
freeipa-be6aa7039bdb2ab512caaba3316700ddbb97335f.zip
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
-rw-r--r--ipalib/frontend.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index e505f5354..c9c070def 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -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):
"""