PR#2382: hub: [multicall] cast args of exception to str
Merges #2382 https://pagure.io/koji/pull-request/2382 Fixes: #2381 https://pagure.io/koji/issue/2381 hub: [multicall] raise unexpected error when the Exception contains non-str arg
This commit is contained in:
commit
74cfb46086
2 changed files with 41 additions and 1 deletions
|
|
@ -341,7 +341,7 @@ class ModXMLRPCRequestHandler(object):
|
|||
# a circular reference.
|
||||
exc_type, exc_value = sys.exc_info()[:2]
|
||||
faultCode = getattr(exc_type, 'faultCode', 1)
|
||||
faultString = ', '.join(exc_value.args)
|
||||
faultString = ', '.join([str(arg) for arg in exc_value.args])
|
||||
trace = traceback.format_exception(*sys.exc_info())
|
||||
# traceback is not part of the multicall spec,
|
||||
# but we include it for debugging purposes
|
||||
|
|
|
|||
40
tests/test_hub/test_multicall.py
Normal file
40
tests/test_hub/test_multicall.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import mock
|
||||
import unittest
|
||||
|
||||
import kojixmlrpc
|
||||
from kojixmlrpc import Fault, HandlerRegistry, ModXMLRPCRequestHandler
|
||||
|
||||
|
||||
class DummyExports(object):
|
||||
|
||||
def foo(self, bar, err=None):
|
||||
if err:
|
||||
raise err
|
||||
return bar
|
||||
|
||||
|
||||
class TestMulticall(unittest.TestCase):
|
||||
|
||||
def test_multicall(self):
|
||||
kojixmlrpc.kojihub = mock.MagicMock()
|
||||
kojixmlrpc.context.opts = mock.MagicMock()
|
||||
kojixmlrpc.context.session = mock.MagicMock()
|
||||
self.registry = HandlerRegistry()
|
||||
self.exports = DummyExports()
|
||||
self.registry.register_instance(self.exports)
|
||||
calls = [{'methodName': 'foo', 'params': [1]},
|
||||
{'methodName': 'non', 'params': [mock.ANY]},
|
||||
{'methodName': 'foo', 'params': [2, Exception('with int arg', 1)]},
|
||||
{'methodName': 'foo', 'params': [3, Fault(2, 'xmlrpc fault')]}]
|
||||
h = ModXMLRPCRequestHandler(self.registry)
|
||||
h.check_session = mock.MagicMock()
|
||||
h.enforce_lockout = mock.MagicMock()
|
||||
kojixmlrpc.context.event_id = mock.MagicMock()
|
||||
rv = h.multiCall(calls)
|
||||
self.assertEqual(rv, [[1],
|
||||
{'faultCode': 1000, 'faultString': 'Invalid method: non',
|
||||
'traceback': mock.ANY},
|
||||
{'faultCode': 1, 'faultString': 'with int arg, 1',
|
||||
'traceback': mock.ANY},
|
||||
{'faultCode': 2, 'faultString': 'xmlrpc fault'}])
|
||||
self.assertFalse(hasattr(kojixmlrpc.context, 'event_id'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue