diff options
author | Gorka Eguileor <geguileo@redhat.com> | 2023-01-26 20:09:30 +0100 |
---|---|---|
committer | Gorka Eguileor <geguileo@redhat.com> | 2023-02-03 14:54:09 +0100 |
commit | d89263711247a912bfce74694cbf888b00239d6e (patch) | |
tree | 2bb9d212dc10f98085ef1868cc582cdffd618b23 /cinder/privsep | |
parent | 4c9b76b9373a85f8dfae28f240bb130525e777af (diff) | |
download | cinder-d89263711247a912bfce74694cbf888b00239d6e.tar.gz |
nvmet: Fix setup methods
On ghange Icae9802713867fa148bc041c86beb010086dacc9 we changed from
using the nvmet CLI interface to using it as a Python library.
In that change we incorrectly wrote the ``setup`` methods signature and
they are all missing the ``err_func`` parameter. It is not failing
because that's on the non-privileged side of things, and then on the
privileged side it forcefully adds the parameter on the call to the
actual library.
This patch adds the missing parameter and handles it on the
non-privileged side.
Change-Id: I615497616d87dfc1683977feafcfbfb9fab8e248
Diffstat (limited to 'cinder/privsep')
-rw-r--r-- | cinder/privsep/targets/nvmet.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/cinder/privsep/targets/nvmet.py b/cinder/privsep/targets/nvmet.py index 9b2f5c8f7..b6a516bf3 100644 --- a/cinder/privsep/targets/nvmet.py +++ b/cinder/privsep/targets/nvmet.py @@ -139,7 +139,7 @@ def do_privsep_call(instance, method_name, *args, **kwargs): @privsep.sys_admin_pctxt.entrypoint -def privsep_setup(cls_name, *args, **kwargs): +def _privsep_setup(cls_name, *args, **kwargs): """Special privsep method for nvmet setup method calls. The setup method is a special case because it's a class method (which @@ -152,7 +152,23 @@ def privsep_setup(cls_name, *args, **kwargs): cls = getattr(nvmet, cls_name) args, kwargs = deserialize_params(args, kwargs) kwargs['err_func'] = _nvmet_setup_failure - cls.setup(*args, **kwargs) + return cls.setup(*args, **kwargs) + + +def privsep_setup(cls_name, *args, **kwargs): + """Wrapper for _privsep_setup that accepts err_func argument.""" + # err_func parameter hardcoded in _privsep_setup as it cannot be serialized + if 'err_func' in kwargs: + err_func = kwargs.pop('err_func') + else: # positional is always last argument of the args tuple + err_func = args[-1] + args = args[:-1] + try: + return _privsep_setup(cls_name, *args, **kwargs) + except exception.CinderException as exc: + if not err_func: + raise + err_func(exc.msg) ################### @@ -177,8 +193,8 @@ class Subsystem(nvmet.Subsystem): super().__init__(nqn=nqn, mode=mode) @classmethod - def setup(cls, t): - privsep_setup(cls.__name__, t) + def setup(cls, t, err_func=None): + privsep_setup(cls.__name__, t, err_func) def delete(self): do_privsep_call(serialize(self), 'delete') @@ -189,8 +205,8 @@ class Port(nvmet.Port): super().__init__(portid=portid, mode=mode) @classmethod - def setup(cls, root, n): - privsep_setup(cls.__name__, serialize(root), n) + def setup(cls, root, n, err_func=None): + privsep_setup(cls.__name__, serialize(root), n, err_func) def add_subsystem(self, nqn): do_privsep_call(serialize(self), 'add_subsystem', nqn) |