Piotr Kliczewski has uploaded a new change for review.

Change subject: jsonrpc: allow processing of notifications
......................................................................

jsonrpc: allow processing of notifications

Change-Id: I3858a3ac505ae5370f97c5592b8d38e340422512
Signed-off-by: pkliczew <piotr.kliczew...@gmail.com>
---
M lib/yajsonrpc/__init__.py
1 file changed, 8 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/69/40169/1

diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py
index 0137e16..2708ea4 100644
--- a/lib/yajsonrpc/__init__.py
+++ b/lib/yajsonrpc/__init__.py
@@ -50,7 +50,7 @@
     log = logging.getLogger("JsonRpcInvalidRequestError")
 
     def __init__(self, object_name, msg_content):
-        self.log.error("Invalid message found " + msg_content)
+        self.log.error("Invalid message found %s", msg_content)
         JsonRpcError.__init__(self, -32600,
                               "The JSON sent is not a valid Request object "
                               "with " + object_name)
@@ -100,7 +100,7 @@
             raise JsonRpcInvalidRequestError("missing method header", obj)
 
         reqId = obj.get("id")
-        if not isinstance(reqId, (str, unicode)):
+        if not isinstance(reqId, (str, unicode, int)):
             raise JsonRpcInvalidRequestError("missing request identifier",
                                              obj)
 
@@ -151,19 +151,7 @@
     @staticmethod
     def decode(msg):
         obj = json.loads(msg, 'utf-8')
-
-        if "result" not in obj and "error" not in obj:
-            raise JsonRpcInvalidRequestError("missing result or error info",
-                                             obj)
-
-        result = obj.get('result')
-        error = JsonRpcError(**obj.get('error'))
-
-        reqId = obj.get('id')
-        if not isinstance(reqId, (str, unicode)):
-            raise JsonRpcInvalidRequestError("missing response identifier",
-                                             obj)
-        return JsonRpcResponse(result, error, reqId)
+        return JsonRpcResponse.fromRawObject(obj)
 
     @staticmethod
     def fromRawObject(obj):
@@ -178,9 +166,6 @@
         error = obj.get("error")
 
         reqId = obj.get("id")
-        if not isinstance(reqId, (str, unicode)):
-            raise JsonRpcInvalidRequestError("missing response identifier",
-                                             obj)
 
         return JsonRpcResponse(result, error, reqId)
 
@@ -354,6 +339,11 @@
 
         resp = JsonRpcResponse.fromRawObject(resp)
         with self._lock:
+            if resp.id is None:
+                self.log.warning(
+                    "Got an error from server without an ID (%s)",
+                    resp.error,
+                )
             ctx = self._runningRequests.pop(resp.id)
 
         ctx.addResponse(resp)


-- 
To view, visit https://gerrit.ovirt.org/40169
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3858a3ac505ae5370f97c5592b8d38e340422512
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczew...@gmail.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to