Change in vdsm[master]: janitorial: introduce the 'response' module
nsoffer at redhat.com
nsoffer at redhat.com
Mon Mar 2 12:43:23 UTC 2015
Nir Soffer has posted comments on this change.
Change subject: janitorial: introduce the 'response' module
......................................................................
Patch Set 2:
(4 comments)
https://gerrit.ovirt.org/#/c/37912/2/lib/vdsm/response.py
File lib/vdsm/response.py:
Line 18: # Refer to the README and COPYING files for full details of the license
Line 19: #
Line 20:
Line 21:
Line 22: from vdsm.define import errCode
In the next version it would be nice to move errCode here and call it ERRORS.
Line 23:
Line 24:
Line 25: def error(key, message=None):
Line 26: if not message:
Line 21:
Line 22: from vdsm.define import errCode
Line 23:
Line 24:
Line 25: def error(key, message=None):
key is little too abstract, "name" makes this more clear that we get the error code by the error name.
Line 26: if not message:
Line 27: return errCode[key]
Line 28: else:
Line 29: return {'status':
Line 23:
Line 24:
Line 25: def error(key, message=None):
Line 26: if not message:
Line 27: return errCode[key]
Returning the mutable dict in errCode[key] is dangerous. The caller an modify it by mistake and break the next response.
Line 28: else:
Line 29: return {'status':
Line 30: {'code': errCode[key]['status']['code'],
Line 27: return errCode[key]
Line 28: else:
Line 29: return {'status':
Line 30: {'code': errCode[key]['status']['code'],
Line 31: 'message': message}}
So:
status = errcode[key]["status"]
return {
"status": {
"code": status["code"],
"message": message or status["message"]
}
}
And we should kill errCode soon - there is no reason to keep this. we need a dict of tuples {"name": (code, message), ...}
--
To view, visit https://gerrit.ovirt.org/37912
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ife293080c2c6654315a609478f3276c9008ea6e7
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
More information about the vdsm-patches
mailing list