Adam Litke has uploaded a new change for review.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
sdm: Add decorators for sdm-only functions and their callers
Change-Id: Iaf736144e5640519851dc9175b5f17539d0ce23e Signed-off-by: Adam Litke alitke@redhat.com --- M tests/Makefile.am A tests/sdm_tests.py M vdsm.spec.in M vdsm/storage/Makefile.am A vdsm/storage/sdm.py 5 files changed, 102 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/43556/1
diff --git a/tests/Makefile.am b/tests/Makefile.am index f116fc4..5907a0d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -92,6 +92,7 @@ scheduleTests.py \ schemaTests.py \ schemaValidationTest.py \ + sdm_tests.py \ securableTests.py \ sourceroutingTests.py \ sslhelper.py \ diff --git a/tests/sdm_tests.py b/tests/sdm_tests.py new file mode 100644 index 0000000..95ae126 --- /dev/null +++ b/tests/sdm_tests.py @@ -0,0 +1,43 @@ +# +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from testlib import VdsmTestCase + +from storage import sdm +from storage.threadLocal import vars + + +class RequireSDMTests(VdsmTestCase): + def setUp(self): + try: + delattr(vars, '__sdm__') + except AttributeError: + pass + + @sdm.sdm_verb + def test_allowed(self): + self.assertTrue(self.sdm_fn()) + + def test_denied(self): + self.assertRaises(sdm.SDMFunctionNotCallable, self.sdm_fn) + + @sdm.require_sdm + def sdm_fn(self): + return True \ No newline at end of file diff --git a/vdsm.spec.in b/vdsm.spec.in index 57e673e..24e0ab7 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -936,6 +936,7 @@ %{_datadir}/%{vdsm_name}/storage/clusterlock.py* %{_datadir}/%{vdsm_name}/storage/sdc.py* %{_datadir}/%{vdsm_name}/storage/sd.py* +%{_datadir}/%{vdsm_name}/storage/sdm.py* %{_datadir}/%{vdsm_name}/storage/securable.py* %{_datadir}/%{vdsm_name}/storage/sp.py* %{_datadir}/%{vdsm_name}/storage/spbackends.py* diff --git a/vdsm/storage/Makefile.am b/vdsm/storage/Makefile.am index e460518..51768ce 100644 --- a/vdsm/storage/Makefile.am +++ b/vdsm/storage/Makefile.am @@ -59,6 +59,7 @@ resourceManager.py \ sdc.py \ sd.py \ + sdm.py \ securable.py \ sp.py \ spbackends.py \ diff --git a/vdsm/storage/sdm.py b/vdsm/storage/sdm.py new file mode 100644 index 0000000..97e599f --- /dev/null +++ b/vdsm/storage/sdm.py @@ -0,0 +1,56 @@ +# +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from functools import wraps +from storage.threadLocal import vars + + +class SDMFunctionNotCallable(Exception): + pass + + +def require_sdm(f): + """ + SDM method decorator. + + This decorator is used to mark methods that can only be called when the + storage is operating in SDM mode (ie. without SPM). + """ + @wraps(f) + def wrapper(*args, **kwds): + if getattr(vars, '__sdm__', False): + return f(*args, **kwds) + else: + raise SDMFunctionNotCallable(f.__name__) + return wrapper + + +def sdm_verb(f): + """ + SDM verb decorator + + This decorator indicates that a function is designed to work without SPM + and is approved to access SDM-only functions. + """ + @wraps(f) + def wrapper(*args, **kwds): + vars.__sdm__ = True + return f(*args, **kwds) + return wrapper
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
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
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 5:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 6:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 7:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 8:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Jenkins CI RO has abandoned this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Abandoned
Abandoned due to no activity - please restore if still relevant
gerrit-hooks has posted comments on this change.
Change subject: sdm: Add decorators for sdm-only functions and their callers ......................................................................
Patch Set 8:
* Update tracker: IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org