Change in vdsm[ovirt-3.6]: hooks: make sure to handle vdsm exception in the bridge

piotr.kliczewski at gmail.com piotr.kliczewski at gmail.com
Tue Feb 2 11:55:39 UTC 2016


Piotr Kliczewski has uploaded a new change for review.

Change subject: hooks: make sure to handle vdsm exception in the bridge
......................................................................

hooks: make sure to handle vdsm exception in the bridge

We need to make sure to handle hook errors properly and pass them to
the client.


Change-Id: Ic9c0e953f96827737eede22ab39a1f7689c30944
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
Bug-Url: https://bugzilla.redhat.com/1295778
---
M tests/bridgeTests.py
M vdsm/rpc/Bridge.py
2 files changed, 19 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/52984/1

diff --git a/tests/bridgeTests.py b/tests/bridgeTests.py
index 5a6d84c..80c2c83 100644
--- a/tests/bridgeTests.py
+++ b/tests/bridgeTests.py
@@ -21,7 +21,10 @@
 import imp
 import json
 
+from vdsm.exception import VdsmException
 from rpc.Bridge import DynamicBridge
+from yajsonrpc import JsonRpcError
+
 from monkeypatch import MonkeyPatch
 from testlib import VdsmTestCase as TestCaseBase
 
@@ -48,6 +51,9 @@
     def getCapabilities(self):
         return {'status': {'code': 0, 'message': 'Done'},
                 'info': {'My caps': 'My capabilites'}}
+
+    def ping(self):
+        raise VdsmException("Kaboom!!!")
 
 
 class StorageDomain():
@@ -144,3 +150,12 @@
         params = obj.get('params', [])
         method = getattr(bridge, mangledMethod)
         self.assertEqual(method(**params), None)
+
+    @MonkeyPatch(DynamicBridge, '_getApiInstance', _getApiInstance)
+    def testHookError(self):
+        bridge = DynamicBridge()
+
+        with self.assertRaises(JsonRpcError) as e:
+            bridge.Host_ping()
+
+        self.assertEquals(e.exception.code, 0)
diff --git a/vdsm/rpc/Bridge.py b/vdsm/rpc/Bridge.py
index 319ec3c..c2a114c 100644
--- a/vdsm/rpc/Bridge.py
+++ b/vdsm/rpc/Bridge.py
@@ -24,6 +24,8 @@
 import yajsonrpc
 
 from vdsm.netinfo import getDeviceByIP
+from vdsm.exception import VdsmException
+
 
 try:
     import gluster.apiwrapper as gapi
@@ -277,6 +279,8 @@
                         result = fn(*methodArgs)
             except TypeError as e:
                 raise InvalidCall(fn, methodArgs, e)
+            except VdsmException as e:
+                raise yajsonrpc.JsonRpcError(e.code, str(e))
 
         if result['status']['code']:
             code = result['status']['code']


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9c0e953f96827737eede22ab39a1f7689c30944
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>


More information about the vdsm-patches mailing list