Piotr Kliczewski has uploaded a new change for review.

Change subject: jsonrpc: provide more info when method not found
......................................................................

jsonrpc: provide more info when method not found

When there was no method to be invoked we returned generic exception
without any information about missing method. Now we return this info.


Change-Id: Ib29240f002ab7c11744d164cf4e0ea5f47924929
Signed-off-by: pkliczewski <piotr.kliczew...@gmail.com>
---
M lib/yajsonrpc/__init__.py
M tests/integration/jsonRpcTests.py
M vdsm/rpc/Bridge.py
3 files changed, 15 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/14/53714/1

diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py
index a5e42b8..3724a91 100644
--- a/lib/yajsonrpc/__init__.py
+++ b/lib/yajsonrpc/__init__.py
@@ -61,9 +61,10 @@
 
 
 class JsonRpcMethodNotFoundError(JsonRpcError):
-    def __init__(self):
-        JsonRpcError.__init__(self, -32601,
-                              "The method does not exist / is not available.")
+    def __init__(self, method_name):
+        JsonRpcError.__init__(
+            self, -32601,
+            "The method %s does not exist or is not available." % method_name)
 
 
 class JsonRpcInvalidParamsError(JsonRpcError):
@@ -513,9 +514,9 @@
             if req.isNotification():
                 return
 
-            ctx.requestDone(JsonRpcResponse(None,
-                                            JsonRpcMethodNotFoundError(),
-                                            req.id))
+            ctx.requestDone(JsonRpcResponse(
+                None, JsonRpcMethodNotFoundError(mangledMethod),
+                req.id))
             return
 
         try:
diff --git a/tests/integration/jsonRpcTests.py 
b/tests/integration/jsonRpcTests.py
index 7da9743..5a968ab 100644
--- a/tests/integration/jsonRpcTests.py
+++ b/tests/integration/jsonRpcTests.py
@@ -132,20 +132,23 @@
 
     @permutations(PERMUTATIONS)
     def testMethodMissingMethod(self, ssl, type):
+        missing_method = "I.DO.NOT.EXIST :("
+
         bridge = _DummyBridge()
         with constructClient(self.log, bridge, ssl, type) as clientFactory:
             with self._client(clientFactory) as client:
                 if type == "xml":
-                    response = client.send("I.DO.NOT.EXIST :(", ())
+                    response = client.send(missing_method, ())
                     self.assertTrue("\"I.DO.NOT.EXIST :(\" is not supported"
                                     in response)
                 else:
                     with self.assertRaises(JsonRpcError) as cm:
-                        self._callTimeout(client, "I.DO.NOT.EXIST :(", [],
+                        self._callTimeout(client, missing_method, [],
                                           CALL_ID)
 
-                    self.assertEquals(cm.exception.code,
-                                      JsonRpcMethodNotFoundError().code)
+                    self.assertEquals(
+                        cm.exception.code,
+                        JsonRpcMethodNotFoundError(missing_method).code)
 
     @permutations(PERMUTATIONS)
     def testMethodBadParameters(self, ssl, type):
diff --git a/vdsm/rpc/Bridge.py b/vdsm/rpc/Bridge.py
index b967ee4..ffb2b0d 100644
--- a/vdsm/rpc/Bridge.py
+++ b/vdsm/rpc/Bridge.py
@@ -75,7 +75,7 @@
         try:
             fn = getattr(self, methodName)
         except AttributeError:
-            raise yajsonrpc.JsonRpcMethodNotFoundError()
+            raise yajsonrpc.JsonRpcMethodNotFoundError(methodName)
 
         try:
             result = fn(argobj)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib29240f002ab7c11744d164cf4e0ea5f47924929
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