[Freeipa-devel] [PATCH] 0133 Use standard_list_of_entries for trust-resolve

Alexander Bokovoy abokovoy at redhat.com
Wed Jan 15 16:31:54 UTC 2014


Hi!

When looking into https://fedorahosted.org/freeipa/ticket/4113, I
decided to use output.standard_list_of_entries instead of a locally
defined list of entries. This solves the problem with wrong exit code in
CLI when non-resolvable SID is given, but only for a single SID. If
multiple SID specified and some of them were not resolved, the exit code
will still be 0 (success) but truncated flag will be set. This
corresponds to the framework behavior in other cases.

-- 
/ Alexander Bokovoy
-------------- next part --------------
>From 56b19598170ce9468be3a91b3e9942eba5e4bd89 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy at redhat.com>
Date: Wed, 15 Jan 2014 17:51:25 +0200
Subject: [PATCH 2/2] trust-resolve: improve output by using
 standard_list_of_entries

Use output.standard_list_of_entries instead of own output format
gives benefit of returning proper process exit code in CLI.

https://fedorahosted.org/freeipa/ticket/4113
---
 ipalib/plugins/trust.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py
index 3d412c9..3809f8b 100644
--- a/ipalib/plugins/trust.py
+++ b/ipalib/plugins/trust.py
@@ -992,14 +992,13 @@ class trust_resolve(Command):
         Str('sid', label= _('SID')),
     )
 
-    has_output = (
-        output.ListOfEntries('result'),
-    )
+    has_output = output.standard_list_of_entries
 
+    msg_summary = _('Resolved %(count)d security identifiers')
     def execute(self, *keys, **options):
         result = list()
         if not _nss_idmap_installed:
-            return dict(result=result)
+            return dict(result=result, count=0, truncated=True)
         try:
             sids = map(lambda x: str(x), options['sids'])
             xlate = pysss_nss_idmap.getnamebysid(sids)
@@ -1012,7 +1011,10 @@ class trust_resolve(Command):
         except ValueError, e:
             pass
 
-        return dict(result=result)
+        len_sids = len(options['sids'])
+        len_result = len(result)
+        truncated = len_sids != len_result
+        return dict(result=result, count=len_result, truncated=truncated)
 
 api.register(trust_resolve)
 
-- 
1.8.4.2



More information about the Freeipa-devel mailing list