Zhou Zheng Sheng has posted comments on this change.

Change subject: Fix test errors on el6
......................................................................


Patch Set 1: (2 inline comments)

....................................................
File tests/jsonRpcTests.py
Line 250:         with constructServer(reactorType, bridge) as (server, 
clientFactory):
Line 251:             client = clientFactory()
Line 252:             client.connect()
Line 253:             with closing(client):
Line 254:                 try:
Another way is to translate the error code into a proper exception in 
JsonRpcClient.callMethod , then 

  self.assertRaises(JsonRpcMethodNotFoundError, client.callMethod, 
"I.DO.NOT.EXIST :(", [], 10)

The same problem exists in storage_exception. If one gets an error code, there 
is no convenient way to turn it into an exception. A dict can be constructed 
automatically for translating error code to a specific exception. We can just 
add a decorator to the XXXError definition like follow.

In storage_exception.py or jsonrpc/__init__.py :
  
CODE_TO_EXCEPTION = {}

def mapErrorCode(cls):
    CODE_TO_EXCEPTION[cls.code] = cls
    return cls

@mapErrorCode
class XXXError(XXXGenericError):
    code = 123
    ...

Then in the client proxy code, we can just import 
storage_exception.CODE_TO_EXCEPTION or jsonrpc.CODE_TO_EXCEPTION to map error 
code to exception.

if resp.get('error') is not None:
    raise jsonrpc.CODE_TO_EXCEPTION[resp['error']['code']]()

Or define a translateErrorCode(resp) function in the storage_exception or 
jsonrpc module that accept resp as the parameter and construct a proper 
exception from the resp['error']['code'] and resp['error']['message'] .
Line 255:                     client.callMethod("I.DO.NOT.EXIST :(", [], 10)
Line 256:                     self.fail("Exception expected")
Line 257:                 except JsonRpcError, ex:
Line 258:                     self.assertEquals(ex.code,


Line 253:             with closing(client):
Line 254:                 try:
Line 255:                     client.callMethod("I.DO.NOT.EXIST :(", [], 10)
Line 256:                     self.fail("Exception expected")
Line 257:                 except JsonRpcError, ex:
Agree
Line 258:                     self.assertEquals(ex.code,
Line 259:                                       
JsonRpcMethodNotFoundError().code)
Line 260: 
Line 261:     @permutations(REACTOR_TYPE_PERMUTATIONS)


--
To view, visit http://gerrit.ovirt.org/11350
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I92e1f6a9c8931982b2467ca4b69a6ec819eb0d16
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Saggi Mizrahi <[email protected]>
Gerrit-Reviewer: Antoni Segura Puimedon <[email protected]>
Gerrit-Reviewer: Saggi Mizrahi <[email protected]>
Gerrit-Reviewer: Zhou Zheng Sheng <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to