Change in vdsm[master]: bridge: obtain method
nsoffer at redhat.com
nsoffer at redhat.com
Sun Feb 14 18:25:43 UTC 2016
Nir Soffer has posted comments on this change.
Change subject: bridge: obtain method
......................................................................
Patch Set 1: Code-Review-1
(4 comments)
Nice change, abusing __getattr__ was bad.
https://gerrit.ovirt.org/#/c/53472/1/vdsm/rpc/Bridge.py
File vdsm/rpc/Bridge.py:
Line 108: return response[member]
Line 109: except KeyError:
Line 110: raise VdsmError(5, "Response is missing '%s' member" % member)
Line 111:
Line 112: def get_method(self, method):
I would use better name like "dispatch".
Line 113: try:
Line 114: (className, methodName) = method.split('.')
Line 115: self.api['commands'][className][methodName]
Line 116: except (KeyError):
Line 110: raise VdsmError(5, "Response is missing '%s' member" % member)
Line 111:
Line 112: def get_method(self, method):
Line 113: try:
Line 114: (className, methodName) = method.split('.')
You just introduced a bug fix by Adam few month ago. When using split, you *must* specify the number of splits.
The parenthesis are unneeded and non-idiomatic.
Line 115: self.api['commands'][className][methodName]
Line 116: except (KeyError):
Line 117: raise ValueError("Method %s.%s not found"
Line 118: % (className, methodName))
Line 112: def get_method(self, method):
Line 113: try:
Line 114: (className, methodName) = method.split('.')
Line 115: self.api['commands'][className][methodName]
Line 116: except (KeyError):
What if name does not contain "."?
>>> a, b = "ab".split(".")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
Please keep the existing error handling or improve it (ValueError is invalid input, not attribute error).
The parenthesis are unneeded and non-idiomatic.
Line 117: raise ValueError("Method %s.%s not found"
Line 118: % (className, methodName))
Line 119: return partial(self._dynamicMethod, className, methodName)
Line 120:
Line 114: (className, methodName) = method.split('.')
Line 115: self.api['commands'][className][methodName]
Line 116: except (KeyError):
Line 117: raise ValueError("Method %s.%s not found"
Line 118: % (className, methodName))
Raising ValueError instead of AttributeError is behavior change. Is this intentional?
I think both error are bad. We should raise our own Bridge errors, not stdlib errors, which make it impossible to return correct response for client errors (e.g non-existing method), or server error (e.g. ValueError, KeyError, SyntaxError which are bugs in this code).
Line 119: return partial(self._dynamicMethod, className, methodName)
Line 120:
Line 121: def _convertClassName(self, name):
Line 122: """
--
To view, visit https://gerrit.ovirt.org/53472
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I9b6cb53d8e42335510e34dfe372c1c21b80ac219
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes
More information about the vdsm-patches
mailing list