137 lines
5.7 KiB
Diff
137 lines
5.7 KiB
Diff
From 5f69a06d1a78242a65164a94d752380613e73e44 Mon Sep 17 00:00:00 2001
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
Date: Wed, 4 Jul 2012 08:39:21 -0400
|
|
Subject: [PATCH 16/79] Fix batch command error reporting
|
|
|
|
The Batch command did not report errors correctly: it reported
|
|
the text of *all* errors, not just PublicError, used unicode(e)
|
|
instead of e.strerror (which results in incorrect i18n), and only
|
|
reported the text of error messages, not their type and code.
|
|
|
|
Fix these problems. Update tests.
|
|
|
|
https://fedorahosted.org/freeipa/ticket/2874
|
|
https://fedorahosted.org/freeipa/ticket/2901
|
|
---
|
|
ipalib/plugins/batch.py | 11 +++++--
|
|
tests/test_xmlrpc/test_batch_plugin.py | 60 ++++++++++++++++++++++++++++------
|
|
2 files changed, 59 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/ipalib/plugins/batch.py b/ipalib/plugins/batch.py
|
|
index 8abad5e1eeab5eeed46c5dc09f17bda1857f9562..db9c08f1052524b58a693f22b123b55637629034 100644
|
|
--- a/ipalib/plugins/batch.py
|
|
+++ b/ipalib/plugins/batch.py
|
|
@@ -102,8 +102,6 @@ class batch(Command):
|
|
)
|
|
result['error']=None
|
|
except Exception, e:
|
|
- result = dict()
|
|
- result['error'] = unicode(e)
|
|
if isinstance(e, errors.RequirementError) or \
|
|
isinstance(e, errors.CommandError):
|
|
self.info(
|
|
@@ -113,6 +111,15 @@ class batch(Command):
|
|
self.info(
|
|
'%s: batch: %s(%s): %s', context.principal, name, ', '.join(api.Command[name]._repr_iter(**params)), e.__class__.__name__
|
|
)
|
|
+ if isinstance(e, errors.PublicError):
|
|
+ reported_error = e
|
|
+ else:
|
|
+ reported_error = errors.InternalError()
|
|
+ result = dict(
|
|
+ error=reported_error.strerror,
|
|
+ error_code=reported_error.errno,
|
|
+ error_name=unicode(type(reported_error).__name__),
|
|
+ )
|
|
results.append(result)
|
|
return dict(count=len(results) , results=results)
|
|
|
|
diff --git a/tests/test_xmlrpc/test_batch_plugin.py b/tests/test_xmlrpc/test_batch_plugin.py
|
|
index d69bfd9c4193af2b8d96bd1f3178dc5566145a35..19728adda40efa7412ad33f0f4be8a5b212120b7 100644
|
|
--- a/tests/test_xmlrpc/test_batch_plugin.py
|
|
+++ b/tests/test_xmlrpc/test_batch_plugin.py
|
|
@@ -121,8 +121,16 @@ class test_batch(Declarative):
|
|
expected=dict(
|
|
count=2,
|
|
results=[
|
|
- dict(error=u'%s: group not found' % group1),
|
|
- dict(error=u'%s: group not found' % group1),
|
|
+ dict(
|
|
+ error=u'%s: group not found' % group1,
|
|
+ error_name=u'NotFound',
|
|
+ error_code=4001,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u'%s: group not found' % group1,
|
|
+ error_name=u'NotFound',
|
|
+ error_code=4001,
|
|
+ ),
|
|
],
|
|
),
|
|
),
|
|
@@ -137,7 +145,11 @@ class test_batch(Declarative):
|
|
expected=dict(
|
|
count=2,
|
|
results=deepequal_list(
|
|
- dict(error=u'%s: group not found' % group1),
|
|
+ dict(
|
|
+ error=u'%s: group not found' % group1,
|
|
+ error_name=u'NotFound',
|
|
+ error_code=4001,
|
|
+ ),
|
|
dict(
|
|
value=group1,
|
|
summary=u'Added group "testgroup1"',
|
|
@@ -180,13 +192,41 @@ class test_batch(Declarative):
|
|
expected=dict(
|
|
count=7,
|
|
results=deepequal_list(
|
|
- dict(error=u"unknown command 'nonexistent_ipa_command'"),
|
|
- dict(error=u"unknown command 'user-del'"),
|
|
- dict(error=u"'method' is required"),
|
|
- dict(error=u"'params' is required"),
|
|
- dict(error=u"'givenname' is required"),
|
|
- dict(error=u"'description' is required"),
|
|
- dict(error=Fuzzy(u"invalid 'gid'.*")),
|
|
+ dict(
|
|
+ error=u"unknown command 'nonexistent_ipa_command'",
|
|
+ error_name=u'CommandError',
|
|
+ error_code=905,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u"unknown command 'user-del'",
|
|
+ error_name=u'CommandError',
|
|
+ error_code=905,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u"'method' is required",
|
|
+ error_name=u'RequirementError',
|
|
+ error_code=3007,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u"'params' is required",
|
|
+ error_name=u'RequirementError',
|
|
+ error_code=3007,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u"'givenname' is required",
|
|
+ error_name=u'RequirementError',
|
|
+ error_code=3007,
|
|
+ ),
|
|
+ dict(
|
|
+ error=u"'description' is required",
|
|
+ error_name=u'RequirementError',
|
|
+ error_code=3007,
|
|
+ ),
|
|
+ dict(
|
|
+ error=Fuzzy(u"invalid 'gid'.*"),
|
|
+ error_name=u'ConversionError',
|
|
+ error_code=3008,
|
|
+ ),
|
|
),
|
|
),
|
|
),
|
|
--
|
|
1.7.11.2
|
|
|