#2382 hub: [multicall] cast args of exception to str
Merged 3 years ago by tkopecek. Opened 3 years ago by julian8628.
julian8628/koji issue/2381  into  master

file modified
+1 -1
@@ -341,7 +341,7 @@ 

                  # 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

@@ -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'))

I think this is good, but how can we test it?

This fix is only about the logging issue, we still need to figure out the root problem in #2361 (it looks like a race condition)

Right, I'm wondering if there is any way (unit test or some other QE test) to prove that this particular pull request does the right thing?

Ah, OK, I will add unit tests for this

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

3 years ago

rebased onto c085e26

3 years ago

Metadata Update from @mfilip:
- Pull-request tagged with: testing-done

3 years ago

Commit 74cfb46 fixes this pull-request

Pull-Request has been merged by tkopecek

3 years ago