Fixes bug 887402
Change utils.execute to accept a list or a single integer in check_exit_code. In libvirt.disconnect_volume() return codes 0 and 255 are both valid for logout/delete, where 255 is returned if the volume is already disconnected. Change-Id: Icffeb0fe8269a02d95ac6ed180ba0bb9f458a6ed
This commit is contained in:
@@ -157,8 +157,9 @@ def execute(*cmd, **kwargs):
|
|||||||
|
|
||||||
:cmd Passed to subprocess.Popen.
|
:cmd Passed to subprocess.Popen.
|
||||||
:process_input Send to opened process.
|
:process_input Send to opened process.
|
||||||
:check_exit_code Defaults to 0. Raise exception.ProcessExecutionError
|
:check_exit_code Single int or list of allowed exit codes. Defaults
|
||||||
unless program exits with this code.
|
to [0]. Raise exception.ProcessExecutionError
|
||||||
|
unless program exits with one of these code.
|
||||||
:delay_on_retry True | False. Defaults to True. If set to True, wait a
|
:delay_on_retry True | False. Defaults to True. If set to True, wait a
|
||||||
short amount of time before retrying.
|
short amount of time before retrying.
|
||||||
:attempts How many times to retry cmd.
|
:attempts How many times to retry cmd.
|
||||||
@@ -171,7 +172,9 @@ def execute(*cmd, **kwargs):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
process_input = kwargs.pop('process_input', None)
|
process_input = kwargs.pop('process_input', None)
|
||||||
check_exit_code = kwargs.pop('check_exit_code', 0)
|
check_exit_code = kwargs.pop('check_exit_code', [0])
|
||||||
|
if type(check_exit_code) == types.IntType:
|
||||||
|
check_exit_code = [check_exit_code]
|
||||||
delay_on_retry = kwargs.pop('delay_on_retry', True)
|
delay_on_retry = kwargs.pop('delay_on_retry', True)
|
||||||
attempts = kwargs.pop('attempts', 1)
|
attempts = kwargs.pop('attempts', 1)
|
||||||
run_as_root = kwargs.pop('run_as_root', False)
|
run_as_root = kwargs.pop('run_as_root', False)
|
||||||
@@ -205,8 +208,7 @@ def execute(*cmd, **kwargs):
|
|||||||
_returncode = obj.returncode # pylint: disable=E1101
|
_returncode = obj.returncode # pylint: disable=E1101
|
||||||
if _returncode:
|
if _returncode:
|
||||||
LOG.debug(_('Result was %s') % _returncode)
|
LOG.debug(_('Result was %s') % _returncode)
|
||||||
if type(check_exit_code) == types.IntType \
|
if _returncode not in check_exit_code:
|
||||||
and _returncode != check_exit_code:
|
|
||||||
(stdout, stderr) = result
|
(stdout, stderr) = result
|
||||||
raise exception.ProcessExecutionError(
|
raise exception.ProcessExecutionError(
|
||||||
exit_code=_returncode,
|
exit_code=_returncode,
|
||||||
|
|||||||
@@ -87,11 +87,13 @@ class LibvirtNetVolumeDriver(LibvirtVolumeDriver):
|
|||||||
class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver):
|
class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver):
|
||||||
"""Driver to attach Network volumes to libvirt."""
|
"""Driver to attach Network volumes to libvirt."""
|
||||||
|
|
||||||
def _run_iscsiadm(self, iscsi_properties, iscsi_command):
|
def _run_iscsiadm(self, iscsi_properties, iscsi_command, **kwargs):
|
||||||
|
check_exit_code = kwargs.pop('check_exit_code', 0)
|
||||||
(out, err) = utils.execute('iscsiadm', '-m', 'node', '-T',
|
(out, err) = utils.execute('iscsiadm', '-m', 'node', '-T',
|
||||||
iscsi_properties['target_iqn'],
|
iscsi_properties['target_iqn'],
|
||||||
'-p', iscsi_properties['target_portal'],
|
'-p', iscsi_properties['target_portal'],
|
||||||
*iscsi_command, run_as_root=True)
|
*iscsi_command, run_as_root=True,
|
||||||
|
check_exit_code=check_exit_code)
|
||||||
LOG.debug("iscsiadm %s: stdout=%s stderr=%s" %
|
LOG.debug("iscsiadm %s: stdout=%s stderr=%s" %
|
||||||
(iscsi_command, out, err))
|
(iscsi_command, out, err))
|
||||||
return (out, err)
|
return (out, err)
|
||||||
@@ -170,5 +172,7 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver):
|
|||||||
sup.disconnect_volume(connection_info, mount_device)
|
sup.disconnect_volume(connection_info, mount_device)
|
||||||
iscsi_properties = connection_info['data']
|
iscsi_properties = connection_info['data']
|
||||||
self._iscsiadm_update(iscsi_properties, "node.startup", "manual")
|
self._iscsiadm_update(iscsi_properties, "node.startup", "manual")
|
||||||
self._run_iscsiadm(iscsi_properties, ("--logout",))
|
self._run_iscsiadm(iscsi_properties, ("--logout"),
|
||||||
self._run_iscsiadm(iscsi_properties, ('--op', 'delete'))
|
check_exit_code=[0, 255])
|
||||||
|
self._run_iscsiadm(iscsi_properties, ('--op', 'delete'),
|
||||||
|
check_exit_code=[0, 255])
|
||||||
|
|||||||
Reference in New Issue
Block a user