Antoni Segura Puimedon has posted comments on this change.
Change subject: tests: vdsProxy remove need to duplicate api ......................................................................
Patch Set 1:
(5 comments)
.................................................... File tests/functional/utils.py Line 132: netinfo.NetInfo(self.vdscli.getVdsCapabilities()['info']) Line 133: Line 134: def __getattr__(self, func): Line 135: """ Line 136: trying to access api call that is not defined here results I propose:
"""When the attribute is missing we look it up at self.vdscli and return the proxy usual tuple (result['status']['code'], result['status']['message'])""" Line 137: in using standard template of Line 138: result = vdsproxy.call(params) Line 139: return result['status']['code'], result['status']['message'] Line 140: """
Line 137: in using standard template of Line 138: result = vdsproxy.call(params) Line 139: return result['status']['code'], result['status']['message'] Line 140: """ Line 141: if hasattr(self.vdscli, func): func = getattr(self.vdscli, func) @wraps(func) and then in the wrapper just result=func(*args, **kwargs) Line 142: def wrapper(*args, **kw): Line 143: result = getattr(self.vdscli, func)(*args, **kw) Line 144: return result['status']['code'], result['status']['message'] Line 145: return wrapper
Line 138: result = vdsproxy.call(params) Line 139: return result['status']['code'], result['status']['message'] Line 140: """ Line 141: if hasattr(self.vdscli, func): Line 142: def wrapper(*args, **kw): s/kw/kwargs/ Line 143: result = getattr(self.vdscli, func)(*args, **kw) Line 144: return result['status']['code'], result['status']['message'] Line 145: return wrapper Line 146: raise AttributeError(func)
Line 139: return result['status']['code'], result['status']['message'] Line 140: """ Line 141: if hasattr(self.vdscli, func): Line 142: def wrapper(*args, **kw): Line 143: result = getattr(self.vdscli, func)(*args, **kw) We could allow an extra keyword argument to be passed to these methods called proxyKeys that would be an iterator (preferably a tuple) that would allow to specify extra keys from "result" to be returned. if 'proxyKeys' in kwargs: keys = kwargs['proxyKeys'] del kwargs['proxyKeys']
With this, one could do:
code, message, info = self.getVdsCapabilities(proxyKeys=('info')) Line 144: return result['status']['code'], result['status']['message'] Line 145: return wrapper Line 146: raise AttributeError(func) Line 147:
Line 140: """ Line 141: if hasattr(self.vdscli, func): Line 142: def wrapper(*args, **kw): Line 143: result = getattr(self.vdscli, func)(*args, **kw) Line 144: return result['status']['code'], result['status']['message'] part of the proxyKeys proposal: proxyValues = tuple(result[value] for value in proxyKeys) return (result['status']['code'], result['status']['message']) + values Line 145: return wrapper Line 146: raise AttributeError(func) Line 147: Line 148: def netinfo_altering(func):