Raise ProcessExecutionError on execute's OSError
In OS-Brick there are many places where calls are made to OS-Brick's execute method, but they mostly only catch ProcessExecutionError exceptions and ignore that it can also raise OSError exceptions. When we replaced the privsep methods we used existing custom_execute method, which doesn't translate OSError exceptions into ProcessExecutionError, so many exceptions are uncaught. This patch adds a new execute method that will do the translation of OSError exceptions raised by custom_execute.
This commit is contained in:
parent
5dbf7528f6
commit
ead327c9ea
|
@ -36,6 +36,8 @@ from os_brick.privileged import rootwrap
|
|||
from oslo_concurrency import processutils as putils
|
||||
from oslo_privsep import priv_context
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
|
||||
|
||||
class RBDConnector(connectors.rbd.RBDConnector):
|
||||
|
@ -124,6 +126,15 @@ def unlink_root(*links, **kwargs):
|
|||
raise exc
|
||||
|
||||
|
||||
def _execute(*cmd, **kwargs):
|
||||
try:
|
||||
return rootwrap.custom_execute(*cmd, **kwargs)
|
||||
except OSError as e:
|
||||
sanitized_cmd = strutils.mask_password(' '.join(cmd))
|
||||
raise putils.ProcessExecutionError(
|
||||
cmd=sanitized_cmd, description=six.text_type(e))
|
||||
|
||||
|
||||
def init(root_helper='sudo'):
|
||||
global ROOT_HELPER
|
||||
ROOT_HELPER = root_helper
|
||||
|
@ -138,7 +149,7 @@ def init(root_helper='sudo'):
|
|||
args[0] = ROOT_HELPER
|
||||
else:
|
||||
kwargs['root_helper'] = ROOT_HELPER
|
||||
kwargs['execute'] = rootwrap.custom_execute
|
||||
kwargs['execute'] = _execute
|
||||
return existing_bgcp(*args, **kwargs)
|
||||
|
||||
def my_bgc(protocol, *args, **kwargs):
|
||||
|
@ -148,7 +159,7 @@ def init(root_helper='sudo'):
|
|||
args[0] = ROOT_HELPER
|
||||
else:
|
||||
kwargs['root_helper'] = ROOT_HELPER
|
||||
kwargs['execute'] = rootwrap.custom_execute
|
||||
kwargs['execute'] = _execute
|
||||
|
||||
# OS-Brick's implementation for RBD is not good enough for us
|
||||
if protocol == 'rbd':
|
||||
|
|
Loading…
Reference in New Issue