Fix get_connector_properties

We get exception oslo_privsep.daemon.FailedToDropPrivileges when calling
cinderlib.get_connector_properties.

This is because we make it point to OS-Brick's original method, which we
later replace when we do the init in nos-brick.  So cinderlib always
call the replaced method, while cinderlib users will be calling the
original OS-Brick method that hasn't replaced the privsep code.

This patch fixes this by assigning our get_connector_properties method
to the cinderlib method during the nos-brick initialization.

We also have a tiny doc change where we were saying connection instead
of connector, and some cosmetic changes in nos_brick to improve
readability, since we were using acronyms bgcp and bcp, which we now
replace for some more meaningful names.

Closes-Bug: #1822976
Change-Id: I627289418d52bdab826d1cf1a941e5671aaf2239
This commit is contained in:
Gorka Eguileor 2019-04-03 11:53:18 +02:00
parent b27120f696
commit 502f4ce9f4
3 changed files with 16 additions and 9 deletions

View File

@ -41,5 +41,6 @@ dumps = serialization.dumps
setup = cinderlib.setup
Backend = cinderlib.Backend
# This gets reassigned on initialization by nos_brick.init
get_connector_properties = objects.brick_connector.get_connector_properties
list_supported_drivers = cinderlib.Backend.list_supported_drivers

View File

@ -26,6 +26,7 @@ Here we take care of:
Some of these changes may be later moved to OS-Brick. For now we just copied it
from the nos-brick repository.
"""
from __future__ import absolute_import
import errno
import functools
import os
@ -42,6 +43,8 @@ from oslo_utils import fileutils
from oslo_utils import strutils
import six
import cinderlib
LOG = logging.getLogger(__name__)
@ -237,19 +240,19 @@ def init(root_helper='sudo'):
ROOT_HELPER = root_helper
priv_context.init(root_helper=[root_helper])
existing_bgcp = connector.get_connector_properties
existing_bcp = connector.InitiatorConnector.factory
brick_get_connector_properties = connector.get_connector_properties
brick_connector_factory = connector.InitiatorConnector.factory
def my_bgcp(*args, **kwargs):
def my_get_connector_properties(*args, **kwargs):
if len(args):
args = list(args)
args[0] = ROOT_HELPER
else:
kwargs['root_helper'] = ROOT_HELPER
kwargs['execute'] = _execute
return existing_bgcp(*args, **kwargs)
return brick_get_connector_properties(*args, **kwargs)
def my_bgc(protocol, *args, **kwargs):
def my_connector_factory(protocol, *args, **kwargs):
if len(args):
# args is a tuple and we cannot do assignments
args = list(args)
@ -262,11 +265,13 @@ def init(root_helper='sudo'):
if protocol == 'rbd':
factory = RBDConnector
else:
factory = functools.partial(existing_bcp, protocol)
factory = functools.partial(brick_connector_factory, protocol)
return factory(*args, **kwargs)
connector.get_connector_properties = my_bgcp
connector.InitiatorConnector.factory = staticmethod(my_bgc)
# Replace OS-Brick method and the reference we have to it
connector.get_connector_properties = my_get_connector_properties
cinderlib.get_connector_properties = my_get_connector_properties
connector.InitiatorConnector.factory = staticmethod(my_connector_factory)
if hasattr(rootwrap, 'unlink_root'):
rootwrap.unlink_root = unlink_root

View File

@ -122,6 +122,7 @@ key-value storage provided by the persistence plugin:
.. code-block:: python
import socket
import cinderlib as cl
cl.setup(persistence_config=persistence_config)
@ -173,7 +174,7 @@ No access to the metadata persistence storage
This is more inconvenient, as you'll have to handle the data exchange manually
as well as the *OS-Brick* library calls to do the attach/detach.
First we need to get the connection information on the host that is going to do
First we need to get the connector information on the host that is going to do
the attach:
.. code-block:: python