Yeela Kaplan has uploaded a new change for review. Change subject: migration: raise and except only specific exceptions ......................................................................
migration: raise and except only specific exceptions Right now on migration over JsonRpc we swallow any RuntimeError, when actually we might need to fail the migration. To avoid this we will do except clause only for very specific JsonRpcErrors. Change-Id: I4cf662d99493921910821f263b6a5a4542d1604f Signed-off-by: Yeela Kaplan <[email protected]> --- M lib/vdsm/jsonrpcvdscli.py M lib/yajsonrpc/__init__.py M vdsm/clientIF.py M vdsm/virt/migration.py 4 files changed, 23 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/85/42385/1 diff --git a/lib/vdsm/jsonrpcvdscli.py b/lib/vdsm/jsonrpcvdscli.py index b125a56..078b455 100644 --- a/lib/vdsm/jsonrpcvdscli.py +++ b/lib/vdsm/jsonrpcvdscli.py @@ -24,7 +24,8 @@ from yajsonrpc import stompreactor from yajsonrpc import \ JsonRpcError, \ - JsonRpcRequest + JsonRpcRequest, \ + JsonRpcNoResponseError _COMMAND_CONVERTER = { @@ -53,8 +54,7 @@ if responses: resp = responses[0] else: - raise RuntimeError('No response after calling method %s ' - 'over json rpc' % method) + raise JsonRpcNoResponseError(method) if resp.error is not None: raise JsonRpcError(resp.error['code'], resp.error['message']) diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py index 79162d6..1f24cb9 100644 --- a/lib/yajsonrpc/__init__.py +++ b/lib/yajsonrpc/__init__.py @@ -79,6 +79,19 @@ JsonRpcError.__init__(self, -32603, msg) +class JsonRpcBindingsError(JsonRpcError): + def __init__(self): + JsonRpcError.__init__(self, -32604, + "Missing bindings for JSON-RPC.") + + +class JsonRpcNoResponseError(JsonRpcError): + def __init__(self, method=''): + JsonRpcError.__init__(self, -32605, + "No response for JSON-RPC " + "%s request." % method) + + class JsonRpcRequest(object): def __init__(self, method, params=(), reqId=None): self.method = method diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py index ea82a51..198daaf 100644 --- a/vdsm/clientIF.py +++ b/vdsm/clientIF.py @@ -30,7 +30,7 @@ from yajsonrpc.betterAsyncore import Reactor from yajsonrpc.stompreactor import StompClient, StompRpcServer -from yajsonrpc import Notification +from yajsonrpc import Notification, JsonRpcBindingsError import alignmentScan from vdsm.config import config from momIF import MomThread @@ -443,7 +443,7 @@ reactor = json_binding.reactor return reactor.createClient(client_socket) else: - raise RuntimeError("json rpc server is not available") + raise JsonRpcBindingsError() @utils.traceback() def _recoverThread(self): diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py index 622becd..1e9710e 100644 --- a/vdsm/virt/migration.py +++ b/vdsm/virt/migration.py @@ -31,6 +31,10 @@ from vdsm.compat import pickle from vdsm.config import config from vdsm.define import NORMAL, errCode, Mbytes +from yajsonrpc import \ + JsonRpcNoResponseError, \ + JsonRpcBindingsError + from . import vmexitreason from . import vmstatus @@ -136,7 +140,7 @@ self.log.debug('Initiating connection with destination') self._destServer.ping() - except RuntimeError: + except (JsonRpcBindingsError, JsonRpcNoResponseError): if config.getboolean('vars', 'ssl'): self._destServer = vdscli.connect( hostPort, -- To view, visit https://gerrit.ovirt.org/42385 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4cf662d99493921910821f263b6a5a4542d1604f Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yeela Kaplan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
