Nir Soffer has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers
......................................................................
Patch Set 2: Code-Review-1
(4 comments)
https://gerrit.ovirt.org/#/c/43556/2/vdsm/storage/sdm.py
File vdsm/storage/sdm.py:
Line 25: class SDMFunctionNotCallable(Exception):
Line 26: pass
Line 27:
Line 28:
Line 29: def require_sdm(f):
requires_sdm?
Line 30: """
Line 31: SDM method decorator.
Line 32:
Line 33: This decorator is used to mark methods that can only be called when the
Line 37: def wrapper(*args, **kwds):
Line 38: if getattr(vars, '__sdm__', False):
Line 39: return f(*args, **kwds)
Line 40: else:
Line 41: raise SDMFunctionNotCallable(f.__name__)
Lets use:
if if getattr(vars, '__sdm__', False):
raise ...
return f(*a, **kw)
Line 42: return wrapper
Line 43:
Line 44:
Line 45: def sdm_verb(f):
Line 41: raise SDMFunctionNotCallable(f.__name__)
Line 42: return wrapper
Line 43:
Line 44:
Line 45: def sdm_verb(f):
Not clear what is the difference between require_sdm and sdm_verb
Line 46: """
Line 47: SDM verb decorator
Line 48:
Line 49: This decorator indicates that a function is designed to work without SPM
Line 52: @wraps(f)
Line 53: def wrapper(*args, **kwds):
Line 54: vars.__sdm__ = True
Line 55: return f(*args, **kwds)
Line 56: return wrapper
We don't need to wrap anything for setting an attribute, just use:
def sdm_verb(f):
f.__sdm__ = True
return f
--
To view, visit
https://gerrit.ovirt.org/43556
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Iaf736144e5640519851dc9175b5f17539d0ce23e
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: automation(a)ovirt.org
Gerrit-HasComments: Yes